Skip to content

Commit

Permalink
fix: remove unnecessary newRPCTransactionFromBlockHash function (bnb-…
Browse files Browse the repository at this point in the history
…chain#22)

Co-authored-by: Welkin <welkin.b@nodereal.com>
Co-authored-by: Owen <103096885+owen-reorg@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 5, 2024
1 parent 04aa065 commit 0eb8a65
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ func RPCMarshalBlock(ctx context.Context, block *types.Block, inclTx bool, fullT
}
if fullTx {
formatTx = func(tx *types.Transaction, index int) (interface{}, error) {
return newRPCTransactionFromBlockHash(ctx, block, tx.Hash(), index, tx, backend), nil
return newRPCTransactionFromBlockIndex(ctx, block, uint64(index), backend), nil
}
}
txs := block.Transactions()
Expand Down Expand Up @@ -1512,14 +1512,12 @@ func NewRPCPendingTransaction(tx *types.Transaction, current *types.Header, conf
}

// newRPCTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation.
func newRPCTransactionFromBlockIndex(ctx context.Context, b *types.Block, index uint64, tx *types.Transaction, backend Backend) *RPCTransaction {
if tx == nil {
txs := b.Transactions()
if index >= uint64(len(txs)) {
return nil
}
tx = txs[index]
func newRPCTransactionFromBlockIndex(ctx context.Context, b *types.Block, index uint64, backend Backend) *RPCTransaction {
txs := b.Transactions()
if index >= uint64(len(txs)) {
return nil
}
tx := txs[index]

rcpt := depositTxReceipt(ctx, b.Hash(), index, backend, tx)
return newRPCTransaction(tx, b.Hash(), b.NumberU64(), index, b.BaseFee(), backend.ChainConfig(), rcpt)
Expand Down Expand Up @@ -1549,11 +1547,6 @@ func newRPCRawTransactionFromBlockIndex(b *types.Block, index uint64) hexutil.By
return blob
}

// newRPCTransactionFromBlockHash returns a transaction that will serialize to the RPC representation.
func newRPCTransactionFromBlockHash(ctx context.Context, b *types.Block, hash common.Hash, idx int, tx *types.Transaction, backend Backend) *RPCTransaction {
return newRPCTransactionFromBlockIndex(ctx, b, uint64(idx), tx, backend)
}

// accessListResult returns an optional accesslist
// Its the result of the `debug_createAccessList` RPC call.
// It contains an error if the transaction itself failed.
Expand Down Expand Up @@ -1698,15 +1691,15 @@ func (s *TransactionAPI) GetBlockTransactionCountByHash(ctx context.Context, blo
// GetTransactionByBlockNumberAndIndex returns the transaction for the given block number and index.
func (s *TransactionAPI) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) *RPCTransaction {
if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil {
return newRPCTransactionFromBlockIndex(ctx, block, uint64(index), nil, s.b)
return newRPCTransactionFromBlockIndex(ctx, block, uint64(index), s.b)
}
return nil
}

// GetTransactionByBlockHashAndIndex returns the transaction for the given block hash and index.
func (s *TransactionAPI) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) *RPCTransaction {
if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil {
return newRPCTransactionFromBlockIndex(ctx, block, uint64(index), nil, s.b)
return newRPCTransactionFromBlockIndex(ctx, block, uint64(index), s.b)
}
return nil
}
Expand Down

0 comments on commit 0eb8a65

Please sign in to comment.