-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathchain_info.go
49 lines (43 loc) · 1.23 KB
/
chain_info.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
package whatsonchain
import (
"context"
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"
)
// GetChainInfo this endpoint retrieves various state info of the chain for the selected network.
//
// For more information: https://developers.whatsonchain.com/#chain-info
func (c *Client) GetChainInfo(ctx context.Context) (chainInfo *ChainInfo, err error) {
var resp string
// https://api.whatsonchain.com/v1/bsv/<network>/chain/info
if resp, err = c.request(
ctx,
fmt.Sprintf("%s%s/chain/info", apiEndpoint, c.Network()),
http.MethodGet, nil,
); err != nil {
return
}
if len(resp) == 0 {
return nil, ErrChainInfoNotFound
}
err = json.Unmarshal([]byte(resp), &chainInfo)
return
}
// GetCirculatingSupply this endpoint retrieves the current circulating supply
//
// For more information: https://developers.whatsonchain.com/#get-circulating-supply
func (c *Client) GetCirculatingSupply(ctx context.Context) (supply float64, err error) {
var resp string
// https://api.whatsonchain.com/v1/bsv/<network>/circulatingsupply
if resp, err = c.request(
ctx,
fmt.Sprintf("%s%s/circulatingsupply", apiEndpoint, c.Network()),
http.MethodGet, nil,
); err != nil {
return
}
return strconv.ParseFloat(strings.TrimSpace(resp), 64)
}