From 598ff32ef0bba76bb191fb18d27398d6c9af412a Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Thu, 18 Apr 2024 12:27:34 +0800 Subject: [PATCH] marshal header --- pkg/eth/backend_utils.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pkg/eth/backend_utils.go b/pkg/eth/backend_utils.go index 06244791..95ac499b 100644 --- a/pkg/eth/backend_utils.go +++ b/pkg/eth/backend_utils.go @@ -41,10 +41,11 @@ import ( var nullHashBytes = common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000") var emptyCodeHash = crypto.Keccak256([]byte{}) +// These marshalling functions are from internal/ethapi so we have to make our own versions here: + // RPCMarshalHeader converts the given header to the RPC output. -// This function is eth/internal so we have to make our own version here... func RPCMarshalHeader(head *types.Header) map[string]interface{} { - headerMap := map[string]interface{}{ + result := map[string]interface{}{ "number": (*hexutil.Big)(head.Number), "hash": head.Hash(), "parentHash": head.ParentHash, @@ -56,18 +57,28 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} { "miner": head.Coinbase, "difficulty": (*hexutil.Big)(head.Difficulty), "extraData": hexutil.Bytes(head.Extra), - "size": hexutil.Uint64(head.Size()), "gasLimit": hexutil.Uint64(head.GasLimit), "gasUsed": hexutil.Uint64(head.GasUsed), "timestamp": hexutil.Uint64(head.Time), "transactionsRoot": head.TxHash, "receiptsRoot": head.ReceiptHash, } - if head.BaseFee != nil { - headerMap["baseFeePerGas"] = (*hexutil.Big)(head.BaseFee) + result["baseFeePerGas"] = (*hexutil.Big)(head.BaseFee) } - return headerMap + if head.WithdrawalsHash != nil { + result["withdrawalsRoot"] = head.WithdrawalsHash + } + if head.BlobGasUsed != nil { + result["blobGasUsed"] = hexutil.Uint64(*head.BlobGasUsed) + } + if head.ExcessBlobGas != nil { + result["excessBlobGas"] = hexutil.Uint64(*head.ExcessBlobGas) + } + if head.ParentBeaconRoot != nil { + result["parentBeaconBlockRoot"] = head.ParentBeaconRoot + } + return result } // RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are