diff options
author | Sonic <sonic@cobinhood.com> | 2018-10-25 17:54:24 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:52 +0800 |
commit | c15f524e4a4bc22dfca78777bfc4ae4cf76b8933 (patch) | |
tree | 7db4321a750831343b09e5080b01798d251f3d93 | |
parent | 2d1ed5288cab621aba39c3a81aae7042ead14fd5 (diff) | |
download | dexon-c15f524e4a4bc22dfca78777bfc4ae4cf76b8933.tar dexon-c15f524e4a4bc22dfca78777bfc4ae4cf76b8933.tar.gz dexon-c15f524e4a4bc22dfca78777bfc4ae4cf76b8933.tar.bz2 dexon-c15f524e4a4bc22dfca78777bfc4ae4cf76b8933.tar.lz dexon-c15f524e4a4bc22dfca78777bfc4ae4cf76b8933.tar.xz dexon-c15f524e4a4bc22dfca78777bfc4ae4cf76b8933.tar.zst dexon-c15f524e4a4bc22dfca78777bfc4ae4cf76b8933.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 } |