-
-
Notifications
You must be signed in to change notification settings - Fork 107
/
account.go
194 lines (172 loc) · 5.33 KB
/
account.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* Copyright (c) 2018 LI Zhennan
*
* Use of this work is governed by a MIT License.
* You may find a license copy in project root.
*/
package etherscan
// AccountBalance gets ether balance for a single address
func (c *Client) AccountBalance(address string) (balance *BigInt, err error) {
param := M{
"tag": "latest",
"address": address,
}
balance = new(BigInt)
err = c.call("account", "balance", param, balance)
return
}
// MultiAccountBalance gets ether balance for multiple addresses in a single call
func (c *Client) MultiAccountBalance(addresses ...string) (balances []AccountBalance, err error) {
param := M{
"tag": "latest",
"address": addresses,
}
balances = make([]AccountBalance, 0, len(addresses))
err = c.call("account", "balancemulti", param, &balances)
return
}
// NormalTxByAddress gets a list of "normal" transactions by address
//
// startBlock and endBlock can be nil
//
// if desc is true, result will be sorted in blockNum descendant order.
func (c *Client) NormalTxByAddress(address string, startBlock *int, endBlock *int, page int, offset int, desc bool) (txs []NormalTx, err error) {
param := M{
"address": address,
"page": page,
"offset": offset,
}
compose(param, "startblock", startBlock)
compose(param, "endblock", endBlock)
if desc {
param["sort"] = "desc"
} else {
param["sort"] = "asc"
}
err = c.call("account", "txlist", param, &txs)
return
}
// InternalTxByAddress gets a list of "internal" transactions by address
//
// startBlock and endBlock can be nil
//
// if desc is true, result will be sorted in descendant order.
func (c *Client) InternalTxByAddress(address string, startBlock *int, endBlock *int, page int, offset int, desc bool) (txs []InternalTx, err error) {
param := M{
"address": address,
"page": page,
"offset": offset,
}
compose(param, "startblock", startBlock)
compose(param, "endblock", endBlock)
if desc {
param["sort"] = "desc"
} else {
param["sort"] = "asc"
}
err = c.call("account", "txlistinternal", param, &txs)
return
}
// ERC20Transfers get a list of "erc20 - token transfer events" by
// contract address and/or from/to address.
//
// leave undesired condition to nil.
//
// Note on a Etherscan bug:
// Some ERC20 contract does not have valid decimals information in Etherscan.
// When that happens, TokenName, TokenSymbol are empty strings,
// and TokenDecimal is 0.
//
// More information can be found at:
// https://github.com/nanmu42/etherscan-api/issues/8
func (c *Client) ERC20Transfers(contractAddress, address *string, startBlock *int, endBlock *int, page int, offset int, desc bool) (txs []ERC20Transfer, err error) {
param := M{
"page": page,
"offset": offset,
}
compose(param, "contractaddress", contractAddress)
compose(param, "address", address)
compose(param, "startblock", startBlock)
compose(param, "endblock", endBlock)
if desc {
param["sort"] = "desc"
} else {
param["sort"] = "asc"
}
err = c.call("account", "tokentx", param, &txs)
return
}
// ERC721Transfers get a list of "erc721 - token transfer events" by
// contract address and/or from/to address.
//
// leave undesired condition to nil.
func (c *Client) ERC721Transfers(contractAddress, address *string, startBlock *int, endBlock *int, page int, offset int, desc bool) (txs []ERC721Transfer, err error) {
param := M{
"page": page,
"offset": offset,
}
compose(param, "contractaddress", contractAddress)
compose(param, "address", address)
compose(param, "startblock", startBlock)
compose(param, "endblock", endBlock)
if desc {
param["sort"] = "desc"
} else {
param["sort"] = "asc"
}
err = c.call("account", "tokennfttx", param, &txs)
return
}
// ERC1155Transfers get a list of "erc1155 - token transfer events" by
// contract address and/or from/to address.
//
// leave undesired condition to nil.
func (c *Client) ERC1155Transfers(contractAddress, address *string, startBlock *int, endBlock *int, page int, offset int, desc bool) (txs []ERC1155Transfer, err error) {
param := M{
"page": page,
"offset": offset,
}
compose(param, "contractaddress", contractAddress)
compose(param, "address", address)
compose(param, "startblock", startBlock)
compose(param, "endblock", endBlock)
if desc {
param["sort"] = "desc"
} else {
param["sort"] = "asc"
}
err = c.call("account", "token1155tx", param, &txs)
return
}
// BlocksMinedByAddress gets list of blocks mined by address
func (c *Client) BlocksMinedByAddress(address string, page int, offset int) (mined []MinedBlock, err error) {
param := M{
"address": address,
"blocktype": "blocks",
"page": page,
"offset": offset,
}
err = c.call("account", "getminedblocks", param, &mined)
return
}
// UnclesMinedByAddress gets list of uncles mined by address
func (c *Client) UnclesMinedByAddress(address string, page int, offset int) (mined []MinedBlock, err error) {
param := M{
"address": address,
"blocktype": "uncles",
"page": page,
"offset": offset,
}
err = c.call("account", "getminedblocks", param, &mined)
return
}
// TokenBalance get erc20-token account balance of address for contractAddress
func (c *Client) TokenBalance(contractAddress, address string) (balance *BigInt, err error) {
param := M{
"contractaddress": contractAddress,
"address": address,
"tag": "latest",
}
err = c.call("account", "tokenbalance", param, &balance)
return
}