-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from DiFronzo/development
+Omni layer propery info, ERC-20 token info, and ERC-20 token holder info.
- Loading branch information
Showing
9 changed files
with
331 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package blockchair | ||
|
||
// DataErc20 includes full server response to ERC-20 request. | ||
type DataErc20 struct { | ||
Data Erc20 `json:"data"` | ||
Context ContextUncle `json:"context"` | ||
} | ||
|
||
// DataErc20Holder includes full server response to ERC-20 holder request. | ||
type DataErc20Holder struct { | ||
Data map[string]Erc20HolderInfo `json:"data"` | ||
Context HolderContext `json:"context"` | ||
} | ||
|
||
// Erc20HolderInfo describes the outer structure of a ERC-20 holder. | ||
type Erc20HolderInfo struct { | ||
Address HolderAddress `json:"address"` | ||
Transaction []HolderTransaction `json:"transaction,omitempty"` | ||
} | ||
|
||
// HolderAddress the structure of one specific Ethereum address. | ||
type HolderAddress struct { | ||
Balance string `json:"balance,omitempty"` | ||
BalanceApproximate int `json:"balance_approximate,omitempty"` | ||
Received string `json:"received,omitempty"` | ||
ReceivedApproximate int `json:"received_approximate,omitempty"` | ||
Spent string `json:"spent,omitempty"` | ||
SpentApproximate int `json:"spent_approximate,omitempty"` | ||
ReceivingTransactionCount int `json:"receiving_transaction_count,omitempty"` | ||
SpendingTransactionCount int `json:"spending_transaction_count,omitempty"` | ||
TransactionCount int `json:"transaction_count,omitempty"` | ||
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"` | ||
} | ||
|
||
// HolderTransaction the structure of one specific Ethereum transaction. | ||
type HolderTransaction struct { | ||
BlockID int `json:"block_id"` | ||
ID int `json:"id"` | ||
TransactionHash string `json:"transaction_hash"` | ||
Time string `json:"time"` | ||
TokenAddress string `json:"token_address"` | ||
TokenName string `json:"token_name"` | ||
TokenSymbol string `json:"token_symbol"` | ||
TokenDecimals int `json:"token_decimals"` | ||
Sender string `json:"sender"` | ||
Recipient string `json:"recipient"` | ||
Value string `json:"value"` | ||
ValueApproximate int `json:"value_approximate"` | ||
} | ||
|
||
// Erc20 is the structure of one specific ERC-20 token. | ||
type Erc20 struct { | ||
Name string `json:"name"` | ||
Symbol string `json:"symbol"` | ||
Decimals int `json:"decimals"` | ||
Time string `json:"time"` | ||
CreatingBlockID int `json:"creating_block_id"` | ||
CreatingTransactionHash string `json:"creating_transaction_hash"` | ||
Transactions int `json:"transactions"` | ||
Transactions24H int `json:"transactions_24h"` | ||
Volume24HApproximate float32 `json:"volume_24h_approximate"` | ||
Volume24H string `json:"volume_24h"` | ||
Circulation string `json:"circulation"` | ||
CirculationApproximate float32 `json:"circulation_approximate"` | ||
MarketPriceUsd float32 `json:"market_price_usd,omitempty"` | ||
MarketPriceBtc float32 `json:"market_price_btc,omitempty"` | ||
MarketCapUsd float32 `json:"market_cap_usd,omitempty"` | ||
} | ||
|
||
// HolderContext is the structure of context for ERC-20 holder. | ||
type HolderContext struct { | ||
Code int `json:"code"` | ||
Source string `json:"source"` | ||
Limit int `json:"limit"` | ||
Offset int `json:"offset"` | ||
Results int `json:"results"` | ||
State int `json:"state"` | ||
StateLayer2 int `json:"state_layer_2"` | ||
MarketPriceUsd float64 `json:"market_price_usd"` | ||
Cache *Cache `json:"cache"` | ||
API *API `json:"api"` | ||
Server string `json:"server"` | ||
Time float32 `json:"time"` | ||
RenderTime float32 `json:"render_time"` | ||
FullTime float32 `json:"full_time"` | ||
RequestCost float32 `json:"request_cost"` | ||
} | ||
|
||
// GetErc20 fetch some basic information on an ERC-20 token on Ethereum. | ||
func (c *Client) GetErc20(crypto string, token string) (*DataErc20, error) { | ||
return c.GetErc20Adv(crypto, token, nil) | ||
} | ||
|
||
// GetErc20Adv fetch some basic information on an ERC-20 token on Ethereum with options. | ||
func (c *Client) GetErc20Adv(crypto string, token string, options map[string]string) (resp *DataErc20, e error) { | ||
if e = c.ValidateCryptoEth(crypto); e != nil { | ||
return | ||
} | ||
if e = c.ValidateErc20Token(token); e != nil { | ||
return | ||
} | ||
|
||
resp = &DataErc20{} | ||
var path = crypto + "/erc-20/" + token + "/stats" | ||
return resp, c.LoadResponse(path, resp, options) | ||
} | ||
|
||
// GetErc20Holder fetch some basic information on an ERC-20 token holder on Ethereum. | ||
func (c *Client) GetErc20Holder(crypto string, token string, address string) (*DataErc20Holder, error) { | ||
return c.GetErc20HolderAdv(crypto, token, address, nil) | ||
} | ||
|
||
// GetErc20HolderAdv fetch some basic information on an ERC-20 token holder on Ethereum with options. | ||
func (c *Client) GetErc20HolderAdv(crypto string, token string, address string, options map[string]string) (resp *DataErc20Holder, e error) { | ||
if e = c.ValidateCryptoEth(crypto); e != nil { | ||
return | ||
} | ||
if e = c.ValidateErc20Tokens([]string{token, address}); e != nil { | ||
return | ||
} | ||
|
||
resp = &DataErc20Holder{} | ||
var path = crypto + "/erc-20/" + token + "/dashboards/address/" + address | ||
return resp, c.LoadResponse(path, resp, options) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package blockchair | ||
|
||
import "testing" | ||
|
||
func TestGetErc20(t *testing.T) { | ||
tests := []struct { | ||
currency string | ||
token string | ||
}{ | ||
{"ethereum", "0x4a73d94683f2c9c2Aaf32ccd5723F3e243D6a654"}, | ||
{"ethereum", "0xdac17f958d2ee523a2206206994597c13d831ec7"}, | ||
{"ethereum", "0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"}, | ||
{"ethereum", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.currency, func(t *testing.T) { | ||
cl := New() | ||
cl.APIKey = clientID | ||
_, e := cl.GetErc20(test.currency, test.token) | ||
if e != nil { | ||
t.Fatal(e) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestGetErc20Holder(t *testing.T) { | ||
tests := []struct { | ||
currency string | ||
token string | ||
address string | ||
}{ | ||
{"ethereum", "0x4a73d94683f2c9c2Aaf32ccd5723F3e243D6a654", "0x3282791d6fd713f1e94f4bfd565eaa78b3a0599d"}, | ||
{"ethereum", "0x68e14bb5a45b9681327e16e528084b9d962c1a39", "0x3282791d6fd713f1e94f4bfd565eaa78b3a0599d"}, | ||
{"ethereum", "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0", "0x3282791d6fd713f1e94f4bfd565eaa78b3a0599d"}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.currency, func(t *testing.T) { | ||
cl := New() | ||
cl.APIKey = clientID | ||
_, e := cl.GetErc20Holder(test.currency, test.token, test.address) | ||
if e != nil { | ||
t.Fatal(e) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package blockchair | ||
|
||
import "strconv" | ||
|
||
// DataOmni includes full server response to the Omni Layer property request. | ||
type DataOmni struct { | ||
Data OmniInfo `json:"data"` | ||
Context ContextOmni `json:"context"` | ||
} | ||
|
||
// OmniInfo describes the outer structure of the Omni Layer property. | ||
type OmniInfo struct { | ||
ID int `json:"id"` | ||
Name string `json:"name"` | ||
Category string `json:"category"` | ||
Subcategory string `json:"subcategory"` | ||
Description string `json:"description"` | ||
URL string `json:"url"` | ||
IsDivisible bool `json:"is_divisible"` | ||
Issuer string `json:"issuer"` | ||
CreationTransactionHash string `json:"creation_transaction_hash,omitempty"` | ||
CreationTime string `json:"creation_time,omitempty"` | ||
CreationBlockID int `json:"creation_block_id"` | ||
IsIssuanceFixed bool `json:"is_issuance_fixed"` | ||
IsIssuanceManaged bool `json:"is_issuance_managed"` | ||
Circulation float32 `json:"circulation"` | ||
Ecosystem int `json:"ecosystem"` | ||
} | ||
|
||
// ContextOmni for omni. | ||
type ContextOmni struct { | ||
Code int `json:"code"` | ||
Source string `json:"source"` | ||
Results int `json:"results"` | ||
State int `json:"state"` | ||
MarketPriceUsd int `json:"market_price_usd"` | ||
Cache *Cache `json:"cache"` | ||
API *API `json:"api"` | ||
Server string `json:"server"` | ||
Time float32 `json:"time"` | ||
RenderTime float32 `json:"render_time"` | ||
FullTime float32 `json:"full_time"` | ||
RequestCost float32 `json:"request_cost"` | ||
} | ||
|
||
// GetOmni fetch some basic information on an Omni Layer (Bitcoin) property (token). | ||
func (c *Client) GetOmni(prorertyID int64) (*DataOmni, error) { | ||
return c.GetOmniAdv(prorertyID, nil) | ||
} | ||
|
||
// GetOmniAdv fetch some basic information on an Omni Layer (Bitcoin) property (token) with options. | ||
func (c *Client) GetOmniAdv(prorertyID int64, options map[string]string) (resp *DataOmni, e error) { | ||
|
||
resp = &DataOmni{} | ||
var path = "bitcoin" + "/omni/dashboards/property/" + strconv.FormatInt(prorertyID, 10) | ||
return resp, c.LoadResponse(path, resp, options) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package blockchair | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
) | ||
|
||
func TestGetOmni(t *testing.T) { | ||
tests := []struct { | ||
currency int64 | ||
}{ | ||
{31}, | ||
{544}, | ||
{1}, | ||
} | ||
for _, test := range tests { | ||
t.Run(strconv.FormatInt(test.currency, 10), func(t *testing.T) { | ||
cl := New() | ||
cl.APIKey = clientID | ||
_, e := cl.GetOmni(test.currency) | ||
if e != nil { | ||
t.Fatal(e) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.