-
Notifications
You must be signed in to change notification settings - Fork 13
/
address.go
81 lines (64 loc) · 2.14 KB
/
address.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
77
78
79
80
81
package mixin
import (
"context"
"fmt"
"github.com/shopspring/decimal"
)
type Address struct {
AddressID string `json:"address_id,omitempty"`
AssetID string `json:"asset_id"`
Label string `json:"label,omitempty"`
Destination string `json:"destination,omitempty"`
Tag string `json:"tag,omitempty"`
Fee decimal.Decimal `json:"fee,omitempty"`
Dust decimal.Decimal `json:"dust,omitempty"`
}
type CreateAddressInput struct {
AssetID string `json:"asset_id"`
Destination string `json:"destination,omitempty"`
Tag string `json:"tag,omitempty"`
Label string `json:"label,omitempty"`
}
func (c *Client) CreateAddress(ctx context.Context, input CreateAddressInput, pin string) (*Address, error) {
body := struct {
CreateAddressInput
Pin string `json:"pin,omitempty"`
}{
CreateAddressInput: input,
Pin: c.EncryptPin(pin),
}
var address Address
if err := c.Post(ctx, "/addresses", body, &address); err != nil {
return nil, err
}
return &address, nil
}
func (c *Client) ReadAddress(ctx context.Context, addressID string) (*Address, error) {
uri := fmt.Sprintf("/addresses/%s", addressID)
var address Address
if err := c.Get(ctx, uri, nil, &address); err != nil {
return nil, err
}
return &address, nil
}
func ReadAddress(ctx context.Context, accessToken, addressID string) (*Address, error) {
return NewFromAccessToken(accessToken).ReadAddress(ctx, addressID)
}
func (c *Client) ReadAddresses(ctx context.Context, assetID string) ([]*Address, error) {
uri := fmt.Sprintf("/assets/%s/addresses", assetID)
var addresses []*Address
if err := c.Get(ctx, uri, nil, &addresses); err != nil {
return nil, err
}
return addresses, nil
}
func ReadAddresses(ctx context.Context, accessToken, assetID string) ([]*Address, error) {
return NewFromAccessToken(accessToken).ReadAddresses(ctx, assetID)
}
func (c *Client) DeleteAddress(ctx context.Context, addressID, pin string) error {
uri := fmt.Sprintf("/addresses/%s/delete", addressID)
body := map[string]interface{}{
"pin": c.EncryptPin(pin),
}
return c.Post(ctx, uri, body, nil)
}