-
Notifications
You must be signed in to change notification settings - Fork 88
/
types.go
176 lines (155 loc) · 4.01 KB
/
types.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package web3
import (
"encoding/json"
"math/big"
"time"
"github.com/gochain/gochain/v4/common"
"github.com/gochain/gochain/v4/core/types"
)
type CallMsg struct {
From *common.Address // the sender of the 'transaction'
To *common.Address // the destination contract (nil for contract creation)
Gas uint64 // if 0, the call executes with near-infinite gas
GasPrice *big.Int // wei <-> gas exchange ratio
Value *big.Int // amount of wei sent along with the call
Data []byte // input data, usually an ABI-encoded contract method invocation
}
type Snapshot struct {
Number uint64 `json:"number"`
Hash common.Hash `json:"hash"`
Signers map[common.Address]uint64 `json:"signers"`
Voters map[common.Address]struct{} `json:"voters"`
Votes []*Vote `json:"votes"`
Tally map[common.Address]Tally `json:"tally"`
}
type Vote struct {
Signer common.Address `json:"signer"`
Block uint64 `json:"block"`
Address common.Address `json:"address"`
Authorize bool `json:"authorize"`
}
type Tally struct {
Authorize bool `json:"authorize"`
Votes int `json:"votes"`
}
type ID struct {
NetworkID *big.Int `json:"network_id"`
ChainID *big.Int `json:"chain_id"`
GenesisHash common.Hash `json:"genesis_hash"`
}
type Receipt struct {
PostState []byte
Status uint64
CumulativeGasUsed uint64
Bloom types.Bloom
Logs []*types.Log
TxHash common.Hash
TxIndex uint64
ContractAddress common.Address
GasUsed uint64
ParsedLogs []Event
BlockHash common.Hash
BlockNumber uint64
From common.Address
To *common.Address
}
func (r *Receipt) UnmarshalJSON(data []byte) error {
var rr rpcReceipt
err := json.Unmarshal(data, &rr)
if err != nil {
return err
}
return rr.copyTo(r)
}
func (r *Receipt) MarshalJSON() ([]byte, error) {
var rr rpcReceipt
rr.copyFrom(r)
return json.Marshal(&rr)
}
type Block struct {
ParentHash common.Hash
Sha3Uncles common.Hash
Miner common.Address
Signers []common.Address
Voters []common.Address
Signer []byte
StateRoot common.Hash
TxsRoot common.Hash
ReceiptsRoot common.Hash
LogsBloom *types.Bloom
Difficulty *big.Int
TotalDifficulty *big.Int
Number *big.Int
GasLimit uint64
GasUsed uint64
Timestamp time.Time
ExtraData []byte
MixHash common.Hash
Nonce types.BlockNonce
Hash common.Hash
// Only one of TxHashes or TxDetails will be populated.
TxHashes []common.Hash
TxDetails []*Transaction
Uncles []common.Hash
}
func (b *Block) UnmarshalJSON(data []byte) error {
var r rpcBlock
err := json.Unmarshal(data, &r)
if err != nil {
return err
}
return r.copyTo(b)
}
func (b *Block) MarshalJSON() ([]byte, error) {
var r rpcBlock
if err := r.copyFrom(b); err != nil {
return nil, err
}
return json.Marshal(&r)
}
func (b *Block) ExtraVanity() string {
l := len(b.ExtraData)
if l > 32 {
l = 32
}
return string(b.ExtraData[:l])
}
func (b *Block) TxCount() int {
if b.TxHashes != nil {
return len(b.TxHashes)
}
return len(b.TxDetails)
}
type Transaction struct {
Nonce uint64
GasPrice *big.Int // wei
GasLimit uint64
To *common.Address
Value *big.Int // wei
Input []byte
From common.Address
V *big.Int
R *big.Int
S *big.Int
Hash common.Hash
BlockNumber *big.Int
BlockHash common.Hash
TransactionIndex uint64
}
type Event struct {
Name string `json:"name"`
Fields map[string]interface{} `json:"fields"`
}
func (t *Transaction) UnmarshalJSON(data []byte) error {
var r rpcTransaction
err := json.Unmarshal(data, &r)
if err != nil {
return err
}
return r.copyTo(t)
}
func (t *Transaction) MarshalJSON() ([]byte, error) {
var r rpcTransaction
r.copyFrom(t)
return json.Marshal(&r)
}