|
|
@ -12,24 +12,25 @@ import ( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func (h Header) MarshalJSON() ([]byte, error) { |
|
|
|
func (h Header) MarshalJSON() ([]byte, error) { |
|
|
|
type HeaderJSON struct { |
|
|
|
type Header struct { |
|
|
|
ParentHash common.Hash `json:"parentHash"` |
|
|
|
ParentHash common.Hash `json:"parentHash" gencodec:"required"` |
|
|
|
UncleHash common.Hash `json:"sha3Uncles"` |
|
|
|
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"` |
|
|
|
Coinbase common.Address `json:"miner"` |
|
|
|
Coinbase common.Address `json:"miner" gencodec:"required"` |
|
|
|
Root common.Hash `json:"stateRoot"` |
|
|
|
Root common.Hash `json:"stateRoot" gencodec:"required"` |
|
|
|
TxHash common.Hash `json:"transactionsRoot"` |
|
|
|
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"` |
|
|
|
ReceiptHash common.Hash `json:"receiptsRoot"` |
|
|
|
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"` |
|
|
|
Bloom Bloom `json:"logsBloom"` |
|
|
|
Bloom Bloom `json:"logsBloom" gencodec:"required"` |
|
|
|
Difficulty *hexutil.Big `json:"difficulty"` |
|
|
|
Difficulty *hexutil.Big `json:"difficulty" gencodec:"required"` |
|
|
|
Number *hexutil.Big `json:"number"` |
|
|
|
Number *hexutil.Big `json:"number" gencodec:"required"` |
|
|
|
GasLimit *hexutil.Big `json:"gasLimit"` |
|
|
|
GasLimit *hexutil.Big `json:"gasLimit" gencodec:"required"` |
|
|
|
GasUsed *hexutil.Big `json:"gasUsed"` |
|
|
|
GasUsed *hexutil.Big `json:"gasUsed" gencodec:"required"` |
|
|
|
Time *hexutil.Big `json:"timestamp"` |
|
|
|
Time *hexutil.Big `json:"timestamp" gencodec:"required"` |
|
|
|
Extra hexutil.Bytes `json:"extraData"` |
|
|
|
Extra hexutil.Bytes `json:"extraData" gencodec:"required"` |
|
|
|
MixDigest common.Hash `json:"mixHash"` |
|
|
|
MixDigest common.Hash `json:"mixHash" gencodec:"required"` |
|
|
|
Nonce BlockNonce `json:"nonce"` |
|
|
|
Nonce BlockNonce `json:"nonce" gencodec:"required"` |
|
|
|
} |
|
|
|
Hash common.Hash `json:"hash"` |
|
|
|
var enc HeaderJSON |
|
|
|
} |
|
|
|
|
|
|
|
var enc Header |
|
|
|
enc.ParentHash = h.ParentHash |
|
|
|
enc.ParentHash = h.ParentHash |
|
|
|
enc.UncleHash = h.UncleHash |
|
|
|
enc.UncleHash = h.UncleHash |
|
|
|
enc.Coinbase = h.Coinbase |
|
|
|
enc.Coinbase = h.Coinbase |
|
|
@ -45,92 +46,91 @@ func (h Header) MarshalJSON() ([]byte, error) { |
|
|
|
enc.Extra = h.Extra |
|
|
|
enc.Extra = h.Extra |
|
|
|
enc.MixDigest = h.MixDigest |
|
|
|
enc.MixDigest = h.MixDigest |
|
|
|
enc.Nonce = h.Nonce |
|
|
|
enc.Nonce = h.Nonce |
|
|
|
|
|
|
|
enc.Hash = h.Hash() |
|
|
|
return json.Marshal(&enc) |
|
|
|
return json.Marshal(&enc) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (h *Header) UnmarshalJSON(input []byte) error { |
|
|
|
func (h *Header) UnmarshalJSON(input []byte) error { |
|
|
|
type HeaderJSON struct { |
|
|
|
type Header struct { |
|
|
|
ParentHash *common.Hash `json:"parentHash"` |
|
|
|
ParentHash *common.Hash `json:"parentHash" gencodec:"required"` |
|
|
|
UncleHash *common.Hash `json:"sha3Uncles"` |
|
|
|
UncleHash *common.Hash `json:"sha3Uncles" gencodec:"required"` |
|
|
|
Coinbase *common.Address `json:"miner"` |
|
|
|
Coinbase *common.Address `json:"miner" gencodec:"required"` |
|
|
|
Root *common.Hash `json:"stateRoot"` |
|
|
|
Root *common.Hash `json:"stateRoot" gencodec:"required"` |
|
|
|
TxHash *common.Hash `json:"transactionsRoot"` |
|
|
|
TxHash *common.Hash `json:"transactionsRoot" gencodec:"required"` |
|
|
|
ReceiptHash *common.Hash `json:"receiptsRoot"` |
|
|
|
ReceiptHash *common.Hash `json:"receiptsRoot" gencodec:"required"` |
|
|
|
Bloom *Bloom `json:"logsBloom"` |
|
|
|
Bloom *Bloom `json:"logsBloom" gencodec:"required"` |
|
|
|
Difficulty *hexutil.Big `json:"difficulty"` |
|
|
|
Difficulty *hexutil.Big `json:"difficulty" gencodec:"required"` |
|
|
|
Number *hexutil.Big `json:"number"` |
|
|
|
Number *hexutil.Big `json:"number" gencodec:"required"` |
|
|
|
GasLimit *hexutil.Big `json:"gasLimit"` |
|
|
|
GasLimit *hexutil.Big `json:"gasLimit" gencodec:"required"` |
|
|
|
GasUsed *hexutil.Big `json:"gasUsed"` |
|
|
|
GasUsed *hexutil.Big `json:"gasUsed" gencodec:"required"` |
|
|
|
Time *hexutil.Big `json:"timestamp"` |
|
|
|
Time *hexutil.Big `json:"timestamp" gencodec:"required"` |
|
|
|
Extra hexutil.Bytes `json:"extraData"` |
|
|
|
Extra hexutil.Bytes `json:"extraData" gencodec:"required"` |
|
|
|
MixDigest *common.Hash `json:"mixHash"` |
|
|
|
MixDigest *common.Hash `json:"mixHash" gencodec:"required"` |
|
|
|
Nonce *BlockNonce `json:"nonce"` |
|
|
|
Nonce *BlockNonce `json:"nonce" gencodec:"required"` |
|
|
|
} |
|
|
|
} |
|
|
|
var dec HeaderJSON |
|
|
|
var dec Header |
|
|
|
if err := json.Unmarshal(input, &dec); err != nil { |
|
|
|
if err := json.Unmarshal(input, &dec); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
var x Header |
|
|
|
|
|
|
|
if dec.ParentHash == nil { |
|
|
|
if dec.ParentHash == nil { |
|
|
|
return errors.New("missing required field 'parentHash' for Header") |
|
|
|
return errors.New("missing required field 'parentHash' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.ParentHash = *dec.ParentHash |
|
|
|
h.ParentHash = *dec.ParentHash |
|
|
|
if dec.UncleHash == nil { |
|
|
|
if dec.UncleHash == nil { |
|
|
|
return errors.New("missing required field 'sha3Uncles' for Header") |
|
|
|
return errors.New("missing required field 'sha3Uncles' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.UncleHash = *dec.UncleHash |
|
|
|
h.UncleHash = *dec.UncleHash |
|
|
|
if dec.Coinbase == nil { |
|
|
|
if dec.Coinbase == nil { |
|
|
|
return errors.New("missing required field 'miner' for Header") |
|
|
|
return errors.New("missing required field 'miner' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.Coinbase = *dec.Coinbase |
|
|
|
h.Coinbase = *dec.Coinbase |
|
|
|
if dec.Root == nil { |
|
|
|
if dec.Root == nil { |
|
|
|
return errors.New("missing required field 'stateRoot' for Header") |
|
|
|
return errors.New("missing required field 'stateRoot' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.Root = *dec.Root |
|
|
|
h.Root = *dec.Root |
|
|
|
if dec.TxHash == nil { |
|
|
|
if dec.TxHash == nil { |
|
|
|
return errors.New("missing required field 'transactionsRoot' for Header") |
|
|
|
return errors.New("missing required field 'transactionsRoot' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.TxHash = *dec.TxHash |
|
|
|
h.TxHash = *dec.TxHash |
|
|
|
if dec.ReceiptHash == nil { |
|
|
|
if dec.ReceiptHash == nil { |
|
|
|
return errors.New("missing required field 'receiptsRoot' for Header") |
|
|
|
return errors.New("missing required field 'receiptsRoot' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.ReceiptHash = *dec.ReceiptHash |
|
|
|
h.ReceiptHash = *dec.ReceiptHash |
|
|
|
if dec.Bloom == nil { |
|
|
|
if dec.Bloom == nil { |
|
|
|
return errors.New("missing required field 'logsBloom' for Header") |
|
|
|
return errors.New("missing required field 'logsBloom' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.Bloom = *dec.Bloom |
|
|
|
h.Bloom = *dec.Bloom |
|
|
|
if dec.Difficulty == nil { |
|
|
|
if dec.Difficulty == nil { |
|
|
|
return errors.New("missing required field 'difficulty' for Header") |
|
|
|
return errors.New("missing required field 'difficulty' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.Difficulty = (*big.Int)(dec.Difficulty) |
|
|
|
h.Difficulty = (*big.Int)(dec.Difficulty) |
|
|
|
if dec.Number == nil { |
|
|
|
if dec.Number == nil { |
|
|
|
return errors.New("missing required field 'number' for Header") |
|
|
|
return errors.New("missing required field 'number' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.Number = (*big.Int)(dec.Number) |
|
|
|
h.Number = (*big.Int)(dec.Number) |
|
|
|
if dec.GasLimit == nil { |
|
|
|
if dec.GasLimit == nil { |
|
|
|
return errors.New("missing required field 'gasLimit' for Header") |
|
|
|
return errors.New("missing required field 'gasLimit' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.GasLimit = (*big.Int)(dec.GasLimit) |
|
|
|
h.GasLimit = (*big.Int)(dec.GasLimit) |
|
|
|
if dec.GasUsed == nil { |
|
|
|
if dec.GasUsed == nil { |
|
|
|
return errors.New("missing required field 'gasUsed' for Header") |
|
|
|
return errors.New("missing required field 'gasUsed' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.GasUsed = (*big.Int)(dec.GasUsed) |
|
|
|
h.GasUsed = (*big.Int)(dec.GasUsed) |
|
|
|
if dec.Time == nil { |
|
|
|
if dec.Time == nil { |
|
|
|
return errors.New("missing required field 'timestamp' for Header") |
|
|
|
return errors.New("missing required field 'timestamp' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.Time = (*big.Int)(dec.Time) |
|
|
|
h.Time = (*big.Int)(dec.Time) |
|
|
|
if dec.Extra == nil { |
|
|
|
if dec.Extra == nil { |
|
|
|
return errors.New("missing required field 'extraData' for Header") |
|
|
|
return errors.New("missing required field 'extraData' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.Extra = dec.Extra |
|
|
|
h.Extra = dec.Extra |
|
|
|
if dec.MixDigest == nil { |
|
|
|
if dec.MixDigest == nil { |
|
|
|
return errors.New("missing required field 'mixHash' for Header") |
|
|
|
return errors.New("missing required field 'mixHash' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.MixDigest = *dec.MixDigest |
|
|
|
h.MixDigest = *dec.MixDigest |
|
|
|
if dec.Nonce == nil { |
|
|
|
if dec.Nonce == nil { |
|
|
|
return errors.New("missing required field 'nonce' for Header") |
|
|
|
return errors.New("missing required field 'nonce' for Header") |
|
|
|
} |
|
|
|
} |
|
|
|
x.Nonce = *dec.Nonce |
|
|
|
h.Nonce = *dec.Nonce |
|
|
|
*h = x |
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|