From ac5dc589be3467110c8863d7db3315ea0fd2840d Mon Sep 17 00:00:00 2001 From: ping-ke Date: Thu, 12 May 2022 17:07:32 +0800 Subject: [PATCH] update RPCMarshalHeader (#79) --- core/types/block.go | 10 +++++----- internal/ethapi/api.go | 40 +++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/core/types/block.go b/core/types/block.go index b570a5242e2b..85cd95df249b 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -88,11 +88,11 @@ type Header struct { BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"` // Chamber-related data structure - TimeMs uint64 `json:"TimeMs" rlp:"optional"` - NextValidators []common.Address `json:"NextValidators" rlp:"optional"` - NextValidatorPowers []uint64 `json:"NextValidatorPowers" rlp:"optional"` - LastCommitHash common.Hash `json:"LastCommitHash" rlp:"optional"` - Commit *Commit `json:"Commit" rlp:"optional"` + TimeMs uint64 `json:"timeMs" rlp:"optional"` + NextValidators []common.Address `json:"nextValidators" rlp:"optional"` + NextValidatorPowers []uint64 `json:"nextValidatorPowers" rlp:"optional"` + LastCommitHash common.Hash `json:"lastCommitHash" rlp:"optional"` + Commit *Commit `json:"commit" rlp:"optional"` /* TODO (MariusVanDerWijden) Add this field once needed diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 366d5714175d..27ea3c8550e0 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -743,6 +743,7 @@ func (s *PublicBlockChainAPI) GetHeaderByHash(ctx context.Context, hash common.H // * When fullTx is true all transactions in the block are returned, otherwise // only the transaction hash is returned. func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) { + log.Warn("=============================GetBlockByNumber==============================") block, err := s.b.BlockByNumber(ctx, number) if block != nil && err == nil { response, err := s.rpcMarshalBlock(ctx, block, true, fullTx) @@ -1186,23 +1187,28 @@ func FormatLogs(logs []logger.StructLog) []StructLogRes { // RPCMarshalHeader converts the given header to the RPC output . func RPCMarshalHeader(head *types.Header) map[string]interface{} { result := map[string]interface{}{ - "number": (*hexutil.Big)(head.Number), - "hash": head.Hash(), - "parentHash": head.ParentHash, - "nonce": head.Nonce, - "mixHash": head.MixDigest, - "sha3Uncles": head.UncleHash, - "logsBloom": head.Bloom, - "stateRoot": head.Root, - "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, + "number": (*hexutil.Big)(head.Number), + "hash": head.Hash(), + "parentHash": head.ParentHash, + "nonce": head.Nonce, + "mixHash": head.MixDigest, + "sha3Uncles": head.UncleHash, + "logsBloom": head.Bloom, + "stateRoot": head.Root, + "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, + "timeMs": head.TimeMs, + "nextValidators": head.NextValidators, + "nextValidatorPowers": head.NextValidatorPowers, + "LastCommitHash": head.LastCommitHash, + "commit": head.Commit, } if head.BaseFee != nil {