-
Notifications
You must be signed in to change notification settings - Fork 13
/
legacy_withdraw.go
51 lines (45 loc) · 1.06 KB
/
legacy_withdraw.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
package mixin
import (
"context"
"github.com/fox-one/mixin-sdk-go/v2/mixinnet"
"github.com/shopspring/decimal"
)
type WithdrawInput struct {
AddressID string `json:"address_id,omitempty"`
Amount decimal.Decimal `json:"amount,omitempty"`
TraceID string `json:"trace_id,omitempty"`
Memo string `json:"memo,omitempty"`
}
func (c *Client) Withdraw(ctx context.Context, input WithdrawInput, pin string) (*Snapshot, error) {
var body interface{}
if key, err := mixinnet.KeyFromString(pin); err == nil {
body = struct {
WithdrawInput
Pin string `json:"pin_base64"`
}{
WithdrawInput: input,
Pin: c.EncryptTipPin(
key,
TIPWithdrawalCreate,
input.AddressID,
input.Amount.String(),
"0", // fee
input.TraceID,
input.Memo,
),
}
} else {
body = struct {
WithdrawInput
Pin string
}{
WithdrawInput: input,
Pin: c.EncryptPin(pin),
}
}
var snapshot Snapshot
if err := c.Post(ctx, "/withdrawals", body, &snapshot); err != nil {
return nil, err
}
return &snapshot, nil
}