-
Notifications
You must be signed in to change notification settings - Fork 2
/
gen_eth_tx_json.go
101 lines (95 loc) · 3.28 KB
/
gen_eth_tx_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
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
package types
import (
"encoding/json"
"errors"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)
var _ = (*ethTxdataMarshaling)(nil)
// MarshalJSON marshals as JSON.
func (e ethTxdata) MarshalJSON() ([]byte, error) {
type ethTxdata struct {
AccountNonce hexutil.Uint64 `json:"nonce" gencodec:"required"`
Price *hexutil.Big `json:"gasPrice" gencodec:"required"`
GasLimit hexutil.Uint64 `json:"gas" gencodec:"required"`
Recipient *common.Address `json:"to" rlp:"nil"`
Amount *hexutil.Big `json:"value" gencodec:"required"`
Payload hexutil.Bytes `json:"input" gencodec:"required"`
V *hexutil.Big `json:"v" gencodec:"required"`
R *hexutil.Big `json:"r" gencodec:"required"`
S *hexutil.Big `json:"s" gencodec:"required"`
Hash *common.Hash `json:"hash" rlp:"-"`
}
var enc ethTxdata
enc.AccountNonce = hexutil.Uint64(e.AccountNonce)
enc.Price = (*hexutil.Big)(e.Price)
enc.GasLimit = hexutil.Uint64(e.GasLimit)
enc.Recipient = e.Recipient
enc.Amount = (*hexutil.Big)(e.Amount)
enc.Payload = e.Payload
enc.V = (*hexutil.Big)(e.V)
enc.R = (*hexutil.Big)(e.R)
enc.S = (*hexutil.Big)(e.S)
enc.Hash = e.Hash
return json.Marshal(&enc)
}
// UnmarshalJSON unmarshals from JSON.
func (e *ethTxdata) UnmarshalJSON(input []byte) error {
type ethTxdata struct {
AccountNonce *hexutil.Uint64 `json:"nonce" gencodec:"required"`
Price *hexutil.Big `json:"gasPrice" gencodec:"required"`
GasLimit *hexutil.Uint64 `json:"gas" gencodec:"required"`
Recipient *common.Address `json:"to" rlp:"nil"`
Amount *hexutil.Big `json:"value" gencodec:"required"`
Payload *hexutil.Bytes `json:"input" gencodec:"required"`
V *hexutil.Big `json:"v" gencodec:"required"`
R *hexutil.Big `json:"r" gencodec:"required"`
S *hexutil.Big `json:"s" gencodec:"required"`
Hash *common.Hash `json:"hash" rlp:"-"`
}
var dec ethTxdata
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
if dec.AccountNonce == nil {
return errors.New("missing required field 'nonce' for ethTxdata")
}
e.AccountNonce = uint64(*dec.AccountNonce)
if dec.Price == nil {
return errors.New("missing required field 'gasPrice' for ethTxdata")
}
e.Price = (*big.Int)(dec.Price)
if dec.GasLimit == nil {
return errors.New("missing required field 'gas' for ethTxdata")
}
e.GasLimit = uint64(*dec.GasLimit)
if dec.Recipient != nil {
e.Recipient = dec.Recipient
}
if dec.Amount == nil {
return errors.New("missing required field 'value' for ethTxdata")
}
e.Amount = (*big.Int)(dec.Amount)
if dec.Payload == nil {
return errors.New("missing required field 'input' for ethTxdata")
}
e.Payload = *dec.Payload
if dec.V == nil {
return errors.New("missing required field 'v' for ethTxdata")
}
e.V = (*big.Int)(dec.V)
if dec.R == nil {
return errors.New("missing required field 'r' for ethTxdata")
}
e.R = (*big.Int)(dec.R)
if dec.S == nil {
return errors.New("missing required field 's' for ethTxdata")
}
e.S = (*big.Int)(dec.S)
if dec.Hash != nil {
e.Hash = dec.Hash
}
return nil
}