-
Notifications
You must be signed in to change notification settings - Fork 5
/
wallet-operations-basic.go
248 lines (220 loc) · 7.51 KB
/
wallet-operations-basic.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
package bitgo
import (
"fmt"
"time"
)
type Transfer struct {
ID string `json:"id"`
Coin string `json:"coin"`
Wallet string `json:"wallet"`
Txid string `json:"txid"`
Height int `json:"height"`
Date time.Time `json:"date"`
Confirmations int `json:"confirmations"`
Value int `json:"value"`
BitgoFee int `json:"bitgoFee"`
Usd float64 `json:"usd"`
UsdRate float64 `json:"usdRate"`
State string `json:"state"`
VSize int `json:"vSize"`
NSegwitInputs int `json:"nSegwitInputs"`
Tags []string `json:"tags"`
SequenceID string `json:"sequenceId"`
History []struct {
Date time.Time `json:"date"`
Action string `json:"action"`
} `json:"history"`
Entries []struct {
Address string `json:"address"`
Value int `json:"value"`
Wallet string `json:"wallet,omitempty"`
} `json:"entries"`
Outputs []struct {
ID string `json:"id"`
Address string `json:"address"`
Value int `json:"value"`
ValueString string `json:"valueString"`
Wallet string `json:"wallet"`
Chain int `json:"chain"`
Index int `json:"index"`
} `json:"outputs"`
Inputs []struct {
ID string `json:"id"`
Address string `json:"address"`
Value int `json:"value"`
ValueString string `json:"valueString"`
Wallet string `json:"wallet"`
Chain int `json:"chain"`
Index int `json:"index"`
} `json:"inputs"`
ConfirmedTime time.Time `json:"confirmedTime"`
CreatedTime time.Time `json:"createdTime"`
}
type TransferList struct {
NextBatchPrevId string `json:"nextBatchPrevId"`
Coin string `json:"coin"`
Count int `json:"count"`
Transfers []Transfer `json:"transfers"`
}
type Address struct {
ID string `json:"id"`
Address string `json:"address"`
Chain int `json:"chain"`
Index int `json:"index"`
Coin string `json:"coin"`
Wallet string `json:"wallet"`
CoinSpecific struct {
RedeemScript string `json:"redeemScript"`
} `json:"coinSpecific"`
Label string `json:"label"`
Balance struct {
Updated time.Time `json:"updated"`
NumTx int `json:"numTx"`
NumUnspents int `json:"numUnspents"`
TotalReceived int `json:"totalReceived"`
TotalSent int `json:"totalSent"`
} `json:"balance"`
}
type TransactionDescription struct {
Txid string `json:"txid"`
Status string `json:"status"`
}
// List Wallet Transfers
func (b *BitGo) ListWalletTransfers(walletId string, params ListParams) (list TransferList, err error) {
err = b.get(
fmt.Sprintf("%s/wallet/%s/transfer",
b.coin,
walletId),
params,
&list)
return
}
// Get Wallet Transfer
func (b *BitGo) GetWalletTransfer(walletId string, transferId string) (transfer Transfer, err error) {
err = b.get(
fmt.Sprintf("%s/wallet/%s/transfer/%s",
b.coin,
walletId,
transferId),
nil,
&transfer)
return
}
// Get Wallet Transfer By Sequence ID
func (b *BitGo) GetWalletTransferBySequenceID(walletId string, sequenceId string) (transfer Transfer, err error) {
err = b.get(
fmt.Sprintf("%s/wallet/%s/transfer/sequenceId/%s",
b.coin,
walletId,
sequenceId),
nil,
&transfer)
return
}
// Create Wallet Address
type AddressParams struct {
Chain int `json:"chain,omitempty"`
Label string `json:"label,omitempty"`
}
func (b *BitGo) CreateWalletAddress(walletId string, params *AddressParams) (address Address, err error) {
err = b.post(
fmt.Sprintf("%s/wallet/%s/address",
b.coin,
walletId),
params,
&address)
return
}
// Get Wallet Address
func (b *BitGo) GetWalletAddress(walletId string, addressOrId string) (address Address, err error) {
err = b.get(
fmt.Sprintf("%s/wallet/%s/address/%s",
b.coin,
walletId,
addressOrId),
nil,
&address)
return
}
// Update Wallet Address
type UpdateWalletAddressParams struct {
Label string `json:"label,omitempty"`
}
func (b *BitGo) UpdateWalletAddress(walletId string, addressOrId string, params UpdateWalletAddressParams) (address Address, err error) {
err = b.put(
fmt.Sprintf("%s/wallet/%s/address/%s",
b.coin,
walletId,
addressOrId),
params,
&address)
return
}
// Send Transaction
type SendParams struct {
Address string `json:"address" valid:"required"`
Amount int `json:"amount" valid:"required"`
WalletPassphrase string `json:"walletPassphrase" valid:"required"`
Prv string `json:"prv,omitempty"`
NumBlocks int `json:"numBlocks,omitempty"`
FeeRate int `json:"feeRate,omitempty"`
Comment string `json:"comment,omitempty"`
// Unspents array `json:"unspents,omitempty"`
MinConfirms int `json:"minConfirms,omitempty"`
EnforceMinConfirmsForChange bool `json:"enforceMinConfirmsForChange,omitempty"`
TargetWalletUnspents int `json:"targetWalletUnspents,omitempty"`
NoSplitChange bool `json:"noSplitChange,omitempty"`
MinValue int `json:"minValue,omitempty"`
MaxValue int `json:"maxValue,omitempty"`
GasPrice int `json:"gasPrice,omitempty"`
GasLimit int `json:"gasLimit,omitempty"`
SequenceId int `json:"sequenceId,omitempty"`
Segwit bool `json:"segwit,omitempty"`
LastLedgerSequence int `json:"lastLedgerSequence,omitempty"`
LedgerSequenceDelta string `json:"ledgerSequenceDelta,omitempty"`
}
func (b *BitGo) SendTransaction(walletId string, params SendParams) (transactionDescription TransactionDescription, err error) {
err = b.post(
fmt.Sprintf("%s/wallet/%s/sendcoins",
b.coin,
walletId),
params,
&transactionDescription)
return
}
// Send Transaction to Many
type Recipient struct {
Address string `json:"address" valid:"required"`
Amount int `json:"amount" valid:"required"`
GasPrice int `json:"gasPrice,omitempty"`
}
type SendToManyParams struct {
Recipients []Recipient `json:"recipients" valid:"required"`
WalletPassphrase string `json:"walletPassphrase" valid:"required"`
Prv string `json:"prv,omitempty"`
NumBlocks int `json:"numBlocks,omitempty"`
FeeRate int `json:"feeRate,omitempty"`
Comment string `json:"comment,omitempty"`
// Unspents array `json:"unspents,omitempty"`
MinConfirms int `json:"minConfirms,omitempty"`
EnforceMinConfirmsForChange bool `json:"enforceMinConfirmsForChange,omitempty"`
TargetWalletUnspents int `json:"targetWalletUnspents,omitempty"`
NoSplitChange bool `json:"noSplitChange,omitempty"`
MinValue int `json:"minValue,omitempty"`
MaxValue int `json:"maxValue,omitempty"`
GasPrice int `json:"gasPrice,omitempty"`
GasLimit int `json:"gasLimit,omitempty"`
SequenceId int `json:"sequenceId,omitempty"`
Segwit bool `json:"segwit,omitempty"`
LastLedgerSequence int `json:"lastLedgerSequence,omitempty"`
LedgerSequenceDelta string `json:"ledgerSequenceDelta,omitempty"`
}
func (b *BitGo) SendTransactionToMany(walletId string, params SendToManyParams) (transactionDescription TransactionDescription, err error) {
err = b.post(
fmt.Sprintf("%s/wallet/%s/sendmany",
b.coin,
walletId),
params,
&transactionDescription)
return
}