-
Notifications
You must be signed in to change notification settings - Fork 13
/
transaction_raw.go
83 lines (71 loc) · 2.04 KB
/
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package mixin
import (
"context"
"encoding/json"
"time"
"github.com/shopspring/decimal"
)
// RawTransaction raw transaction
type RawTransaction struct {
Type string `json:"type"`
SnapshotID string `json:"snapshot"`
OpponentKey string `json:"opponent_key"`
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"`
}
// GhostKeys transaction ghost keys
type GhostKeys struct {
Mask Key `json:"mask"`
Keys []Key `json:"keys"`
}
func (g GhostKeys) DumpOutput(threshold uint8, amount decimal.Decimal) *Output {
return &Output{
Mask: g.Mask,
Keys: g.Keys,
Amount: NewIntegerFromDecimal(amount),
Script: NewThresholdScript(threshold),
}
}
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,
"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
}
func (c *Client) ReadGhostKeys(ctx context.Context, receivers []string, index int) (*GhostKeys, error) {
data, err := json.Marshal(map[string]interface{}{
"receivers": receivers,
"index": index,
})
if err != nil {
return nil, err
}
var resp GhostKeys
if err := c.Post(ctx, "/outputs", data, &resp); err != nil {
return nil, err
}
return &resp, nil
}