-
Notifications
You must be signed in to change notification settings - Fork 25
/
transaction.go
53 lines (49 loc) · 1.28 KB
/
transaction.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
package bot
import (
"context"
"encoding/json"
"net/url"
)
type Transaction struct {
Type string `json:"type"`
TransactionId string `json:"transaction_id"`
TransactionHash string `json:"transaction_hash"`
Sender string `json:"sender"`
ChainId string `json:"chain_id"`
AssetId string `json:"asset_id"`
Amount string `json:"amount"`
Destination string `json:"destination"`
Tag string `json:"tag"`
Confirmations int `json:"confirmations"`
Threshold int `json:"threshold"`
CreatedAt string `json:"created_at"`
}
func ExternalTranactions(ctx context.Context, asset, destination, tag string) ([]*Transaction, error) {
values := url.Values{}
if destination != "" {
values.Add("destination", destination)
}
if tag != "" {
values.Add("tag", tag)
}
if asset != "" {
values.Add("asset", asset)
}
endpoint := "/external/transactions?" + values.Encode()
body, err := Request(ctx, "GET", endpoint, nil, "")
if err != nil {
return nil, err
}
var resp struct {
Data []*Transaction `json:"data"`
Error *Error `json:"error"`
}
err = json.Unmarshal(body, &resp)
if err != nil {
return nil, BadDataError(ctx)
}
if resp.Error != nil {
return nil, resp.Error
}
return resp.Data, nil
}