-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbalances.go
39 lines (31 loc) · 1.08 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
package coinpayments
import (
"net/url"
)
// BalancesRequest is what we sent to the API
type BalancesRequest struct {
All string `json:"all"`
}
// BalancesResult is a result from the API for a balances command
type BalancesResult struct {
Balance int `json:"balance"` // balance as integer in satoshis
Balancef string `json:"balancef"` // balance as floating point number
}
// BalancesResponse is the response we expect from the API server.
type BalancesResponse struct {
ErrorResponse
Result map[string]BalancesResult `json:"result"`
}
// CallBalances calls the balances command on the API
func (c *Client) CallBalances(req *BalancesRequest) (map[string]BalancesResult, error) {
// add in data specific to this Balances, then forward the request to the call method
data := url.Values{}
data.Add("all", req.All)
// make the actual call and unmarshal the response into our BalancesResponse struct
var response BalancesResponse
if err := c.Call(CmdBalances, data, &response); err != nil {
return nil, err
}
// return the entire result to be used
return response.Result, nil
}