-
Notifications
You must be signed in to change notification settings - Fork 8
/
addresses.go
46 lines (38 loc) 路 1.06 KB
/
addresses.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
package api
import (
"encoding/json"
"strconv"
"strings"
)
type AddressesResponse struct {
Jsonrpc string `json:"jsonrpc"`
ID string `json:"id,omitempty"`
Result []*AddressesResult `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
type AddressesResult struct {
Address string `json:"address"`
Balance []Balance `json:"balance"`
TransactionCount string `json:"transaction_count"`
}
func (a *Api) Addresses(addresses []string, height int) ([]*AddressesResult, error) {
params := make(map[string]string)
params["height"] = strconv.Itoa(height)
params["addresses"] = "[" + strings.Join(addresses, ",") + "]"
res, err := a.client.R().SetQueryParams(params).Get("/addresses")
if err != nil {
return nil, err
}
if res.IsError() {
return nil, NewResponseError(res)
}
response := new(AddressesResponse)
err = json.Unmarshal(res.Body(), response)
if err != nil {
return nil, err
}
if response.Error != nil {
return nil, response.Error
}
return response.Result, nil
}