diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-10-30 14:03:22 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:52 +0800 |
commit | 6e0cf992988f29daabd39e67f2f6ce8034ba4513 (patch) | |
tree | a60995a993cc0d5dd2c1a520f12243c78311a747 /core | |
parent | b109172d0141c704f90e0272dcab806791c4580b (diff) | |
download | dexon-6e0cf992988f29daabd39e67f2f6ce8034ba4513.tar dexon-6e0cf992988f29daabd39e67f2f6ce8034ba4513.tar.gz dexon-6e0cf992988f29daabd39e67f2f6ce8034ba4513.tar.bz2 dexon-6e0cf992988f29daabd39e67f2f6ce8034ba4513.tar.lz dexon-6e0cf992988f29daabd39e67f2f6ce8034ba4513.tar.xz dexon-6e0cf992988f29daabd39e67f2f6ce8034ba4513.tar.zst dexon-6e0cf992988f29daabd39e67f2f6ce8034ba4513.zip |
core: fix blockReward serialization
Diffstat (limited to 'core')
-rw-r--r-- | core/types/block.go | 43 | ||||
-rw-r--r-- | core/types/gen_header_json.go | 22 |
2 files changed, 28 insertions, 37 deletions
diff --git a/core/types/block.go b/core/types/block.go index 07fc55358..6186c66bb 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -26,7 +26,6 @@ import ( "time" "unsafe" - coreTypes "github.com/dexon-foundation/dexon-consensus/core/types" "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/common/hexutil" "github.com/dexon-foundation/dexon/rlp" @@ -75,26 +74,25 @@ type WitnessData struct { // Header represents a block header in the Ethereum blockchain. 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 *big.Int `json:"difficulty" gencodec:"required"` - Number *big.Int `json:"number" gencodec:"required"` - GasLimit uint64 `json:"gasLimit" gencodec:"required"` - GasUsed uint64 `json:"gasUsed" gencodec:"required"` - Time uint64 `json:"timestamp" gencodec:"required"` - Extra []byte `json:"extraData" gencodec:"required"` - MixDigest common.Hash `json:"mixHash"` - Nonce BlockNonce `json:"nonce"` - Randomness []byte `json:"randomness" gencodec:"required"` - Position coreTypes.Position `json:"position" gencodec:"required"` - Round uint64 `json:"round" gencodec:"required"` - DexconMeta []byte `json:"dexconMeta" gencodec:"required"` - BlockReward *big.Int `json:"blockReward" 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 *big.Int `json:"difficulty" gencodec:"required"` + Number *big.Int `json:"number" gencodec:"required"` + GasLimit uint64 `json:"gasLimit" gencodec:"required"` + GasUsed uint64 `json:"gasUsed" gencodec:"required"` + Time uint64 `json:"timestamp" gencodec:"required"` + Extra []byte `json:"extraData" gencodec:"required"` + MixDigest common.Hash `json:"mixHash"` + Nonce BlockNonce `json:"nonce"` + Reward *big.Int `json:"reward" gencodec:"required"` + Randomness []byte `json:"randomness" gencodec:"required"` + Round uint64 `json:"round" gencodec:"required"` + DexconMeta []byte `json:"dexconMeta" gencodec:"required"` } // field type overrides for gencodec @@ -105,9 +103,10 @@ type headerMarshaling struct { GasUsed hexutil.Uint64 Time hexutil.Uint64 Extra hexutil.Bytes - Randomness hexutil.Bytes Round hexutil.Uint64 + Randomness hexutil.Bytes DexconMeta hexutil.Bytes + Reward *hexutil.Big 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 b49d48f14..5b14ab26e 100644 --- a/core/types/gen_header_json.go +++ b/core/types/gen_header_json.go @@ -7,7 +7,6 @@ import ( "errors" "math/big" - "github.com/dexon-foundation/dexon-consensus/core/types" "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/common/hexutil" ) @@ -32,11 +31,10 @@ func (h Header) MarshalJSON() ([]byte, error) { Extra hexutil.Bytes `json:"extraData" gencodec:"required"` MixDigest common.Hash `json:"mixHash"` Nonce BlockNonce `json:"nonce"` + Reward *hexutil.Big `json:"reward" gencodec:"required"` Randomness hexutil.Bytes `json:"randomness" gencodec:"required"` - Position types.Position `json:"position" gencodec:"required"` Round hexutil.Uint64 `json:"round" gencodec:"required"` DexconMeta hexutil.Bytes `json:"dexconMeta" gencodec:"required"` - BlockReward *big.Int `json:"blockReward" gencodec:"required"` Hash common.Hash `json:"hash"` } var enc Header @@ -55,11 +53,10 @@ func (h Header) MarshalJSON() ([]byte, error) { enc.Extra = h.Extra enc.MixDigest = h.MixDigest enc.Nonce = h.Nonce + enc.Reward = (*hexutil.Big)(h.Reward) enc.Randomness = h.Randomness - enc.Position = h.Position enc.Round = hexutil.Uint64(h.Round) enc.DexconMeta = h.DexconMeta - enc.BlockReward = h.BlockReward enc.Hash = h.Hash() return json.Marshal(&enc) } @@ -82,11 +79,10 @@ func (h *Header) UnmarshalJSON(input []byte) error { Extra *hexutil.Bytes `json:"extraData" gencodec:"required"` MixDigest *common.Hash `json:"mixHash"` Nonce *BlockNonce `json:"nonce"` + Reward *hexutil.Big `json:"reward" gencodec:"required"` Randomness *hexutil.Bytes `json:"randomness" gencodec:"required"` - Position *types.Position `json:"position" gencodec:"required"` Round *hexutil.Uint64 `json:"round" gencodec:"required"` DexconMeta *hexutil.Bytes `json:"dexconMeta" gencodec:"required"` - BlockReward *big.Int `json:"blockReward" gencodec:"required"` } var dec Header if err := json.Unmarshal(input, &dec); err != nil { @@ -150,14 +146,14 @@ func (h *Header) UnmarshalJSON(input []byte) error { if dec.Nonce != nil { h.Nonce = *dec.Nonce } + if dec.Reward == nil { + return errors.New("missing required field 'reward' for Header") + } + h.Reward = (*big.Int)(dec.Reward) if dec.Randomness == nil { return errors.New("missing required field 'randomness' for Header") } h.Randomness = *dec.Randomness - if dec.Position == nil { - return errors.New("missing required field 'position' for Header") - } - h.Position = *dec.Position if dec.Round == nil { return errors.New("missing required field 'round' for Header") } @@ -166,9 +162,5 @@ func (h *Header) UnmarshalJSON(input []byte) error { return errors.New("missing required field 'dexconMeta' for Header") } h.DexconMeta = *dec.DexconMeta - if dec.BlockReward == nil { - return errors.New("missing required field 'blockReward' for Header") - } - h.BlockReward = dec.BlockReward return nil } |