11package blockchair
22
33import (
4- "fmt"
5- "log"
64 "strings"
75)
86
7+ // DataAddress includes full server response to address request.
98type DataAddress struct {
109 Data map [string ]AddressInfo `json:"data"`
1110 Context ContextAddress `json:"context"`
1211}
1312
13+ // DataAddressEth includes full server response to address request for Ethereum.
1414type DataAddressEth struct {
1515 Data map [string ]AddressInfoEth `json:"data"`
1616 Context ContextAddress `json:"context"`
1717}
1818
19+ // DataAddresses includes full server response to addresses request.
1920type DataAddresses struct {
2021 Data AddressesInfo `json:"data"`
2122 Context ContextAddress `json:"context"`
2223}
2324
25+ // DataXpub includes full server response to xpub request.
2426type DataXpub struct {
2527 Data map [string ]XpubInfo `json:"data"`
2628 Context ContextAddress `json:"context"`
2729}
2830
31+ // XpubInfo describes the outer structure of the x/z/v-pub.
2932type XpubInfo struct {
3033 Xpub Xpub `json:"xpub"`
3134 Addresses map [string ]Address `json:"addresses"`
3235 Transactions []string `json:"transactions"`
3336 Utxo []Utxo `json:"utxo"`
3437}
3538
39+ // Xpub describes the inner structure of the x/z/v-pub.
3640type Xpub struct {
3741 AddressCount int `json:"address_count"`
3842 Balance int `json:"balance"`
@@ -41,25 +45,28 @@ type Xpub struct {
4145 Spent int `json:"spent"`
4246 OutputCount int `json:"output_count"`
4347 UnspentOutputCount int `json:"unspent_output_count"`
44- FirstSeenReceiving string `json:"first_seen_receiving"`
45- LastSeenReceiving string `json:"last_seen_receiving"`
46- FirstSeenSpending string `json:"first_seen_spending"`
47- LastSeenSpending string `json:"last_seen_spending"`
48+ FirstSeenReceiving string `json:"first_seen_receiving,omitempty "`
49+ LastSeenReceiving string `json:"last_seen_receiving,omitempty "`
50+ FirstSeenSpending string `json:"first_seen_spending,omitempty "`
51+ LastSeenSpending string `json:"last_seen_spending,omitempty "`
4852 TransactionCount int `json:"transaction_count"`
4953}
5054
55+ // AddressesInfo describes the outer structure of the addresses.
5156type AddressesInfo struct {
5257 Set Set `json:"set"`
5358 Addresses map [string ]Address `json:"addresses"`
5459 Transactions []string `json:"transactions"`
5560 Utxo []Utxo `json:"utxo"`
5661}
5762
63+ // AddressInfoEth the structure of the set of address and calls for Ethereum.
5864type AddressInfoEth struct {
5965 Address AddressEth `json:"address"`
6066 Calls []CallsAddress `json:"calls"`
6167}
6268
69+ // Set the structure of the set for Bitcoin-like address.
6370type Set struct {
6471 AddressCount int `json:"address_count"`
6572 Balance int64 `json:"balance"`
@@ -75,25 +82,27 @@ type Set struct {
7582 TransactionCount int `json:"transaction_count"`
7683}
7784
85+ // AddressInfo structure of the set of address, transactions, and utxo.
7886type AddressInfo struct {
7987 Address Address `json:"address"`
8088 Transactions []string `json:"transactions"`
8189 Utxo []Utxo `json:"utxo"`
8290}
8391
92+ // AddressEth is the structure of one specific Ethereum address.
8493type AddressEth struct {
8594 Type string `json:"type"`
86- ContractCodeHex string `json:"contract_code_hex"`
87- ContractCreated string `json:"contract_created"`
88- ContractDestroyed string `json:"contract_destroyed"`
95+ ContractCodeHex string `json:"contract_code_hex,omitempty "`
96+ ContractCreated string `json:"contract_created,omitempty "`
97+ ContractDestroyed string `json:"contract_destroyed,omitempty "`
8998 Balance string `json:"balance"`
90- BalanceUsd float64 `json:"balance_usd"`
99+ BalanceUsd float32 `json:"balance_usd"`
91100 ReceivedApproximate string `json:"received_approximate"`
92- ReceivedUsd float64 `json:"received_usd"`
101+ ReceivedUsd float32 `json:"received_usd"`
93102 SpentApproximate string `json:"spent_approximate"`
94- SpentUsd float64 `json:"spent_usd"`
103+ SpentUsd float32 `json:"spent_usd"`
95104 FeesApproximate string `json:"fees_approximate"`
96- FeesUsd float64 `json:"fees_usd"`
105+ FeesUsd float32 `json:"fees_usd"`
97106 ReceivingCallCount int `json:"receiving_call_count"`
98107 SpendingCallCount int `json:"spending_call_count"`
99108 CallCount int `json:"call_count"`
@@ -102,118 +111,134 @@ type AddressEth struct {
102111 LastSeenReceiving string `json:"last_seen_receiving"`
103112 FirstSeenSpending string `json:"first_seen_spending"`
104113 LastSeenSpending string `json:"last_seen_spending"`
105- Nonce int `json:"nonce"`
114+ Nonce int `json:"nonce,omitempty "`
106115}
107116
117+ // Address the structure of one specific Bitcoin-like address.
108118type Address struct {
119+ Path string `json:"path,omitempty"`
109120 Type string `json:"type"`
110121 ScriptHex string `json:"script_hex"`
111- Balance int64 `json:"balance"`
122+ Balance float32 `json:"balance"`
112123 BalanceUsd float32 `json:"balance_usd"`
113- Received int64 `json:"received"`
124+ Received float32 `json:"received"`
114125 ReceivedUsd float32 `json:"received_usd"`
115- Spent int `json:"spent"`
126+ Spent float32 `json:"spent"`
116127 SpentUsd float32 `json:"spent_usd"`
117128 OutputCount int `json:"output_count"`
118129 UnspentOutputCount int `json:"unspent_output_count"`
119- FirstSeenReceiving string `json:"first_seen_receiving"`
120- LastSeenReceiving string `json:"last_seen_receiving"`
121- FirstSeenSpending string `json:"first_seen_spending"`
122- LastSeenSpending string `json:"last_seen_spending"`
123- ScripthashType string `json:"scripthash_type"`
124- TransactionCount int `json:"transaction_count"`
130+ FirstSeenReceiving string `json:"first_seen_receiving,omitempty "`
131+ LastSeenReceiving string `json:"last_seen_receiving,omitempty "`
132+ FirstSeenSpending string `json:"first_seen_spending,omitempty "`
133+ LastSeenSpending string `json:"last_seen_spending,omitempty "`
134+ ScripthashType string `json:"scripthash_type,omitempty "`
135+ TransactionCount int `json:"transaction_count,omitempty "`
125136}
126137
138+ // Utxo the structure of utxo.
127139type Utxo struct {
128140 BlockID int `json:"block_id"`
129141 TransactionHash string `json:"transaction_hash"`
130142 Index int `json:"index"`
131143 Value int `json:"value"`
132144}
133145
146+ // CallsAddress is the structures of calls.
134147type CallsAddress struct {
135148 BlockID int `json:"block_id"`
136- TransactionHash string `json:"transaction_hash"`
149+ TransactionHash string `json:"transaction_hash,omitempty "`
137150 Index string `json:"index"`
138151 Time string `json:"time"`
139- Sender string `json:"sender"`
152+ Sender string `json:"sender,omitempty "`
140153 Recipient string `json:"recipient"`
141154 Value float64 `json:"value"`
142155 ValueUsd float64 `json:"value_usd"`
143156 Transferred bool `json:"transferred"`
144157}
145158
146159// ContextAddress TODO! FIX "CHECKED" INTO A SLICE
160+ // the structure of context for address(es).
147161type ContextAddress struct {
148162 Code int `json:"code"`
149163 Source string `json:"source"`
150164 Limit string `json:"limit"`
151165 Offset string `json:"offset"`
152166 Results int `json:"results"`
153- Checked []string `json:"checked"`
167+ Checked []string `json:"checked,omitempty "`
154168 State int `json:"state"`
155169 MarketPriceUsd float32 `json:"market_price_usd"`
156170 Cache * Cache `json:"cache"`
157- API * Api `json:"api"`
171+ API * API `json:"api"`
158172 Server string `json:"server"`
159173 Time float32 `json:"time"`
160174 RenderTime float32 `json:"render_time"`
161175 FullTime float32 `json:"full_time"`
162176 RequestCost float32 `json:"request_cost"`
163177}
164178
179+ // GetAddress get the address by type of crypto and address hash.
165180func (c * Client ) GetAddress (crypto string , address string ) (* DataAddress , error ) {
166- if ! Contains (GetSupportedCrypto (), crypto ) {
167- log .Fatalf ("error: %v is not supported" , crypto )
168- }
169- rsp := & DataAddress {}
170- var path = crypto + "/dashboards/address/" + address
171- e := c .loadResponse (path , rsp )
181+ return c .GetAddressAdv (crypto , address , nil )
182+ }
172183
173- if e != nil {
174- fmt .Print (e )
184+ // GetAddressAdv get the address by type of crypto, address hash, and options.
185+ func (c * Client ) GetAddressAdv (crypto string , address string , options map [string ]string ) (resp * DataAddress , e error ) {
186+ if e = c .ValidateCrypto (crypto ); e != nil {
187+ return
175188 }
176- return rsp , e
189+
190+ resp = & DataAddress {}
191+ var path = crypto + "/dashboards/address/" + address
192+ return resp , c .LoadResponse (path , resp , options )
177193}
178194
195+ // GetAddresses get the addresses by type of crypto and addresses hash.
179196func (c * Client ) GetAddresses (crypto string , addresses []string ) (* DataAddresses , error ) {
180- if ! Contains (GetSupportedCrypto (), crypto ) {
181- log .Fatalf ("error: %v is not supported" , crypto )
182- }
183- rsp := & DataAddresses {}
184- var path = crypto + "/dashboards/addresses/" + strings .Join (addresses , "," )
185- e := c .loadResponse (path , rsp )
197+ return c .GetAddressesAdv (crypto , addresses , nil )
198+ }
186199
187- if e != nil {
188- fmt .Print (e )
200+ // GetAddressesAdv get the addresses by type of crypto, addresses hash and options.
201+ func (c * Client ) GetAddressesAdv (crypto string , addresses []string , options map [string ]string ) (resp * DataAddresses , e error ) {
202+ if e = c .ValidateCrypto (crypto ); e != nil {
203+ return
189204 }
190- return rsp , e
205+
206+ resp = & DataAddresses {}
207+ var path = crypto + "/dashboards/addresses/" + strings .Join (addresses , "," )
208+ return resp , c .LoadResponse (path , resp , options )
191209}
192210
211+ // GetXpub get the xpub/ypub/zpub by type of crypto and the extended key.
212+ // 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)
193213func (c * Client ) GetXpub (crypto string , extendedKey string ) (* DataXpub , error ) {
194- // xpub (supported for all blockchains), ypub (supported for Bitcoin, Litecoin, Groestlcoin, and Bitcoin Testnet only)
195- // zpub (supported for Bitcoin, Litecoin, Groestlcoin, and Bitcoin Testnet only)
196- rsp := & DataXpub {}
197- var path = crypto + "/dashboards/xpub/" + extendedKey
198- e := c .loadResponse (path , rsp )
214+ return c .GetXpubAdv (crypto , extendedKey , nil )
215+ }
199216
200- if e != nil {
201- fmt .Print (e )
217+ // GetXpubAdv get the xpub/ypub/zpub by type of crypto, the extended key, and options.
218+ // 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)
219+ func (c * Client ) GetXpubAdv (crypto string , extendedKey string , options map [string ]string ) (resp * DataXpub , e error ) {
220+ if e = c .ValidateCryptoBoth (crypto ); e != nil {
221+ return
202222 }
203- return rsp , e
223+
224+ resp = & DataXpub {}
225+ var path = crypto + "/dashboards/xpub/" + extendedKey
226+ return resp , c .LoadResponse (path , resp , options )
204227}
205228
229+ // GetAddressEth get the address by type of crypto and address hash for Ethereum.
206230func (c * Client ) GetAddressEth (crypto string , address string ) (* DataAddressEth , error ) {
207- if ! Contains (GetSupportedCryptoEth (), crypto ) {
208- log .Fatalf ("error: %v is not supported" , crypto )
231+ return c .GetAddressEthAdv (crypto , address , nil )
232+ }
233+
234+ // GetAddressEthAdv get the address by type of crypto, address hash, and options for Ethereum.
235+ // TODO! Validate address
236+ func (c * Client ) GetAddressEthAdv (crypto string , address string , options map [string ]string ) (resp * DataAddressEth , e error ) {
237+ if e = c .ValidateCryptoEth (crypto ); e != nil {
238+ return
209239 }
210240
211- rsp : = & DataAddressEth {}
241+ resp = & DataAddressEth {}
212242 var path = crypto + "/dashboards/address/" + address
213- e := c .loadResponse (path , rsp )
214-
215- if e != nil {
216- fmt .Print (e )
217- }
218- return rsp , e
243+ return resp , c .LoadResponse (path , resp , options )
219244}
0 commit comments