diff options
author | Sonic <sonic@cobinhood.com> | 2018-10-25 17:54:24 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:17 +0800 |
commit | 218edbb4b4116b6f5e5707c5c89b8a346f47300d (patch) | |
tree | c24b07addef9c024c2de8c912a89632f4da023ec | |
parent | dcb706ee7a9a497527dff649d8cf7d37a1d8fb2d (diff) | |
download | go-tangerine-218edbb4b4116b6f5e5707c5c89b8a346f47300d.tar go-tangerine-218edbb4b4116b6f5e5707c5c89b8a346f47300d.tar.gz go-tangerine-218edbb4b4116b6f5e5707c5c89b8a346f47300d.tar.bz2 go-tangerine-218edbb4b4116b6f5e5707c5c89b8a346f47300d.tar.lz go-tangerine-218edbb4b4116b6f5e5707c5c89b8a346f47300d.tar.xz go-tangerine-218edbb4b4116b6f5e5707c5c89b8a346f47300d.tar.zst go-tangerine-218edbb4b4116b6f5e5707c5c89b8a346f47300d.zip |
core: types: fix header marshal json
-rw-r--r-- | core/types/block.go | 2 | ||||
-rw-r--r-- | core/types/gen_header_json.go | 104 |
2 files changed, 72 insertions, 34 deletions
diff --git a/core/types/block.go b/core/types/block.go index 68346acaa..73537b517 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -101,6 +101,8 @@ type headerMarshaling struct { GasUsed hexutil.Uint64 Time hexutil.Uint64 Extra hexutil.Bytes + Randomness hexutil.Bytes + DexconMeta hexutil.Bytes Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON } diff --git a/core/types/gen_header_json.go b/core/types/gen_header_json.go index d06b07769..72de5a457 100644 --- a/core/types/gen_header_json.go +++ b/core/types/gen_header_json.go @@ -9,6 +9,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/common/hexutil" + "github.com/dexon-foundation/dexon/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types" ) var _ = (*headerMarshaling)(nil) @@ -16,23 +17,28 @@ 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" gencodec:"required"` - 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"` - Randomness []byte `json:"randomness" gencodec:"required"` - Hash common.Hash `json:"hash"` + ParentHash common.Hash `json:"parentHash" gencodec:"required"` + UncleHash common.Hash `json:"sha3Uncles" 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"` + 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"` + Randomness hexutil.Bytes `json:"randomness" gencodec:"required"` + Position types.Position `json:"position" gencodec:"required"` + WitnessHeight uint64 `json:"witnessHeight" gencodec:"required"` + WitnessRoot common.Hash `json:"witnessRoot" gencodec:"required"` + WitnessReceiptHash common.Hash `json:"witnessReceiptHash" gencodec:"required"` + DexconMeta hexutil.Bytes `json:"dexconMeta" gencodec:"required"` + Hash common.Hash `json:"hash"` } var enc Header enc.ParentHash = h.ParentHash @@ -51,6 +57,11 @@ func (h Header) MarshalJSON() ([]byte, error) { enc.MixDigest = h.MixDigest enc.Nonce = h.Nonce enc.Randomness = h.Randomness + enc.Position = h.Position + enc.WitnessHeight = h.WitnessHeight + enc.WitnessRoot = h.WitnessRoot + enc.WitnessReceiptHash = h.WitnessReceiptHash + enc.DexconMeta = h.DexconMeta enc.Hash = h.Hash() return json.Marshal(&enc) } @@ -58,22 +69,27 @@ func (h Header) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals from JSON. func (h *Header) UnmarshalJSON(input []byte) error { type Header struct { - ParentHash *common.Hash `json:"parentHash" gencodec:"required"` - UncleHash *common.Hash `json:"sha3Uncles" 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"` - 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"` - Randomness []byte `json:"randomness" gencodec:"required"` + ParentHash *common.Hash `json:"parentHash" gencodec:"required"` + UncleHash *common.Hash `json:"sha3Uncles" 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"` + 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"` + Randomness *hexutil.Bytes `json:"randomness" gencodec:"required"` + Position *types.Position `json:"position" gencodec:"required"` + WitnessHeight *uint64 `json:"witnessHeight" gencodec:"required"` + WitnessRoot *common.Hash `json:"witnessRoot" gencodec:"required"` + WitnessReceiptHash *common.Hash `json:"witnessReceiptHash" gencodec:"required"` + DexconMeta *hexutil.Bytes `json:"dexconMeta" gencodec:"required"` } var dec Header if err := json.Unmarshal(input, &dec); err != nil { @@ -140,6 +156,26 @@ func (h *Header) UnmarshalJSON(input []byte) error { if dec.Randomness == nil { return errors.New("missing required field 'randomness' for Header") } - h.Randomness = dec.Randomness + h.Randomness = *dec.Randomness + if dec.Position == nil { + return errors.New("missing required field 'position' for Header") + } + h.Position = *dec.Position + if dec.WitnessHeight == nil { + return errors.New("missing required field 'witnessHeight' for Header") + } + h.WitnessHeight = *dec.WitnessHeight + if dec.WitnessRoot == nil { + return errors.New("missing required field 'witnessRoot' for Header") + } + h.WitnessRoot = *dec.WitnessRoot + if dec.WitnessReceiptHash == nil { + return errors.New("missing required field 'witnessReceiptHash' for Header") + } + h.WitnessReceiptHash = *dec.WitnessReceiptHash + if dec.DexconMeta == nil { + return errors.New("missing required field 'dexconMeta' for Header") + } + h.DexconMeta = *dec.DexconMeta return nil } |