aboutsummaryrefslogtreecommitdiffstats
path: root/core/types
diff options
context:
space:
mode:
authorBojie Wu <bojie@dexon.org>2018-10-09 13:28:45 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:52 +0800
commit7c1386d928acd050684f435e49149696bcc0a637 (patch)
treedb7141013bd1aa9e2349aa8b161d6529ff25cd40 /core/types
parentd44a8b7003df87c7e7662a7ac86fb351872cd371 (diff)
downloaddexon-7c1386d928acd050684f435e49149696bcc0a637.tar
dexon-7c1386d928acd050684f435e49149696bcc0a637.tar.gz
dexon-7c1386d928acd050684f435e49149696bcc0a637.tar.bz2
dexon-7c1386d928acd050684f435e49149696bcc0a637.tar.lz
dexon-7c1386d928acd050684f435e49149696bcc0a637.tar.xz
dexon-7c1386d928acd050684f435e49149696bcc0a637.tar.zst
dexon-7c1386d928acd050684f435e49149696bcc0a637.zip
app: add cache mechanism to increase performance
Diffstat (limited to 'core/types')
-rw-r--r--core/types/block.go35
-rw-r--r--core/types/gen_header_json.go75
2 files changed, 59 insertions, 51 deletions
diff --git a/core/types/block.go b/core/types/block.go
index 9e42a776a..07fc55358 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -75,25 +75,26 @@ 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"`
+ 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"`
+ 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"`
}
// field type overrides for gencodec
diff --git a/core/types/gen_header_json.go b/core/types/gen_header_json.go
index 31796bf5b..b49d48f14 100644
--- a/core/types/gen_header_json.go
+++ b/core/types/gen_header_json.go
@@ -17,25 +17,26 @@ 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"`
+ 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"`
- Round hexutil.Uint64 `json:"round" gencodec:"required"`
- DexconMeta hexutil.Bytes `json:"dexconMeta" 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
@@ -58,6 +59,7 @@ func (h Header) MarshalJSON() ([]byte, error) {
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)
}
@@ -65,25 +67,26 @@ 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"`
+ 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"`
- Round *hexutil.Uint64 `json:"round" gencodec:"required"`
- DexconMeta *hexutil.Bytes `json:"dexconMeta" 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 {
@@ -163,5 +166,9 @@ 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
}