-
Notifications
You must be signed in to change notification settings - Fork 4
/
gen_header_json.go
130 lines (124 loc) · 4.7 KB
/
gen_header_json.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
package types
import (
"encoding/json"
"errors"
"github.com/LemoFoundationLtd/lemochain-go/common"
"github.com/LemoFoundationLtd/lemochain-go/common/hexutil"
)
var _ = (*headerMarshaling)(nil)
// MarshalJSON marshals as JSON.
func (h Header) MarshalJSON() ([]byte, error) {
type Header struct {
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
MinerAddress common.Address `json:"miner" gencodec:"required"`
VersionRoot common.Hash `json:"versionRoot" gencodec:"required"`
TxRoot common.Hash `json:"transactionRoot" gencodec:"required"`
LogRoot common.Hash `json:"changeLogRoot" gencodec:"required"`
EventRoot common.Hash `json:"eventRoot" gencodec:"required"`
Bloom Bloom `json:"eventBloom" gencodec:"required"`
Height hexutil.Uint32 `json:"height" gencodec:"required"`
GasLimit hexutil.Uint64 `json:"gasLimit" gencodec:"required"`
GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
Time hexutil.Uint32 `json:"timestamp" gencodec:"required"`
SignData hexutil.Bytes `json:"signData" gencodec:"required"`
DeputyRoot hexutil.Bytes `json:"deputyRoot"`
Extra hexutil.Bytes `json:"extraData"`
Hash common.Hash `json:"hash"`
}
var enc Header
enc.ParentHash = h.ParentHash
enc.MinerAddress = h.MinerAddress
enc.VersionRoot = h.VersionRoot
enc.TxRoot = h.TxRoot
enc.LogRoot = h.LogRoot
enc.EventRoot = h.EventRoot
enc.Bloom = h.Bloom
enc.Height = hexutil.Uint32(h.Height)
enc.GasLimit = hexutil.Uint64(h.GasLimit)
enc.GasUsed = hexutil.Uint64(h.GasUsed)
enc.Time = hexutil.Uint32(h.Time)
enc.SignData = h.SignData
enc.DeputyRoot = h.DeputyRoot
enc.Extra = h.Extra
enc.Hash = h.Hash()
return json.Marshal(&enc)
}
// UnmarshalJSON unmarshals from JSON.
func (h *Header) UnmarshalJSON(input []byte) error {
type Header struct {
ParentHash *common.Hash `json:"parentHash" gencodec:"required"`
MinerAddress *common.Address `json:"miner" gencodec:"required"`
VersionRoot *common.Hash `json:"versionRoot" gencodec:"required"`
TxRoot *common.Hash `json:"transactionRoot" gencodec:"required"`
LogRoot *common.Hash `json:"changeLogRoot" gencodec:"required"`
EventRoot *common.Hash `json:"eventRoot" gencodec:"required"`
Bloom *Bloom `json:"eventBloom" gencodec:"required"`
Height *hexutil.Uint32 `json:"height" gencodec:"required"`
GasLimit *hexutil.Uint64 `json:"gasLimit" gencodec:"required"`
GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
Time *hexutil.Uint32 `json:"timestamp" gencodec:"required"`
SignData *hexutil.Bytes `json:"signData" gencodec:"required"`
DeputyRoot *hexutil.Bytes `json:"deputyRoot"`
Extra *hexutil.Bytes `json:"extraData"`
}
var dec Header
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
if dec.ParentHash == nil {
return errors.New("missing required field 'parentHash' for Header")
}
h.ParentHash = *dec.ParentHash
if dec.MinerAddress == nil {
return errors.New("missing required field 'miner' for Header")
}
h.MinerAddress = *dec.MinerAddress
if dec.VersionRoot == nil {
return errors.New("missing required field 'versionRoot' for Header")
}
h.VersionRoot = *dec.VersionRoot
if dec.TxRoot == nil {
return errors.New("missing required field 'transactionRoot' for Header")
}
h.TxRoot = *dec.TxRoot
if dec.LogRoot == nil {
return errors.New("missing required field 'changeLogRoot' for Header")
}
h.LogRoot = *dec.LogRoot
if dec.EventRoot == nil {
return errors.New("missing required field 'eventRoot' for Header")
}
h.EventRoot = *dec.EventRoot
if dec.Bloom == nil {
return errors.New("missing required field 'eventBloom' for Header")
}
h.Bloom = *dec.Bloom
if dec.Height == nil {
return errors.New("missing required field 'height' for Header")
}
h.Height = uint32(*dec.Height)
if dec.GasLimit == nil {
return errors.New("missing required field 'gasLimit' for Header")
}
h.GasLimit = uint64(*dec.GasLimit)
if dec.GasUsed == nil {
return errors.New("missing required field 'gasUsed' for Header")
}
h.GasUsed = uint64(*dec.GasUsed)
if dec.Time == nil {
return errors.New("missing required field 'timestamp' for Header")
}
h.Time = uint32(*dec.Time)
if dec.SignData == nil {
return errors.New("missing required field 'signData' for Header")
}
h.SignData = *dec.SignData
if dec.DeputyRoot != nil {
h.DeputyRoot = *dec.DeputyRoot
}
if dec.Extra != nil {
h.Extra = *dec.Extra
}
return nil
}