-
Notifications
You must be signed in to change notification settings - Fork 177
/
types.go
158 lines (144 loc) · 4.97 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
package types
import (
"fmt"
"math/big"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
watcher "github.com/okex/exchain/x/evm/watcher"
)
// Copied the Account and StorageResult types since they are registered under an
// internal pkg on geth.
// AccountResult struct for account proof
type AccountResult struct {
Address common.Address `json:"address"`
AccountProof []string `json:"accountProof"`
Balance *hexutil.Big `json:"balance"`
CodeHash common.Hash `json:"codeHash"`
Nonce hexutil.Uint64 `json:"nonce"`
StorageHash common.Hash `json:"storageHash"`
StorageProof []StorageResult `json:"storageProof"`
}
// StorageResult defines the format for storage proof return
type StorageResult struct {
Key string `json:"key"`
Value *hexutil.Big `json:"value"`
Proof []string `json:"proof"`
}
// SendTxArgs represents the arguments to submit a new transaction into the transaction pool.
// Duplicate struct definition since geth struct is in internal package
// Ref: https://github.com/ethereum/go-ethereum/blob/release/1.9/internal/ethapi/api.go#L1346
type SendTxArgs struct {
From *common.Address `json:"from"`
To *common.Address `json:"to"`
Gas *hexutil.Uint64 `json:"gas"`
GasPrice *hexutil.Big `json:"gasPrice"`
Value *hexutil.Big `json:"value"`
Nonce *hexutil.Uint64 `json:"nonce"`
// We accept "data" and "input" for backwards-compatibility reasons. "input" is the
// newer name and should be preferred by clients.
Data *hexutil.Bytes `json:"data"`
Input *hexutil.Bytes `json:"input"`
}
func (ca SendTxArgs) String() string {
var arg string
if ca.From != nil {
arg += fmt.Sprintf("From: %s, ", ca.From.String())
}
if ca.To != nil {
arg += fmt.Sprintf("To: %s, ", ca.To.String())
}
if ca.Gas != nil {
arg += fmt.Sprintf("Gas: %s, ", ca.Gas.String())
}
if ca.GasPrice != nil {
arg += fmt.Sprintf("GasPrice: %s, ", ca.GasPrice.String())
}
if ca.Value != nil {
arg += fmt.Sprintf("Value: %s, ", ca.Value.String())
}
if ca.Nonce != nil {
arg += fmt.Sprintf("Nonce: %s, ", ca.Nonce.String())
}
if ca.Data != nil {
arg += fmt.Sprintf("Data: %s, ", ca.Data.String())
}
if ca.Input != nil {
arg += fmt.Sprintf("Input: %s, ", ca.Input.String())
}
return strings.TrimRight(arg, ", ")
}
// CallArgs represents the arguments for a call.
type CallArgs struct {
From *common.Address `json:"from"`
To *common.Address `json:"to"`
Gas *hexutil.Uint64 `json:"gas"`
GasPrice *hexutil.Big `json:"gasPrice"`
Value *hexutil.Big `json:"value"`
Data *hexutil.Bytes `json:"data"`
}
func (ca CallArgs) String() string {
var arg string
if ca.From != nil {
arg += fmt.Sprintf("From: %s, ", ca.From.String())
}
if ca.To != nil {
arg += fmt.Sprintf("To: %s, ", ca.To.String())
}
if ca.Gas != nil {
arg += fmt.Sprintf("Gas: %s, ", ca.Gas.String())
}
if ca.GasPrice != nil {
arg += fmt.Sprintf("GasPrice: %s, ", ca.GasPrice.String())
}
if ca.Value != nil {
arg += fmt.Sprintf("Value: %s, ", ca.Value.String())
}
if ca.Data != nil {
arg += fmt.Sprintf("Data: %s, ", ca.Data.String())
}
return strings.TrimRight(arg, ", ")
}
// EthHeaderWithBlockHash represents a block header in the Ethereum blockchain with block hash generated from Tendermint Block
type EthHeaderWithBlockHash struct {
ParentHash common.Hash `json:"parentHash"`
UncleHash common.Hash `json:"sha3Uncles"`
Coinbase common.Address `json:"miner"`
Root common.Hash `json:"stateRoot"`
TxHash common.Hash `json:"transactionsRoot"`
ReceiptHash common.Hash `json:"receiptsRoot"`
Bloom ethtypes.Bloom `json:"logsBloom"`
Difficulty *hexutil.Big `json:"difficulty"`
Number *hexutil.Big `json:"number"`
GasLimit hexutil.Uint64 `json:"gasLimit"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
Time hexutil.Uint64 `json:"timestamp"`
Extra hexutil.Bytes `json:"extraData"`
MixDigest common.Hash `json:"mixHash"`
Nonce ethtypes.BlockNonce `json:"nonce"`
Hash common.Hash `json:"hash"`
}
type FeeHistoryResult struct {
OldestBlock *hexutil.Big `json:"oldestBlock"`
Reward [][]*hexutil.Big `json:"reward,omitempty"`
BaseFee []*hexutil.Big `json:"baseFeePerGas,omitempty"`
GasUsedRatio []float64 `json:"gasUsedRatio"`
}
// SignTransactionResult represents a RLP encoded signed transaction.
type SignTransactionResult struct {
Raw hexutil.Bytes `json:"raw"`
Tx *watcher.Transaction `json:"tx"`
}
type GPIn3Gears struct {
SafeLow *hexutil.Big `json:"safe_low"`
Average *hexutil.Big `json:"average"`
Fastest *hexutil.Big `json:"fastest"`
}
func NewGPIn3Gears(safelow, avg, fastest *big.Int) GPIn3Gears {
return GPIn3Gears{
SafeLow: (*hexutil.Big)(safelow),
Average: (*hexutil.Big)(avg),
Fastest: (*hexutil.Big)(fastest),
}
}