-
Notifications
You must be signed in to change notification settings - Fork 10
/
api_network.go
57 lines (48 loc) · 1.2 KB
/
api_network.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
package blockfrost
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
)
const (
resourceNetwork = "network"
)
// NetworkSupply contains information on network supply
type NetworkSupply struct {
Max string `json:"max"`
Total string `json:"total"`
Circulating string `json:"circulating"`
Locked string `json:"locked"`
}
// NetworkStake contains information on the cardano network stake
type NetworkStake struct {
Live string `json:"live"`
Active string `json:"active"`
}
// NetworkInfo contains network stake and supply information on the network
type NetworkInfo struct {
Supply NetworkSupply `json:"supply"`
Stake NetworkStake `json:"stake"`
}
// Network returns detailed network information.
func (c *apiClient) Network(ctx context.Context) (ni NetworkInfo, err error) {
requestUrl, err := url.Parse(fmt.Sprintf("%s/%s", c.server, resourceNetwork))
if err != nil {
return
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, requestUrl.String(), nil)
if err != nil {
return
}
res, err := c.handleRequest(req)
if err != nil {
return
}
defer res.Body.Close()
if err = json.NewDecoder(res.Body).Decode(&ni); err != nil {
return
}
return ni, nil
}