Skip to content

Commit

Permalink
Merge pull request #12 from DiFronzo/0.1.3
Browse files Browse the repository at this point in the history
0.1.3
  • Loading branch information
DiFronzo authored Jan 20, 2023
2 parents 31d17b0 + 1ef8c4c commit 1575d61
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 39 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
name: Tests

on:
push:
branches:
- main
pull_request:
branches:
- main
on: [push, pull_request]

jobs:
test:
Expand Down
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

## ⚡️ Quick start

First of all, [download](https://golang.org/) and install **GO**. Version `1.17` or higher is required.
First of all, [download](https://golang.org/) and install **GO**. Version `1.17`
or higher is required.

Verify that the installation was successful by running the following command that should return the version number for GO.
Verify that the installation was successful by running the following command
that should return the version number for GO.

```bash
go version
Expand All @@ -26,19 +28,26 @@ That's all you need to know to start! 🎉

## ⚙️ Usage & Options

For full documentation see [Gitbook](https://blockchair.vfiles.no/), also a big thanks to Gitbook for supporting the project.
For full documentation see [Gitbook](https://blockchair.vfiles.no/), also a big
thanks to Gitbook for supporting the project.

For an example of usage see
[here](https://github.com/DiFronzo/blockchair/blob/main/example/main.go).

For an example of usage see [here](https://github.com/DiFronzo/blockchair/blob/main/example/main.go).

### 🐳 Docker-way to quick start

UNDER CONSTRUCTION.

## ⭐️ Project assistance

If you want to say **thank you** or/and support active development of `blockchair`:
If you want to say **thank you** or/and support active development of
`blockchair`:

- Add a [GitHub Star](https://github.com/DiFronzo/blockchair) to the project.

## ⚠️ License
`Blockchair` is free and open-source software licensed under the [MIT](https://github.com/DiFronzo/blockchair/blob/main/LICENSE). This is not an official release from [Blockchair](https://github.com/Blockchair). Use on your own risk.

`Blockchair` is free and open-source software licensed under the
[MIT](https://github.com/DiFronzo/blockchair/blob/main/LICENSE). This is not an
official release from [Blockchair](https://github.com/Blockchair). Use on your
own risk.
10 changes: 5 additions & 5 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ type AddressEth struct {
ContractCreated string `json:"contract_created,omitempty"`
ContractDestroyed string `json:"contract_destroyed,omitempty"`
Balance string `json:"balance"`
BalanceUsd float32 `json:"balance_usd"`
BalanceUsd float64 `json:"balance_usd"` //maybe 32?
ReceivedApproximate string `json:"received_approximate"`
ReceivedUsd float32 `json:"received_usd"`
ReceivedUsd float64 `json:"received_usd"`
SpentApproximate string `json:"spent_approximate"`
SpentUsd float32 `json:"spent_usd"`
SpentUsd float64 `json:"spent_usd"`
FeesApproximate string `json:"fees_approximate"`
FeesUsd float32 `json:"fees_usd"`
FeesUsd float64 `json:"fees_usd"`
ReceivingCallCount int `json:"receiving_call_count"`
SpendingCallCount int `json:"spending_call_count"`
CallCount int `json:"call_count"`
Expand Down Expand Up @@ -237,7 +237,7 @@ type ContextAddress struct {
MarketPriceUsd float32 `json:"market_price_usd"`
Cache *Cache `json:"cache"`
API *API `json:"api"`
Server string `json:"server"`
Servers string `json:"servers"`
Time float32 `json:"time"`
RenderTime float32 `json:"render_time"`
FullTime float32 `json:"full_time"`
Expand Down
7 changes: 4 additions & 3 deletions address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ func TestGetAddress(t *testing.T) {
{"bitcoin-cash", "pq47a3s9exn9zt64l6f66an48cj0eptekq3vk6udg0"},
{"litecoin", "MKLyUgmiWF6SPZJVzm1hbiiNgpTxgnRiDE"},
{"litecoin", "MD4Q9gLQ7Cv1ZCqwFi33SezVFGomja8r9f"},
{"bitcoin-sv", "s-3412d0b7305a8173d53edc596012dc1d"},
{"bitcoin-sv", "s-166ee714859656ae26bc1c041d808804"},
// November 7th, 2022 public support for bitcoin-sv was dropped
// {"bitcoin-sv", "s-3412d0b7305a8173d53edc596012dc1d"},
// {"bitcoin-sv", "s-166ee714859656ae26bc1c041d808804"},
{"dogecoin", "DPEzPFx1YAg2AndcYXD9ouPiNT5izSgeHL"},
{"dogecoin", "D9a1Ah7mUNAJwNqHPER4DN9zNLoqcYFDZW"},
{"dash", "Xty4Q4B1CCm1qA4sMFkmczZqCtftFJuEse"},
Expand Down Expand Up @@ -68,8 +69,8 @@ func TestGetAddressEth(t *testing.T) {
}{
{"ethereum", "0x3282791d6fd713f1e94f4bfd565eaa78b3a0599d"},
{"ethereum", "0x9b22a80D5c7B3374a05b446081f97d0A34079e7F"},
//{"ethereum", "0xea674fdde714fd979de3edf0f56aa9716b898ec8"}, TODO! Finds out why this fail
{"ethereum", "0x3282791d6fd713f1e94f4bfd565eaa78b3a0599d"},
{"ethereum", "0xea674fdde714fd979de3edf0f56aa9716b898ec8"},
}
for _, test := range tests {
t.Run(test.currency, func(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ func TestGetBlock(t *testing.T) {
{"bitcoin-cash", "000000000000000002fa05038b3972e9f36b7ac4f8ce324348a5ce43813414d5"},
{"litecoin", "ea55f38d14dbd878f99d9d981630a62a8108ed97df4c3bd94a6d2ae5bb28d57d"},
{"litecoin", "410182837492d6705e0f2eef50c3d4dc197d240952a317e5ba26afdfb94e9f52"},
{"bitcoin-sv", "00000000000000000abf435db75d4a52becdaccd4635d03ffbde40a929b584c4"},
{"bitcoin-sv", "00000000000000000c2a7f12215b338a253d3cdd6dbff8830d969f212570ede4"},
// November 7th, 2022 public support for bitcoin-sv was dropped
// {"bitcoin-sv", "00000000000000000abf435db75d4a52becdaccd4635d03ffbde40a929b584c4"},
// {"bitcoin-sv", "00000000000000000c2a7f12215b338a253d3cdd6dbff8830d969f212570ede4"},
{"dogecoin", "fadc302877f6660a98ec6e92201fad1034c861225cafb067035be91369359679"},
{"dogecoin", "c195b67e9874e592800cd0761717d0cd202c1427c3988bbbfe2758bcb9ce9933"},
{"dash", "0000000000000006acf56c629320671659f9eac03272c81d1b4a2cc882366944"},
Expand Down
45 changes: 33 additions & 12 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand All @@ -29,7 +28,6 @@ var (
ErrSCE = errors.New("blockchair: the Ethereum cryptocurrency is not supported")
ErrSCG = errors.New("blockchair: the cryptocurrency is not supported")
ErrCGD = errors.New("blockchair: cannot get data on url")
ErrCRR = errors.New("blockchair: could not read answer response")
ErrRPE = errors.New("blockchair: response parsing error")
ErrIRS = errors.New("blockchair: incorrect response status")
ErrRLR = errors.New("blockchair: error 402, rate limit reached for free tier")
Expand All @@ -39,7 +37,7 @@ var (

// GetSupportedCrypto List of supported Bitcoin-like crypto.
func GetSupportedCrypto() []string {
return []string{"bitcoin", "bitcoin-cash", "litecoin", "bitcoin-sv", "dogecoin", "dash", "groestlcoin", "zcash", "ecash", "bitcoin/testnet"}
return []string{"bitcoin", "bitcoin-cash", "litecoin", "dogecoin", "dash", "groestlcoin", "zcash", "ecash", "bitcoin/testnet"}
}

// GetSupportedCryptoEth List of supported Ethereum crypto.
Expand All @@ -49,7 +47,7 @@ func GetSupportedCryptoEth() []string {

// GetSupportedCryptoMultichain List of supported crypto for multichain address check.
func GetSupportedCryptoMultichain() []string {
return []string{"bitcoin", "bitcoin-cash", "litecoin", "bitcoin-sv", "dash", "groestlcoin", "zcash", "ethereum"}
return []string{"bitcoin", "bitcoin-cash", "litecoin", "dash", "groestlcoin", "zcash", "ethereum"}
}

// Client specifies the mechanism by which individual API requests are made.
Expand Down Expand Up @@ -140,7 +138,7 @@ func parseRate(apikey string) RateLimit {
countRemaining = countRemaining - 1
rlVal.Limit = 30
rlVal.Remaining = countRemaining
rlVal.Period = 1800
rlVal.Period = 30
}

return rlVal
Expand Down Expand Up @@ -172,7 +170,9 @@ func (c *Client) LoadResponse(path string, i interface{}, options map[string]str

req.Header.Set("User-Agent", c.userAgent())

// fmt.Println("Querry... ", fullPath)
resp, e := c.client.Do(req)

if e != nil {
return c.err3(ErrCGD, e, resp)
}
Expand All @@ -187,9 +187,9 @@ func (c *Client) LoadResponse(path string, i interface{}, options map[string]str
rl := parseRate(c.APIKey)
c.RateLimitFunc(rl)

b, e := ioutil.ReadAll(resp.Body)
if e != nil {
return c.err3(ErrCRR, e, resp)
err := json.NewDecoder(resp.Body).Decode(&i)
if err != nil {
return c.err3(ErrRPE, err, resp)
}

if resp.Status[0] != '2' {
Expand All @@ -199,13 +199,34 @@ func (c *Client) LoadResponse(path string, i interface{}, options map[string]str
return c.err3(ErrIRS, e, resp)
}

if err := json.Unmarshal(b, &i); err != nil {
return c.err3(ErrRPE, err, resp)
}

return nil
}

// formatRateReset formats d to look like "[rate reset in 2s]" or
// "[rate reset in 87m02s]" for the positive durations. And like "[rate limit was reset 87m02s ago]"
// for the negative cases.
// func formatRateReset(d time.Duration) string {
// isNegative := d < 0
// if isNegative {
// d *= -1
// }
// secondsTotal := int(0.5 + d.Seconds())
// minutes := secondsTotal / 60
// seconds := secondsTotal - minutes*60

// var timeString string
// if minutes > 0 {
// timeString = fmt.Sprintf("%dm%02ds", minutes, seconds)
// } else {
// timeString = fmt.Sprintf("%ds", seconds)
// }

// if isNegative {
// return fmt.Sprintf("[rate limit was reset %v ago]", timeString)
// }
// return fmt.Sprintf("[rate reset in %v]", timeString)
// }

// New creates a new client instance the network internet.
func New() *Client {
return &Client{client: &http.Client{}, RateLimitFunc: defaultRateLimitFunc}
Expand Down
1 change: 1 addition & 0 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func init() {
func main() {
c := blockchair.New()
c.APIKey = clientID
c.RateLimitStrategySleep() //keeps you within rate limit
resp, err := c.GetAddressEthAdv("ethereum", "0x3282791d6fd713f1e94f4bfd565eaa78b3a0599d", map[string]string{"limit": "1", "offset": "0"})
if err != nil {
log.Fatalln(err)
Expand Down
4 changes: 3 additions & 1 deletion premium_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package blockchair

import "testing"
import (
"testing"
)

func TestClient_GetUsage(t *testing.T) {
cl := New()
Expand Down
5 changes: 3 additions & 2 deletions transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ func TestGetTransaction(t *testing.T) {
{"bitcoin-cash", "96fb4ea992bd6bf086d7ac8cee07ee6c261aaf65570b6bc64288b57debd0e13c"},
{"litecoin", "dc4b9ce0713971202270ae8240ec206f34d1289dfba5b96dcf12bb98c4dc96d1"},
{"litecoin", "5e8ccf8c5869e66d498c348aabeb564d330e846a806acbea00715e9005b3fc8d"},
{"bitcoin-sv", "1fcb691ace1894b7f1dd556b0ba3070bd6b799795a2192d0dc22ec223c945b9a"},
{"bitcoin-sv", "124ce1001e77bceabeb098fce32c27bc41b9ee9b6723a445ecddf8927549641b"},
// November 7th, 2022 public support for bitcoin-sv was dropped
// {"bitcoin-sv", "1fcb691ace1894b7f1dd556b0ba3070bd6b799795a2192d0dc22ec223c945b9a"},
// {"bitcoin-sv", "124ce1001e77bceabeb098fce32c27bc41b9ee9b6723a445ecddf8927549641b"},
{"dogecoin", "863556186e0b0687a5ab329927fbd40bb558b3e232b9d80616d406da91e53822"},
{"dogecoin", "0696eecd9f12940b08e9ac565fcdd7a58c513043457c51652bdbd051f30a45cb"},
{"dash", "b1624961540cc2317bbd4b2e1ec01f3e80f5c06ca76cacdebd99a3eeae76f63a"},
Expand Down

0 comments on commit 1575d61

Please sign in to comment.