Skip to content

Commit

Permalink
update RPCMarshalHeader (ethereum#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
ping-ke authored May 12, 2022
1 parent e99ed3f commit ac5dc58
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
10 changes: 5 additions & 5 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 23 additions & 17 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ac5dc58

Please sign in to comment.