internal/ethapi: minor refactor in block serialization (#27268)
This commit is contained in:
+5
-18
@@ -1263,21 +1263,18 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param
|
||||
fields["size"] = hexutil.Uint64(block.Size())
|
||||
|
||||
if inclTx {
|
||||
formatTx := func(tx *types.Transaction) (interface{}, error) {
|
||||
return tx.Hash(), nil
|
||||
formatTx := func(idx int, tx *types.Transaction) interface{} {
|
||||
return tx.Hash()
|
||||
}
|
||||
if fullTx {
|
||||
formatTx = func(tx *types.Transaction) (interface{}, error) {
|
||||
return newRPCTransactionFromBlockHash(block, tx.Hash(), config), nil
|
||||
formatTx = func(idx int, tx *types.Transaction) interface{} {
|
||||
return newRPCTransactionFromBlockIndex(block, uint64(idx), config)
|
||||
}
|
||||
}
|
||||
txs := block.Transactions()
|
||||
transactions := make([]interface{}, len(txs))
|
||||
var err error
|
||||
for i, tx := range txs {
|
||||
if transactions[i], err = formatTx(tx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
transactions[i] = formatTx(i, tx)
|
||||
}
|
||||
fields["transactions"] = transactions
|
||||
}
|
||||
@@ -1424,16 +1421,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(b *types.Block, hash common.Hash, config *params.ChainConfig) *RPCTransaction {
|
||||
for idx, tx := range b.Transactions() {
|
||||
if tx.Hash() == hash {
|
||||
return newRPCTransactionFromBlockIndex(b, uint64(idx), config)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// accessListResult returns an optional accesslist
|
||||
// It's the result of the `debug_createAccessList` RPC call.
|
||||
// It contains an error if the transaction itself failed.
|
||||
|
||||
Reference in New Issue
Block a user