You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
4.3 KiB
118 lines
4.3 KiB
6 years ago
|
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
|
||
|
|
||
5 years ago
|
package v1
|
||
6 years ago
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"errors"
|
||
|
"math/big"
|
||
|
|
||
|
"github.com/ethereum/go-ethereum/common"
|
||
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||
6 years ago
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||
6 years ago
|
)
|
||
|
|
||
|
var _ = (*headerMarshaling)(nil)
|
||
|
|
||
|
func (h Header) MarshalJSON() ([]byte, error) {
|
||
6 years ago
|
// TODO: update with new fields
|
||
6 years ago
|
type Header struct {
|
||
|
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
|
||
|
Coinbase common.Address `json:"miner" gencodec:"required"`
|
||
|
Root common.Hash `json:"stateRoot" gencodec:"required"`
|
||
|
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
|
||
|
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
|
||
6 years ago
|
Bloom ethtypes.Bloom `json:"logsBloom" gencodec:"required"`
|
||
6 years ago
|
Number *hexutil.Big `json:"number" gencodec:"required"`
|
||
|
GasLimit hexutil.Uint64 `json:"gasLimit" gencodec:"required"`
|
||
|
GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
|
||
|
Time *hexutil.Big `json:"timestamp" gencodec:"required"`
|
||
|
Extra hexutil.Bytes `json:"extraData" gencodec:"required"`
|
||
|
MixDigest common.Hash `json:"mixHash" gencodec:"required"`
|
||
|
Hash common.Hash `json:"hash"`
|
||
|
}
|
||
|
var enc Header
|
||
5 years ago
|
enc.ParentHash = h.ParentHash()
|
||
|
enc.Coinbase = h.Coinbase()
|
||
|
enc.Root = h.Root()
|
||
|
enc.TxHash = h.TxHash()
|
||
|
enc.ReceiptHash = h.ReceiptHash()
|
||
|
enc.Bloom = h.Bloom()
|
||
|
enc.Number = (*hexutil.Big)(h.Number())
|
||
|
enc.GasLimit = hexutil.Uint64(h.GasLimit())
|
||
|
enc.GasUsed = hexutil.Uint64(h.GasUsed())
|
||
|
enc.Time = (*hexutil.Big)(h.Time())
|
||
|
enc.Extra = h.Extra()
|
||
|
enc.MixDigest = h.MixDigest()
|
||
6 years ago
|
enc.Hash = h.Hash()
|
||
|
return json.Marshal(&enc)
|
||
|
}
|
||
|
|
||
|
func (h *Header) UnmarshalJSON(input []byte) error {
|
||
6 years ago
|
// TODO: update with new fields
|
||
6 years ago
|
type Header struct {
|
||
|
ParentHash *common.Hash `json:"parentHash" gencodec:"required"`
|
||
|
Coinbase *common.Address `json:"miner" gencodec:"required"`
|
||
|
Root *common.Hash `json:"stateRoot" gencodec:"required"`
|
||
|
TxHash *common.Hash `json:"transactionsRoot" gencodec:"required"`
|
||
|
ReceiptHash *common.Hash `json:"receiptsRoot" gencodec:"required"`
|
||
6 years ago
|
Bloom *ethtypes.Bloom `json:"logsBloom" gencodec:"required"`
|
||
6 years ago
|
Number *hexutil.Big `json:"number" gencodec:"required"`
|
||
|
GasLimit *hexutil.Uint64 `json:"gasLimit" gencodec:"required"`
|
||
|
GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
|
||
|
Time *hexutil.Big `json:"timestamp" gencodec:"required"`
|
||
|
Extra *hexutil.Bytes `json:"extraData" gencodec:"required"`
|
||
|
MixDigest *common.Hash `json:"mixHash" gencodec:"required"`
|
||
|
}
|
||
|
var dec Header
|
||
|
if err := json.Unmarshal(input, &dec); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
if dec.ParentHash == nil {
|
||
|
return errors.New("missing required field 'parentHash' for Header")
|
||
|
}
|
||
5 years ago
|
h.SetParentHash(*dec.ParentHash)
|
||
6 years ago
|
if dec.Coinbase == nil {
|
||
|
return errors.New("missing required field 'miner' for Header")
|
||
|
}
|
||
5 years ago
|
h.SetCoinbase(*dec.Coinbase)
|
||
6 years ago
|
if dec.Root == nil {
|
||
|
return errors.New("missing required field 'stateRoot' for Header")
|
||
|
}
|
||
5 years ago
|
h.SetRoot(*dec.Root)
|
||
6 years ago
|
if dec.TxHash == nil {
|
||
|
return errors.New("missing required field 'transactionsRoot' for Header")
|
||
|
}
|
||
5 years ago
|
h.SetTxHash(*dec.TxHash)
|
||
6 years ago
|
if dec.ReceiptHash == nil {
|
||
|
return errors.New("missing required field 'receiptsRoot' for Header")
|
||
|
}
|
||
5 years ago
|
h.SetReceiptHash(*dec.ReceiptHash)
|
||
6 years ago
|
if dec.Bloom == nil {
|
||
|
return errors.New("missing required field 'logsBloom' for Header")
|
||
|
}
|
||
5 years ago
|
h.SetBloom(*dec.Bloom)
|
||
|
h.SetNumber((*big.Int)(dec.Number))
|
||
6 years ago
|
if dec.GasLimit == nil {
|
||
|
return errors.New("missing required field 'gasLimit' for Header")
|
||
|
}
|
||
5 years ago
|
h.SetGasLimit(uint64(*dec.GasLimit))
|
||
6 years ago
|
if dec.GasUsed == nil {
|
||
|
return errors.New("missing required field 'gasUsed' for Header")
|
||
|
}
|
||
5 years ago
|
h.SetGasUsed(uint64(*dec.GasUsed))
|
||
6 years ago
|
if dec.Time == nil {
|
||
|
return errors.New("missing required field 'timestamp' for Header")
|
||
|
}
|
||
5 years ago
|
h.SetTime((*big.Int)(dec.Time))
|
||
6 years ago
|
if dec.Extra == nil {
|
||
|
return errors.New("missing required field 'extraData' for Header")
|
||
|
}
|
||
5 years ago
|
h.SetExtra(*dec.Extra)
|
||
6 years ago
|
if dec.MixDigest == nil {
|
||
|
return errors.New("missing required field 'mixHash' for Header")
|
||
|
}
|
||
5 years ago
|
h.SetMixDigest(*dec.MixDigest)
|
||
6 years ago
|
return nil
|
||
|
}
|