-
Notifications
You must be signed in to change notification settings - Fork 12
/
transaction_raw.go
64 lines (55 loc) · 1.6 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
package mixin
import (
"context"
"encoding/json"
"time"
)
// 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"`
SnapshotHash string `json:"snapshot_hash"`
SnapshotAt time.Time `json:"snapshot_at"`
}
// GhostKeys transaction ghost keys
type GhostKeys struct {
Mask string `json:"mask"`
Keys []string `json:"keys"`
}
func (c *Client) Transaction(ctx context.Context, in *TransferInput, pin string) (*RawTransaction, error) {
paras := map[string]interface{}{
"asset_id": in.AssetID,
"opponent_key": in.OpponentKey,
"amount": in.Amount,
"trace_id": in.TraceID,
"memo": in.Memo,
"pin": c.EncryptPin(pin),
}
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
}