aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2018-10-30 14:03:22 +0800
committerWei-Ning Huang <w@dexon.org>2019-03-12 12:19:09 +0800
commit32d79763bfb2ab6952786bf590c3a65fd33eca50 (patch)
tree1fe752f3cea2fe82370ac8cfba7d6fd9e5097aaf /core
parent07c599fec712ff4af9725bcd0db1a55bcb81bea1 (diff)
downloaddexon-32d79763bfb2ab6952786bf590c3a65fd33eca50.tar.gz
dexon-32d79763bfb2ab6952786bf590c3a65fd33eca50.tar.zst
dexon-32d79763bfb2ab6952786bf590c3a65fd33eca50.zip
core: fix blockReward serialization
Diffstat (limited to 'core')
-rw-r--r--core/types/block.go43
-rw-r--r--core/types/gen_header_json.go22
2 files changed, 28 insertions, 37 deletions
diff --git a/core/types/block.go b/core/types/block.go
index dadcfb4c1..2825c6987 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 *big.Int `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 *big.Int `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.Big
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 35c308c4a..622b7c330 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
}