|
|
|
@ -16,25 +16,26 @@ var _ = (*headerMarshaling)(nil) |
|
|
|
|
// MarshalJSON marshals as JSON.
|
|
|
|
|
func (h Header) MarshalJSON() ([]byte, error) { |
|
|
|
|
type Header struct { |
|
|
|
|
ParentHash common.Hash `json:"parentHash" gencodec:"required"` |
|
|
|
|
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"` |
|
|
|
|
Coinbase common.Address `json:"miner"` |
|
|
|
|
Root common.Hash `json:"stateRoot" gencodec:"required"` |
|
|
|
|
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"` |
|
|
|
|
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"` |
|
|
|
|
Bloom Bloom `json:"logsBloom" gencodec:"required"` |
|
|
|
|
Difficulty *hexutil.Big `json:"difficulty" gencodec:"required"` |
|
|
|
|
Number *hexutil.Big `json:"number" gencodec:"required"` |
|
|
|
|
GasLimit hexutil.Uint64 `json:"gasLimit" gencodec:"required"` |
|
|
|
|
GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"` |
|
|
|
|
Time hexutil.Uint64 `json:"timestamp" gencodec:"required"` |
|
|
|
|
Extra hexutil.Bytes `json:"extraData" gencodec:"required"` |
|
|
|
|
MixDigest common.Hash `json:"mixHash"` |
|
|
|
|
Nonce BlockNonce `json:"nonce"` |
|
|
|
|
BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` |
|
|
|
|
WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"` |
|
|
|
|
ExcessDataGas *big.Int `json:"excessDataGas" rlp:"optional"` |
|
|
|
|
Hash common.Hash `json:"hash"` |
|
|
|
|
ParentHash common.Hash `json:"parentHash" gencodec:"required"` |
|
|
|
|
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"` |
|
|
|
|
Coinbase common.Address `json:"miner"` |
|
|
|
|
Root common.Hash `json:"stateRoot" gencodec:"required"` |
|
|
|
|
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"` |
|
|
|
|
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"` |
|
|
|
|
Bloom Bloom `json:"logsBloom" gencodec:"required"` |
|
|
|
|
Difficulty *hexutil.Big `json:"difficulty" gencodec:"required"` |
|
|
|
|
Number *hexutil.Big `json:"number" gencodec:"required"` |
|
|
|
|
GasLimit hexutil.Uint64 `json:"gasLimit" gencodec:"required"` |
|
|
|
|
GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"` |
|
|
|
|
Time hexutil.Uint64 `json:"timestamp" gencodec:"required"` |
|
|
|
|
Extra hexutil.Bytes `json:"extraData" gencodec:"required"` |
|
|
|
|
MixDigest common.Hash `json:"mixHash"` |
|
|
|
|
Nonce BlockNonce `json:"nonce"` |
|
|
|
|
BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` |
|
|
|
|
WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"` |
|
|
|
|
ExcessDataGas *hexutil.Uint64 `json:"excessDataGas" rlp:"optional"` |
|
|
|
|
DataGasUsed *hexutil.Uint64 `json:"dataGasUsed" rlp:"optional"` |
|
|
|
|
Hash common.Hash `json:"hash"` |
|
|
|
|
} |
|
|
|
|
var enc Header |
|
|
|
|
enc.ParentHash = h.ParentHash |
|
|
|
@ -54,7 +55,8 @@ func (h Header) MarshalJSON() ([]byte, error) { |
|
|
|
|
enc.Nonce = h.Nonce |
|
|
|
|
enc.BaseFee = (*hexutil.Big)(h.BaseFee) |
|
|
|
|
enc.WithdrawalsHash = h.WithdrawalsHash |
|
|
|
|
enc.ExcessDataGas = h.ExcessDataGas |
|
|
|
|
enc.ExcessDataGas = (*hexutil.Uint64)(h.ExcessDataGas) |
|
|
|
|
enc.DataGasUsed = (*hexutil.Uint64)(h.DataGasUsed) |
|
|
|
|
enc.Hash = h.Hash() |
|
|
|
|
return json.Marshal(&enc) |
|
|
|
|
} |
|
|
|
@ -79,7 +81,8 @@ func (h *Header) UnmarshalJSON(input []byte) error { |
|
|
|
|
Nonce *BlockNonce `json:"nonce"` |
|
|
|
|
BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` |
|
|
|
|
WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"` |
|
|
|
|
ExcessDataGas *big.Int `json:"excessDataGas" rlp:"optional"` |
|
|
|
|
ExcessDataGas *hexutil.Uint64 `json:"excessDataGas" rlp:"optional"` |
|
|
|
|
DataGasUsed *hexutil.Uint64 `json:"dataGasUsed" rlp:"optional"` |
|
|
|
|
} |
|
|
|
|
var dec Header |
|
|
|
|
if err := json.Unmarshal(input, &dec); err != nil { |
|
|
|
@ -149,7 +152,10 @@ func (h *Header) UnmarshalJSON(input []byte) error { |
|
|
|
|
h.WithdrawalsHash = dec.WithdrawalsHash |
|
|
|
|
} |
|
|
|
|
if dec.ExcessDataGas != nil { |
|
|
|
|
h.ExcessDataGas = dec.ExcessDataGas |
|
|
|
|
h.ExcessDataGas = (*uint64)(dec.ExcessDataGas) |
|
|
|
|
} |
|
|
|
|
if dec.DataGasUsed != nil { |
|
|
|
|
h.DataGasUsed = (*uint64)(dec.DataGasUsed) |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|