diff --git a/core/types/gen_header_json.go b/core/types/gen_header_json.go index 75e24b34d6a0..38f054b80ce9 100644 --- a/core/types/gen_header_json.go +++ b/core/types/gen_header_json.go @@ -16,23 +16,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"` - BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` - 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"` + BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` + TimeMs uint64 `json:"TimeMs" rlp:"optional"` + NextValidators []common.Address `json:"NextValidators" rlp:"optional"` + NextValidatorPowers []uint64 `json:"NextValidatorPowers" rlp:"optional"` + LastCommitHash common.Hash `json:"LastCommitHash" rlp:"optional"` + Commit *Commit `json:"Commit" rlp:"optional"` + Hash common.Hash `json:"hash"` } var enc Header enc.ParentHash = h.ParentHash @@ -51,6 +56,11 @@ func (h Header) MarshalJSON() ([]byte, error) { enc.MixDigest = h.MixDigest enc.Nonce = h.Nonce enc.BaseFee = (*hexutil.Big)(h.BaseFee) + enc.TimeMs = h.TimeMs + enc.NextValidators = h.NextValidators + enc.NextValidatorPowers = h.NextValidatorPowers + enc.LastCommitHash = h.LastCommitHash + enc.Commit = h.Commit enc.Hash = h.Hash() return json.Marshal(&enc) } @@ -58,22 +68,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"` - BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` + 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"` + BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` + TimeMs *uint64 `json:"TimeMs" rlp:"optional"` + NextValidators []common.Address `json:"NextValidators" rlp:"optional"` + NextValidatorPowers []uint64 `json:"NextValidatorPowers" rlp:"optional"` + LastCommitHash *common.Hash `json:"LastCommitHash" rlp:"optional"` + Commit *Commit `json:"Commit" rlp:"optional"` } var dec Header if err := json.Unmarshal(input, &dec); err != nil { @@ -140,5 +155,20 @@ func (h *Header) UnmarshalJSON(input []byte) error { if dec.BaseFee != nil { h.BaseFee = (*big.Int)(dec.BaseFee) } + if dec.TimeMs != nil { + h.TimeMs = *dec.TimeMs + } + if dec.NextValidators != nil { + h.NextValidators = dec.NextValidators + } + if dec.NextValidatorPowers != nil { + h.NextValidatorPowers = dec.NextValidatorPowers + } + if dec.LastCommitHash != nil { + h.LastCommitHash = *dec.LastCommitHash + } + if dec.Commit != nil { + h.Commit = dec.Commit + } return nil } diff --git a/core/types/gen_header_rlp.go b/core/types/gen_header_rlp.go index 2bac26e720b5..33b236ec956a 100644 --- a/core/types/gen_header_rlp.go +++ b/core/types/gen_header_rlp.go @@ -78,24 +78,8 @@ func (obj *Header) EncodeRLP(_w io.Writer) error { w.WriteBytes(obj.LastCommitHash[:]) } if _tmp6 { - if obj.Commit == nil { - w.Write([]byte{0xC0}) - } else { - _tmp11 := w.List() - w.WriteUint64(obj.Commit.Height) - w.WriteUint64(uint64(obj.Commit.Round)) - w.WriteBytes(obj.Commit.BlockID[:]) - _tmp12 := w.List() - for _, _tmp13 := range obj.Commit.Signatures { - _tmp14 := w.List() - w.WriteUint64(uint64(_tmp13.BlockIDFlag)) - w.WriteBytes(_tmp13.ValidatorAddress[:]) - w.WriteUint64(_tmp13.TimestampMs) - w.WriteBytes(_tmp13.Signature) - w.ListEnd(_tmp14) - } - w.ListEnd(_tmp12) - w.ListEnd(_tmp11) + if err := obj.Commit.EncodeRLP(w); err != nil { + return err } } w.ListEnd(_tmp0)