-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathasset.go
58 lines (48 loc) · 1.35 KB
/
asset.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
package fswap
import (
"context"
"github.com/shopspring/decimal"
)
type (
Asset struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Symbol string `json:"symbol,omitempty"`
DisplaySymbol string `json:"display_symbol,omitempty"`
Logo string `json:"logo,omitempty"`
ChainID string `json:"chain_id,omitempty"`
Price decimal.Decimal `json:"price,omitempty"`
Tag string `json:"tag,omitempty"`
Chain *Asset `json:"chain,omitempty"`
}
)
// ReadAsset read asset
func (c *Client) ReadAsset(ctx context.Context, assetID string) (*Asset, error) {
const uri = "/api/assets/{id}"
resp, err := c.request(ctx).SetPathParams(map[string]string{
"id": assetID,
}).Get(uri)
if err != nil {
return nil, err
}
var asset Asset
if err := UnmarshalResponse(resp, &asset); err != nil {
return nil, err
}
return &asset, nil
}
// ListAssets list all assets
func (c *Client) ListAssets(ctx context.Context) ([]*Asset, error) {
const uri = "/api/assets"
resp, err := c.request(ctx).Get(uri)
if err != nil {
return nil, err
}
var body struct {
Assets []*Asset `json:"assets,omitempty"`
}
if err := UnmarshalResponse(resp, &body); err != nil {
return nil, err
}
return body.Assets, nil
}