-
Notifications
You must be signed in to change notification settings - Fork 13
/
legacy_transaction_raw.go
69 lines (61 loc) · 1.73 KB
/
legacy_transaction_raw.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
package mixin
import (
"context"
"fmt"
"strings"
"time"
"github.com/fox-one/mixin-sdk-go/v2/mixinnet"
)
type (
// RawTransaction raw transaction
RawTransaction struct {
Type string `json:"type"`
SnapshotID string `json:"snapshot_id,omitempty"`
OpponentKey string `json:"opponent_key,omitempty"`
AssetID string `json:"asset_id"`
Amount string `json:"amount"`
TraceID string `json:"trace_id"`
Memo string `json:"memo"`
State string `json:"state"`
CreatedAt time.Time `json:"created_at"`
TransactionHash string `json:"transaction_hash,omitempty"`
SnapshotHash string `json:"snapshot_hash,omitempty"`
SnapshotAt time.Time `json:"snapshot_at"`
}
)
func (c *Client) Transaction(ctx context.Context, in *TransferInput, pin string) (*RawTransaction, error) {
paras := map[string]interface{}{
"asset_id": in.AssetID,
"amount": in.Amount,
"trace_id": in.TraceID,
"memo": in.Memo,
}
if key, err := mixinnet.KeyFromString(pin); err == nil {
paras["pin_base64"] = c.EncryptTipPin(
key,
TIPRawTransactionCreate,
in.AssetID,
in.OpponentKey,
strings.Join(in.OpponentMultisig.Receivers, ""),
fmt.Sprint(in.OpponentMultisig.Threshold),
in.Amount.String(),
in.TraceID,
in.Memo,
)
} else {
paras["pin"] = c.EncryptPin(pin)
}
if in.OpponentKey != "" {
paras["opponent_key"] = in.OpponentKey
} else {
paras["opponent_multisig"] = map[string]interface{}{
"receivers": in.OpponentMultisig.Receivers,
"threshold": in.OpponentMultisig.Threshold,
}
}
var resp RawTransaction
if err := c.Post(ctx, "/transactions", paras, &resp); err != nil {
return nil, err
}
return &resp, nil
}