@ -18,23 +18,26 @@ var _ = (*headerMarshaling)(nil)
// MarshalJSON marshals as JSON.
func ( h header ) MarshalJSON ( ) ( [ ] byte , error ) {
type header struct {
ParentHash common . Hash ` json:"parentHash" `
OmmerHash * common . Hash ` json:"sha3Uncles" `
Coinbase * common . Address ` json:"miner" `
Root common . Hash ` json:"stateRoot" gencodec:"required" `
TxHash * common . Hash ` json:"transactionsRoot" `
ReceiptHash * common . Hash ` json:"receiptsRoot" `
Bloom types . Bloom ` json:"logsBloom" `
Difficulty * math . HexOrDecimal256 ` json:"difficulty" `
Number * math . HexOrDecimal256 ` json:"number" gencodec:"required" `
GasLimit math . HexOrDecimal64 ` json:"gasLimit" gencodec:"required" `
GasUsed math . HexOrDecimal64 ` json:"gasUsed" `
Time math . HexOrDecimal64 ` json:"timestamp" gencodec:"required" `
Extra hexutil . Bytes ` json:"extraData" `
MixDigest common . Hash ` json:"mixHash" `
Nonce * types . BlockNonce ` json:"nonce" `
BaseFee * math . HexOrDecimal256 ` json:"baseFeePerGas" rlp:"optional" `
WithdrawalsHash * common . Hash ` json:"withdrawalsRoot" rlp:"optional" `
ParentHash common . Hash ` json:"parentHash" `
OmmerHash * common . Hash ` json:"sha3Uncles" `
Coinbase * common . Address ` json:"miner" `
Root common . Hash ` json:"stateRoot" gencodec:"required" `
TxHash * common . Hash ` json:"transactionsRoot" `
ReceiptHash * common . Hash ` json:"receiptsRoot" `
Bloom types . Bloom ` json:"logsBloom" `
Difficulty * math . HexOrDecimal256 ` json:"difficulty" `
Number * math . HexOrDecimal256 ` json:"number" gencodec:"required" `
GasLimit math . HexOrDecimal64 ` json:"gasLimit" gencodec:"required" `
GasUsed math . HexOrDecimal64 ` json:"gasUsed" `
Time math . HexOrDecimal64 ` json:"timestamp" gencodec:"required" `
Extra hexutil . Bytes ` json:"extraData" `
MixDigest common . Hash ` json:"mixHash" `
Nonce * types . BlockNonce ` json:"nonce" `
BaseFee * math . HexOrDecimal256 ` json:"baseFeePerGas" rlp:"optional" `
WithdrawalsHash * common . Hash ` json:"withdrawalsRoot" rlp:"optional" `
BlobGasUsed * math . HexOrDecimal64 ` json:"blobGasUsed" rlp:"optional" `
ExcessBlobGas * math . HexOrDecimal64 ` json:"excessBlobGas" rlp:"optional" `
ParentBeaconBlockRoot * common . Hash ` json:"parentBeaconBlockRoot" rlp:"optional" `
}
var enc header
enc . ParentHash = h . ParentHash
@ -54,29 +57,35 @@ func (h header) MarshalJSON() ([]byte, error) {
enc . Nonce = h . Nonce
enc . BaseFee = ( * math . HexOrDecimal256 ) ( h . BaseFee )
enc . WithdrawalsHash = h . WithdrawalsHash
enc . BlobGasUsed = ( * math . HexOrDecimal64 ) ( h . BlobGasUsed )
enc . ExcessBlobGas = ( * math . HexOrDecimal64 ) ( h . ExcessBlobGas )
enc . ParentBeaconBlockRoot = h . ParentBeaconBlockRoot
return json . Marshal ( & enc )
}
// UnmarshalJSON unmarshals from JSON.
func ( h * header ) UnmarshalJSON ( input [ ] byte ) error {
type header struct {
ParentHash * common . Hash ` json:"parentHash" `
OmmerHash * common . Hash ` json:"sha3Uncles" `
Coinbase * common . Address ` json:"miner" `
Root * common . Hash ` json:"stateRoot" gencodec:"required" `
TxHash * common . Hash ` json:"transactionsRoot" `
ReceiptHash * common . Hash ` json:"receiptsRoot" `
Bloom * types . Bloom ` json:"logsBloom" `
Difficulty * math . HexOrDecimal256 ` json:"difficulty" `
Number * math . HexOrDecimal256 ` json:"number" gencodec:"required" `
GasLimit * math . HexOrDecimal64 ` json:"gasLimit" gencodec:"required" `
GasUsed * math . HexOrDecimal64 ` json:"gasUsed" `
Time * math . HexOrDecimal64 ` json:"timestamp" gencodec:"required" `
Extra * hexutil . Bytes ` json:"extraData" `
MixDigest * common . Hash ` json:"mixHash" `
Nonce * types . BlockNonce ` json:"nonce" `
BaseFee * math . HexOrDecimal256 ` json:"baseFeePerGas" rlp:"optional" `
WithdrawalsHash * common . Hash ` json:"withdrawalsRoot" rlp:"optional" `
ParentHash * common . Hash ` json:"parentHash" `
OmmerHash * common . Hash ` json:"sha3Uncles" `
Coinbase * common . Address ` json:"miner" `
Root * common . Hash ` json:"stateRoot" gencodec:"required" `
TxHash * common . Hash ` json:"transactionsRoot" `
ReceiptHash * common . Hash ` json:"receiptsRoot" `
Bloom * types . Bloom ` json:"logsBloom" `
Difficulty * math . HexOrDecimal256 ` json:"difficulty" `
Number * math . HexOrDecimal256 ` json:"number" gencodec:"required" `
GasLimit * math . HexOrDecimal64 ` json:"gasLimit" gencodec:"required" `
GasUsed * math . HexOrDecimal64 ` json:"gasUsed" `
Time * math . HexOrDecimal64 ` json:"timestamp" gencodec:"required" `
Extra * hexutil . Bytes ` json:"extraData" `
MixDigest * common . Hash ` json:"mixHash" `
Nonce * types . BlockNonce ` json:"nonce" `
BaseFee * math . HexOrDecimal256 ` json:"baseFeePerGas" rlp:"optional" `
WithdrawalsHash * common . Hash ` json:"withdrawalsRoot" rlp:"optional" `
BlobGasUsed * math . HexOrDecimal64 ` json:"blobGasUsed" rlp:"optional" `
ExcessBlobGas * math . HexOrDecimal64 ` json:"excessBlobGas" rlp:"optional" `
ParentBeaconBlockRoot * common . Hash ` json:"parentBeaconBlockRoot" rlp:"optional" `
}
var dec header
if err := json . Unmarshal ( input , & dec ) ; err != nil {
@ -137,5 +146,14 @@ func (h *header) UnmarshalJSON(input []byte) error {
if dec . WithdrawalsHash != nil {
h . WithdrawalsHash = dec . WithdrawalsHash
}
if dec . BlobGasUsed != nil {
h . BlobGasUsed = ( * uint64 ) ( dec . BlobGasUsed )
}
if dec . ExcessBlobGas != nil {
h . ExcessBlobGas = ( * uint64 ) ( dec . ExcessBlobGas )
}
if dec . ParentBeaconBlockRoot != nil {
h . ParentBeaconBlockRoot = dec . ParentBeaconBlockRoot
}
return nil
}