-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathaddress.go
347 lines (310 loc) · 14.4 KB
/
address.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
package blockchair
import (
"encoding/json"
"strings"
)
// DataAddress includes full server response to address request.
type DataAddress struct {
Data map[string]AddressInfo `json:"data"`
Context ContextAddress `json:"context"`
}
// DataAddressEth includes full server response to address request for Ethereum.
type DataAddressEth struct {
Data map[string]AddressInfoEth `json:"data"`
Context ContextAddress `json:"context"`
}
// DataMultichain includes full server response to multichain address check request.
type DataMultichain struct {
Data MultichainInfo `json:"data"`
Context Context `json:"context"`
}
// DataAddresses includes full server response to addresses request.
type DataAddresses struct {
Data AddressesInfo `json:"data"`
Context ContextAddress `json:"context"`
}
// DataXpub includes full server response to xpub request.
type DataXpub struct {
Data map[string]XpubInfo `json:"data"`
Context ContextAddress `json:"context"`
}
// XpubInfo describes the outer structure of the x/z/v-pub.
type XpubInfo struct {
Xpub Xpub `json:"xpub"`
Addresses map[string]Address `json:"addresses"`
Transactions []string `json:"transactions"`
Utxo []Utxo `json:"utxo"`
}
// MultichainInfo describes the outer structure of the multichain address check.
type MultichainInfo struct {
Set SetMultichain `json:"set"`
Addresses map[string]MultichainAddress `json:"addresses"`
Transactions []TransactionsMultichain `json:"transactions"`
}
// Xpub describes the inner structure of the x/z/v-pub.
type Xpub struct {
AddressCount int `json:"address_count"`
Balance int `json:"balance"`
BalanceUsd float64 `json:"balance_usd"`
Received int `json:"received"`
Spent int `json:"spent"`
OutputCount int `json:"output_count"`
UnspentOutputCount int `json:"unspent_output_count"`
FirstSeenReceiving string `json:"first_seen_receiving,omitempty"`
LastSeenReceiving string `json:"last_seen_receiving,omitempty"`
FirstSeenSpending string `json:"first_seen_spending,omitempty"`
LastSeenSpending string `json:"last_seen_spending,omitempty"`
TransactionCount int `json:"transaction_count"`
}
// AddressesInfo describes the outer structure of the addresses.
type AddressesInfo struct {
Set Set `json:"set"`
Addresses map[string]Address `json:"addresses"`
Transactions []string `json:"transactions"`
Utxo []Utxo `json:"utxo"`
}
// AddressInfoEth the structure of the set of address and calls for Ethereum.
type AddressInfoEth struct {
Address AddressEth `json:"address"`
Calls []CallsAddress `json:"calls"`
}
// Set the structure of the set for Bitcoin-like address.
type Set struct {
AddressCount int `json:"address_count"`
Balance int64 `json:"balance"`
BalanceUsd float32 `json:"balance_usd"`
Received int64 `json:"received"`
Spent int `json:"spent"`
OutputCount int `json:"output_count"`
UnspentOutputCount int `json:"unspent_output_count"`
FirstSeenReceiving string `json:"first_seen_receiving"`
LastSeenReceiving string `json:"last_seen_receiving"`
FirstSeenSpending string `json:"first_seen_spending"`
LastSeenSpending string `json:"last_seen_spending"`
TransactionCount int `json:"transaction_count"`
}
// SetMultichain the structure of the set for the multichain address check.
type SetMultichain struct {
AddressCount int `json:"address_count"`
BalanceUsd float32 `json:"balance_usd"`
ReceivedUsd float32 `json:"received_usd"`
FirstSeenReceiving string `json:"first_seen_receiving"`
LastSeenReceiving string `json:"last_seen_receiving"`
FirstSeenSpending string `json:"first_seen_spending"`
LastSeenSpending string `json:"last_seen_spending"`
TransactionCount int `json:"transaction_count"`
}
// AddressInfo structure of the set of address, transactions, and utxo.
type AddressInfo struct {
Address Address `json:"address"`
Transactions []string `json:"transactions"`
Utxo []Utxo `json:"utxo"`
}
// AddressEth is the structure of one specific Ethereum address.
type AddressEth struct {
Type string `json:"type"`
ContractCodeHex string `json:"contract_code_hex,omitempty"`
ContractCreated string `json:"contract_created,omitempty"`
ContractDestroyed string `json:"contract_destroyed,omitempty"`
Balance string `json:"balance"`
BalanceUsd float64 `json:"balance_usd"` //maybe 32?
ReceivedApproximate string `json:"received_approximate"`
ReceivedUsd float64 `json:"received_usd"`
SpentApproximate string `json:"spent_approximate"`
SpentUsd float64 `json:"spent_usd"`
FeesApproximate string `json:"fees_approximate"`
FeesUsd float64 `json:"fees_usd"`
ReceivingCallCount int `json:"receiving_call_count"`
SpendingCallCount int `json:"spending_call_count"`
CallCount int `json:"call_count"`
TransactionCount int `json:"transaction_count"`
FirstSeenReceiving string `json:"first_seen_receiving"`
LastSeenReceiving string `json:"last_seen_receiving"`
FirstSeenSpending string `json:"first_seen_spending,omitempty"`
LastSeenSpending string `json:"last_seen_spending,omitempty"`
Nonce int `json:"nonce,omitempty"`
}
// Address the structure of one specific Bitcoin-like address.
type Address struct {
Path string `json:"path,omitempty"`
Type string `json:"type"`
ScriptHex string `json:"script_hex"`
Balance float32 `json:"balance"`
BalanceUsd float32 `json:"balance_usd"`
Received float32 `json:"received"`
ReceivedUsd float32 `json:"received_usd"`
Spent float32 `json:"spent"`
SpentUsd float32 `json:"spent_usd"`
OutputCount int `json:"output_count"`
UnspentOutputCount int `json:"unspent_output_count"`
FirstSeenReceiving string `json:"first_seen_receiving,omitempty"`
LastSeenReceiving string `json:"last_seen_receiving,omitempty"`
FirstSeenSpending string `json:"first_seen_spending,omitempty"`
LastSeenSpending string `json:"last_seen_spending,omitempty"`
ScripthashType string `json:"scripthash_type,omitempty"`
TransactionCount int `json:"transaction_count,omitempty"`
}
// Utxo the structure of utxo.
type Utxo struct {
BlockID int `json:"block_id"`
TransactionHash string `json:"transaction_hash"`
Index int `json:"index"`
Value int `json:"value"`
}
// CallsAddress is the structures of calls.
type CallsAddress struct {
BlockID int `json:"block_id"`
TransactionHash string `json:"transaction_hash,omitempty"`
Index string `json:"index"`
Time string `json:"time"`
Sender string `json:"sender,omitempty"`
Recipient string `json:"recipient"`
Value float64 `json:"value"`
ValueUsd float64 `json:"value_usd"`
Transferred bool `json:"transferred"`
}
// MultichainAddress is the structures of multichain address for Bitcoin-like and Ethereum.
type MultichainAddress struct {
Chain string `json:"chain"`
Address string `json:"address"`
Type string `json:"type"`
ScriptHex string `json:"script_hex,omitempty"`
ContractCodeHex string `json:"contract_code_hex,omitempty"`
ContractCreated string `json:"contract_created,omitempty"`
ContractDestroyed string `json:"contract_destroyed,omitempty"`
Balance json.Number `json:"balance"` //int64 for Bitcoin-like and string for Ethereum TODO!
BalanceUsd float32 `json:"balance_usd"`
Received float32 `json:"received,omitempty"`
ReceivedApproximate string `json:"received_approximate,omitempty"`
ReceivedUsd float32 `json:"received_usd"`
Spent float32 `json:"spent,omitempty"`
SpentApproximate string `json:"spent_approximate,omitempty"`
SpentUsd float32 `json:"spent_usd"`
OutputCount int `json:"output_count,omitempty"`
UnspentOutputCount int `json:"unspent_output_count,omitempty"`
FeesApproximate string `json:"fees_approximate,omitempty"`
FeesUsd float32 `json:"fees_usd,omitempty"`
ReceivingCallCount int `json:"receiving_call_count,omitempty"`
SpendingCallCount int `json:"spending_call_count,omitempty"`
CallCount int `json:"call_count,omitempty"`
TransactionCount int `json:"transaction_count,omitempty"`
FirstSeenReceiving string `json:"first_seen_receiving"`
LastSeenReceiving string `json:"last_seen_receiving"`
FirstSeenSpending string `json:"first_seen_spending,omitempty"`
LastSeenSpending string `json:"last_seen_spending,omitempty"`
Nonce int `json:"nonce,omitempty"`
}
// TransactionsMultichain is the structure of one specific transaction.
type TransactionsMultichain struct {
Chain string `json:"chain"`
Address string `json:"address"`
BlockID int32 `json:"block_id"`
Hash string `json:"hash"`
Time string `json:"time"`
BalanceChange float32 `json:"balance_change"`
}
// ContextAddress the structure of context for address(es).
// TODO! FIX "CHECKED" INTO A SLICE
type ContextAddress struct {
Code int `json:"code"`
Source string `json:"source"`
Limit string `json:"limit"`
Offset string `json:"offset"`
Results int `json:"results"`
Checked []string `json:"checked,omitempty"`
State int `json:"state"`
MarketPriceUsd float32 `json:"market_price_usd"`
Cache *Cache `json:"cache"`
API *API `json:"api"`
Servers string `json:"servers"`
Time float32 `json:"time"`
RenderTime float32 `json:"render_time"`
FullTime float32 `json:"full_time"`
RequestCost float32 `json:"request_cost"`
}
// GetAddress get the address by type of crypto and address hash.
func (c *Client) GetAddress(crypto string, address string) (*DataAddress, error) {
return c.GetAddressAdv(crypto, address, nil)
}
// GetAddressAdv get the address by type of crypto, address hash, and options.
func (c *Client) GetAddressAdv(crypto string, address string, options map[string]string) (resp *DataAddress, e error) {
if e = c.ValidateCrypto(crypto); e != nil {
return
}
resp = &DataAddress{}
var path = crypto + "/dashboards/address/" + address
return resp, c.LoadResponse(path, resp, options)
}
// GetAddresses get the addresses by type of crypto and addresses hash.
func (c *Client) GetAddresses(crypto string, addresses []string) (*DataAddresses, error) {
return c.GetAddressesAdv(crypto, addresses, nil)
}
// GetAddressesAdv get the addresses by type of crypto, addresses hash and options.
func (c *Client) GetAddressesAdv(crypto string, addresses []string, options map[string]string) (resp *DataAddresses, e error) {
if e = c.ValidateCrypto(crypto); e != nil {
return
}
resp = &DataAddresses{}
var path = crypto + "/dashboards/addresses/" + strings.Join(addresses, ",")
return resp, c.LoadResponse(path, resp, options)
}
// GetXpub get the xpub/ypub/zpub by type of crypto and the extended key.
// xpub (supported for all blockchains), ypub (supported for Bitcoin, Litecoin, Groestlcoin, and Bitcoin Testnet only) and zpub (supported for Bitcoin, Litecoin, Groestlcoin, and Bitcoin Testnet only)
func (c *Client) GetXpub(crypto string, extendedKey string) (*DataXpub, error) {
return c.GetXpubAdv(crypto, extendedKey, nil)
}
// GetXpubAdv get the xpub/ypub/zpub by type of crypto, the extended key, and options.
// xpub (supported for all blockchains), ypub (supported for Bitcoin, Litecoin, Groestlcoin, and Bitcoin Testnet only) and zpub (supported for Bitcoin, Litecoin, Groestlcoin, and Bitcoin Testnet only)
func (c *Client) GetXpubAdv(crypto string, extendedKey string, options map[string]string) (resp *DataXpub, e error) {
if e = c.ValidateCryptoBoth(crypto); e != nil {
return
}
resp = &DataXpub{}
var path = crypto + "/dashboards/xpub/" + extendedKey
return resp, c.LoadResponse(path, resp, options)
}
// GetAddressEth get the address by type of crypto and address hash for Ethereum.
func (c *Client) GetAddressEth(crypto string, address string) (*DataAddressEth, error) {
return c.GetAddressEthAdv(crypto, address, nil)
}
// GetAddressEthAdv get the address by type of crypto, address hash, and options for Ethereum.
// TODO! Validate address
func (c *Client) GetAddressEthAdv(crypto string, address string, options map[string]string) (resp *DataAddressEth, e error) {
if e = c.ValidateCryptoEth(crypto); e != nil {
return
}
resp = &DataAddressEth{}
var path = crypto + "/dashboards/address/" + address
return resp, c.LoadResponse(path, resp, options)
}
// MutliAddress struct for usage with GetMutlichainAddressCheck(Adv), sends type of crypto and address.
type MutliAddress []struct {
currency, address string
}
// GetMutlichainAddressCheck check multiple addresses from different blockchain via just one request. This can be useful if you're monitoring your own wallet or portfolio.
func (c *Client) GetMutlichainAddressCheck(mutliAddress MutliAddress) (resp *DataMultichain, e error) {
return c.GetMutlichainAddressCheckAdv(mutliAddress, nil)
}
// GetMutlichainAddressCheckAdv check multiple addresses from different blockchain via just one request. This can be useful if you're monitoring your own wallet or portfolio with options.
func (c *Client) GetMutlichainAddressCheckAdv(mutliAddress MutliAddress, options map[string]string) (resp *DataMultichain, e error) {
if len(mutliAddress) >= 100 { // max 100 addresses
return nil, c.err1(ErrMAX)
}
ethCount := 0
var formatMultiAddr []string
for j := range mutliAddress {
if e = c.ValidateCryptoMultichain(mutliAddress[j].currency); e != nil {
return
}
if mutliAddress[j].currency == "ethereum" {
ethCount++
if ethCount > 1 {
return nil, c.err1(ErrETH)
}
}
formatMultiAddr = append(formatMultiAddr, mutliAddress[j].currency+":"+mutliAddress[j].address)
}
resp = &DataMultichain{}
var path = "multi/dashboards/addresses/" + strings.Join(formatMultiAddr, ",")
return resp, c.LoadResponse(path, resp, options)
}