forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 136
/
gen_blockmetadata.go
82 lines (76 loc) 路 2.85 KB
/
gen_blockmetadata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
package engine
import (
"encoding/json"
"errors"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)
var _ = (*blockMetadataMarshaling)(nil)
// MarshalJSON marshals as JSON.
func (b BlockMetadata) MarshalJSON() ([]byte, error) {
type BlockMetadata struct {
Beneficiary common.Address `json:"beneficiary" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
Timestamp hexutil.Uint64 `json:"timestamp" gencodec:"required"`
MixHash common.Hash `json:"mixHash" gencodec:"required"`
TxList hexutil.Bytes `json:"txList" gencodec:"required"`
HighestBlockID *big.Int `json:"highestBlockID" gencodec:"required"`
ExtraData []byte `json:"extraData" gencodec:"required"`
}
var enc BlockMetadata
enc.Beneficiary = b.Beneficiary
enc.GasLimit = b.GasLimit
enc.Timestamp = hexutil.Uint64(b.Timestamp)
enc.MixHash = b.MixHash
enc.TxList = b.TxList
enc.HighestBlockID = b.HighestBlockID
enc.ExtraData = b.ExtraData
return json.Marshal(&enc)
}
// UnmarshalJSON unmarshals from JSON.
func (b *BlockMetadata) UnmarshalJSON(input []byte) error {
type BlockMetadata struct {
Beneficiary *common.Address `json:"beneficiary" gencodec:"required"`
GasLimit *uint64 `json:"gasLimit" gencodec:"required"`
Timestamp *hexutil.Uint64 `json:"timestamp" gencodec:"required"`
MixHash *common.Hash `json:"mixHash" gencodec:"required"`
TxList *hexutil.Bytes `json:"txList" gencodec:"required"`
HighestBlockID *big.Int `json:"highestBlockID" gencodec:"required"`
ExtraData []byte `json:"extraData" gencodec:"required"`
}
var dec BlockMetadata
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
if dec.Beneficiary == nil {
return errors.New("missing required field 'beneficiary' for BlockMetadata")
}
b.Beneficiary = *dec.Beneficiary
if dec.GasLimit == nil {
return errors.New("missing required field 'gasLimit' for BlockMetadata")
}
b.GasLimit = *dec.GasLimit
if dec.Timestamp == nil {
return errors.New("missing required field 'timestamp' for BlockMetadata")
}
b.Timestamp = uint64(*dec.Timestamp)
if dec.MixHash == nil {
return errors.New("missing required field 'mixHash' for BlockMetadata")
}
b.MixHash = *dec.MixHash
if dec.TxList == nil {
return errors.New("missing required field 'txList' for BlockMetadata")
}
b.TxList = *dec.TxList
if dec.HighestBlockID == nil {
return errors.New("missing required field 'highestBlockID' for BlockMetadata")
}
b.HighestBlockID = dec.HighestBlockID
if dec.ExtraData == nil {
return errors.New("missing required field 'extraData' for BlockMetadata")
}
b.ExtraData = dec.ExtraData
return nil
}