Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display dynamic fee transactions in block explorers #284

Merged
merged 8 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions jsonrpc/eth_blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ func TestEth_Block_GetTransactionByBlockNumberAndIndex(t *testing.T) {

transaction := toTransaction(
block.Transactions[testIndex],
argUintPtr(block.Number()),
argHashPtr(block.Hash()),
block.Header,
&testIndex,
)

Expand All @@ -217,8 +216,7 @@ func TestEth_Block_GetTransactionByBlockHashAndIndex(t *testing.T) {

transaction := toTransaction(
block.Transactions[testIndex],
argUintPtr(block.Number()),
argHashPtr(block.Hash()),
block.Header,
&testIndex,
)

Expand Down
5 changes: 1 addition & 4 deletions jsonrpc/eth_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,9 @@ func (e *Eth) GetTransactionByHash(hash types.Hash) (interface{}, error) {

// Find the transaction within the block
if txn, idx := types.FindTxByHash(block.Transactions, hash); txn != nil {
txn.SetGasPrice(txn.GetGasPrice(block.Header.BaseFee))

return toTransaction(
txn,
argUintPtr(block.Number()),
argHashPtr(block.Hash()),
block.Header,
&idx,
)
}
Expand Down
3 changes: 1 addition & 2 deletions jsonrpc/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ func GetTransactionByBlockAndIndex(block *types.Block, index argUint64) (interfa

return toTransaction(
block.Transactions[index],
argUintPtr(block.Number()),
argHashPtr(block.Hash()),
block.Header,
&idx,
), nil
}
Expand Down
4 changes: 2 additions & 2 deletions jsonrpc/txpool_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (t *TxPool) ContentFrom(addr types.Address) (interface{}, error) {
convertTxMap := func(txs []*types.Transaction) map[uint64]*transaction {
result := make(map[uint64]*transaction, len(txs))
for _, tx := range txs {
result[tx.Nonce()] = toTransaction(tx, nil, &types.ZeroHash, nil)
result[tx.Nonce()] = toTransaction(tx, nil, nil)
}

return result
Expand All @@ -76,7 +76,7 @@ func (t *TxPool) Content() (interface{}, error) {
result[addr] = make(map[uint64]*transaction, len(txs))

for _, tx := range txs {
result[addr][tx.Nonce()] = toTransaction(tx, nil, &types.ZeroHash, nil)
result[addr][tx.Nonce()] = toTransaction(tx, nil, nil)
}
}

Expand Down
62 changes: 29 additions & 33 deletions jsonrpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,45 +59,43 @@ func (h transactionHash) MarshalText() ([]byte, error) {
}

func toPendingTransaction(t *types.Transaction) *transaction {
return toTransaction(t, nil, nil, nil)
return toTransaction(t, nil, nil)
}

func toTransaction(
t *types.Transaction,
blockNumber *argUint64,
blockHash *types.Hash,
header *types.Header,
txIndex *int,
) *transaction {
v, r, s := t.RawSignatureValues()
res := &transaction{
Nonce: argUint64(t.Nonce()),
Gas: argUint64(t.Gas()),
To: t.To(),
Value: argBig(*t.Value()),
Input: t.Input(),
V: argBig(*v),
R: argBig(*r),
S: argBig(*s),
Hash: t.Hash(),
From: t.From(),
Type: argUint64(t.Type()),
BlockNumber: blockNumber,
BlockHash: blockHash,
}

if t.GasPrice() != nil && t.Type() != types.DynamicFeeTxType {
gasPrice := argBig(*(t.GasPrice()))
res.GasPrice = &gasPrice
}

if t.GasTipCap() != nil && t.Type() == types.DynamicFeeTxType {
gasTipCap := argBig(*(t.GasTipCap()))
res.GasTipCap = &gasTipCap
}
Nonce: argUint64(t.Nonce()),
Gas: argUint64(t.Gas()),
To: t.To(),
Value: argBig(*t.Value()),
Input: t.Input(),
V: argBig(*v),
R: argBig(*r),
S: argBig(*s),
Hash: t.Hash(),
From: t.From(),
Type: argUint64(t.Type()),
}

if header != nil {
res.BlockNumber = argUintPtr(header.Number)
res.BlockHash = &header.Hash
res.GasPrice = argBigPtr(t.GetGasPrice(header.BaseFee))
}

if t.Type() == types.DynamicFeeTxType {
if t.GasTipCap() != nil {
res.GasTipCap = argBigPtr(t.GasTipCap())
}

if t.GasFeeCap() != nil && t.Type() == types.DynamicFeeTxType {
gasFeeCap := argBig(*(t.GasFeeCap()))
res.GasFeeCap = &gasFeeCap
if t.GasFeeCap() != nil {
res.GasFeeCap = argBigPtr(t.GasFeeCap())
}
}

if t.ChainID() != nil {
Expand Down Expand Up @@ -195,13 +193,11 @@ func toBlock(b *types.Block, fullTx bool) *block {

for idx, txn := range b.Transactions {
if fullTx {
txn.SetGasPrice(txn.GetGasPrice(b.Header.BaseFee))
res.Transactions = append(
res.Transactions,
toTransaction(
txn,
argUintPtr(b.Number()),
argHashPtr(b.Hash()),
b.Header,
&idx,
),
)
Expand Down
4 changes: 2 additions & 2 deletions jsonrpc/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestToTransaction_Returns_V_R_S_ValuesWithoutLeading0(t *testing.T) {
types.WithFrom(types.Address{}),
))

jsonTx := toTransaction(txn, nil, nil, nil)
jsonTx := toTransaction(txn, nil, nil)

jsonV, _ := jsonTx.V.MarshalText()
jsonR, _ := jsonTx.R.MarshalText()
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestToTransaction_EIP1559(t *testing.T) {
types.WithFrom(types.Address{}),
))

jsonTx := toTransaction(txn, nil, nil, nil)
jsonTx := toTransaction(txn, nil, nil)

jsonV, _ := jsonTx.V.MarshalText()
jsonR, _ := jsonTx.R.MarshalText()
Expand Down
Loading