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