-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbalances.go
76 lines (60 loc) · 1.63 KB
/
balances.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package eclair
import "encoding/json"
const (
usableBalancesPath = "/usablebalances"
channelBalancesPath = "/channelbalances"
globalBalancePath = "/globalbalance"
)
type UsableBalance struct {
ChannelId string `json:"channelId"`
ToRemote int `json:"toRemote"`
ToLocal int `json:"toLocal"`
}
type UsableBalancesResponse []UsableBalance
type ChannelBalance struct {
ChannelId string `json:"channelId"`
Balance int `json:"balance"`
Capacity int `json:"capacity"`
}
type ChannelBalancesResponse []ChannelBalance
type GlobalBalanceResponse struct {
TotalBalance int `json:"totalBalance"`
Onchain ChainState `json:"onchain"`
Offchain ChainState `json:"offchain"`
}
func (c *Client) UsableBalances() (*UsableBalancesResponse, error) {
usableBalances := UsableBalancesResponse{}
data, err := c.Post(usableBalancesPath, nil, nil)
if err != nil {
return nil, err
}
err = json.Unmarshal(data, &usableBalances)
if err != nil {
return nil, err
}
return &usableBalances, nil
}
func (c *Client) ChannelBalances() (*ChannelBalancesResponse, error) {
channelBalances := ChannelBalancesResponse{}
data, err := c.Post(channelBalancesPath, nil, nil)
if err != nil {
return nil, err
}
err = json.Unmarshal(data, &channelBalances)
if err != nil {
return nil, err
}
return &channelBalances, nil
}
func (c *Client) GlobalBalance() (*GlobalBalanceResponse, error) {
globalBalance := GlobalBalanceResponse{}
data, err := c.Post(globalBalancePath, nil, nil)
if err != nil {
return nil, err
}
err = json.Unmarshal(data, &globalBalance)
if err != nil {
return nil, err
}
return &globalBalance, nil
}