/
wallet.go
120 lines (107 loc) · 4.54 KB
/
wallet.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package core
import (
"context"
"database/sql/driver"
"encoding/json"
"time"
"github.com/fox-one/mixin-sdk-go"
"github.com/jmoiron/sqlx/types"
"github.com/lib/pq"
"github.com/shopspring/decimal"
)
type (
// TODO Deprecated, remove in the future version
MemoData struct {
Member string `json:"member,omitempty"`
Type int `json:"type,omitempty"`
UserID string `json:"user_id,omitempty"`
FollowID string `json:"follow_id,omitempty"`
Data []byte `json:"data,omitempty"`
}
// Output represent Mixin Network multisig Outputs
Output struct {
ID int64 `sql:"PRIMARY_KEY" json:"id,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
Version int64 `sql:"NOT NULL" json:"version,omitempty"`
Sender string `sql:"type:char(36)" json:"sender,omitempty"`
TraceID string `sql:"type:char(36)" json:"trace_id,omitempty"`
AssetID string `sql:"type:char(36)" json:"asset_id,omitempty"`
Amount decimal.Decimal `sql:"type:decimal(64,8)" json:"amount,omitempty"`
Memo string `sql:"type:char(200)" json:"memo,omitempty"`
MemoData MemoData `sql:"type:TEXT" json:"memo_data,omitempty"`
State string `sql:"size:24" json:"state,omitempty"`
// SpentBy represent the associated transfer trace id
SpentBy string `sql:"type:char(36);NOT NULL" json:"spent_by,omitempty"`
// UTXO json Data
Data types.JSONText `sql:"type:TEXT" json:"data,omitempty"`
// Raw Mixin UTXO
UTXO *mixin.MultisigUTXO `sql:"-" json:"-,omitempty"`
}
Transfer struct {
ID int64 `sql:"PRIMARY_KEY" json:"id,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
TraceID string `sql:"type:char(36)" json:"trace_id,omitempty"`
AssetID string `sql:"type:char(36)" json:"asset_id,omitempty"`
Amount decimal.Decimal `sql:"type:decimal(64,8)" json:"amount,omitempty"`
Memo string `sql:"size:200" json:"memo,omitempty"`
Handled types.BitBool `sql:"type:bit(1)" json:"handled,omitempty"`
Passed types.BitBool `sql:"type:bit(1)" json:"passed,omitempty"`
Threshold uint8 `json:"threshold,omitempty"`
Opponents pq.StringArray `sql:"type:varchar(1024)" json:"opponents,omitempty"`
}
RawTransaction struct {
ID int64 `sql:"PRIMARY_KEY" json:"id,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
TraceID string `sql:"type:char(36);" json:"trace_id,omitempty"`
Data string `sql:"type:TEXT" json:"data,omitempty"`
}
WalletStore interface {
// Save batch update multiple Output
Save(ctx context.Context, outputs []*Output) error
// List return a list of Output by order
List(ctx context.Context, fromID int64, limit int) ([]*Output, error)
// ListUnspent list unspent Output
ListUnspent(ctx context.Context, assetID string, limit int) ([]*Output, error)
ListSpentBy(ctx context.Context, assetID string, spentBy string) ([]*Output, error)
// Transfers
CreateTransfers(ctx context.Context, transfers []*Transfer) error
UpdateTransfer(ctx context.Context, transfer *Transfer) error
ListPendingTransfers(ctx context.Context) ([]*Transfer, error)
ListNotPassedTransfers(ctx context.Context) ([]*Transfer, error)
Spent(ctx context.Context, outputs []*Output, transfer *Transfer) error
// mixin net transaction
CreateRawTransaction(ctx context.Context, tx *RawTransaction) error
ListPendingRawTransactions(ctx context.Context, limit int) ([]*RawTransaction, error)
ExpireRawTransaction(ctx context.Context, tx *RawTransaction) error
}
WalletService interface {
// Pull fetch NEW Output updates
Pull(ctx context.Context, offset time.Time, limit int) ([]*Output, error)
// Spend spend multiple Output
Spend(ctx context.Context, outputs []*Output, transfer *Transfer) (*RawTransaction, error)
// ReqTransfer generate payment code for multisig transfer
ReqTransfer(ctx context.Context, transfer *Transfer) (string, error)
}
)
// Scan implements the sql.Scanner interface for database deserialization.
func (m *MemoData) Scan(value interface{}) error {
var d []byte
switch v := value.(type) {
case string:
d = []byte(v)
case []byte:
d = v
}
var memo MemoData
if err := json.Unmarshal(d, &memo); err != nil {
return err
}
*m = memo
return nil
}
// Value implements the driver.Valuer interface for database serialization.
func (m MemoData) Value() (driver.Value, error) {
return json.Marshal(m)
}