-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvault.go
308 lines (264 loc) · 10.8 KB
/
vault.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
package fireblocksdk
import (
"encoding/json"
"fmt"
"net/http"
"github.com/pkg/errors"
)
// VaultAccount endpoint
// Filters
// VaultAccountsFilter defines parameters for GetVaultAccountsPaged.
type VaultAccountsFilter struct {
NamePrefix string `json:"namePrefix,omitempty"`
NameSuffix string `json:"nameSuffix,omitempty"`
MinAmountThreshold string `json:"minAmountThreshold,omitempty"`
AssetID string `json:"assetId,omitempty"`
}
// PagedVaultAccountsRequestFilters defines parameters for GetVaultAccountsPaged.
type PagedVaultAccountsRequestFilters struct {
NamePrefix string `json:"namePrefix,omitempty"`
NameSuffix string `json:"nameSuffix,omitempty"`
MinAmountThreshold string `json:"minAmountThreshold,omitempty"`
AssetID string `json:"assetId,omitempty"`
OrderBy string `json:"orderBy,omitempty"` // ASC | DESC, The results are ordered by the creation time of the vault account.
Before string `json:"before,omitempty"` // [optional] cursor string, if specified then we give the next results after this cursor
After string `json:"after,omitempty"` // [optional] cursor string, if specified then we give the next results before this cursor
Limit int64 `json:"limit,omitempty"` // Returns the maximum number of vault accounts in a single response. The default value is 300 and maximum value is 500.
}
// Responses
/*
export interface VaultAccountResponse {
id: string;
name: string;
hiddenOnUI: boolean;
assets: AssetResponse[];
customerRefId?: string;
autoFuel: boolean;
}
*/
type VaultAccountRequest struct {
Name string `json:"name"`
CustomerRefID string `json:"customerRefId,omitempty"`
HiddenOnUI *bool `json:"hiddenOnUi,omitempty"`
AutoFuel *bool `json:"autoFuel,omitempty"`
}
// VaultAccountResponse defines model for VaultAccount.
type VaultAccountResponse struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Assets []*AssetResponse `json:"assets,omitempty"`
CustomerRefID *string `json:"customerRefId,omitempty"`
AutoFuel *bool `json:"autoFuel,omitempty"`
HiddenOnUI *bool `json:"hiddenOnUI,omitempty"`
}
/*
export interface PagedVaultAccountsResponse {
accounts: VaultAccountResponse[];
paging: {
before: string;
after: string;
};
previousUrl: string;
nextUrl: string;
}
*/
type PagedVaultAccountsResponse struct {
Accounts []VaultAccountResponse `json:"accounts,omitempty"`
Paging struct {
Before string `json:"before,omitempty"`
After string `json:"after,omitempty"`
} `json:"paging"`
PreviousURL string `json:"previousUrl,omitempty"`
NextURL string `json:"nextUrl,omitempty"`
}
/*
export interface DepositAddressResponse {
assetId: string;
address: string;
tag?: string;
description?: string;
type: string;
customerRefId?: string;
addressFormat: string;
legacyAddress?: string;
enterpriseAddress?: string;
}
*/
type DepositAddressResponse struct {
AssetID string `json:"assetId,omitempty"` // The ID of the asset
Address string `json:"address,omitempty"` // Address of the asset in a Vault Account, for BTC/LTC the address is in Segwit (Bech32) format, for BCH cash format
Tag string `json:"tag,omitempty"` // Destination tag for XRP, used as memo for EOS/XLM, for the fiat providers (Signet by Signature, SEN by Silvergate, BLINC by BCB Group), it is the Bank Transfer
Description string `json:"description,omitempty"` // Description of the address
TypeAddress string `json:"type,omitempty"` // Address type
CustomerRefID string `json:"customerRefId,omitempty"` // [optional] The ID for AML providers to associate the owner of funds with transactions
LegacyAddress string `json:"legacyAddress,omitempty"` // For BTC/LTC/BCH the legacy format address
AddressFormat string `json:"addressFormat,omitempty"` //
EnterpriseAddress string `json:"enterpriseAddress,omitempty"` //
Bip44AddressIndex int `json:"bip44AddressIndex,omitempty"` // [optional] The address_index, addressFormat, and enterpriseAddress in the derivation path of this address based on BIP44
}
/*
export interface PublicKeyInfoForVaultAccountArgs {
assetId: string;
vaultAccountId: number;
change: number;
addressIndex: number;
compressed?: boolean;
}
*/
/*type PublicKeyInfoForVaultAccountArgs struct {
AssetId string // The ID of the asset
VaultAccountId int64 // The ID of the vault account which address should be retrieved, or 'default' for the default vault account
Change int64 // Whether the address should be derived internal (change) or not
AddressIndex int64 // The index of the address for the derivation path
Compressed bool // Boolean, whether the returned key should be in compressed format or not, false by default
}*/
type PublicKeyInfoResponse struct {
Status int `json:"status,omitempty"`
PublicKey string `json:"publicKey,omitempty"`
Algorithm string `json:"algorithm,omitempty"`
DerivationPath []int64 `json:"derivationPath,omitempty"`
}
/*
export interface GenerateAddressResponse {
address: string;
tag?: string;
legacyAddress?: string;
enterpriseAddress?: string;
}
*/
type GenerateAddressResponse struct {
Address string `json:"address,omitempty"`
Tag *string `json:"tag,omitempty"`
LegacyAddress *string `json:"legacy_address,omitempty"`
EnterpriseAddress *string `json:"enterpriseAddress,omitempty"`
Bip44AddressIndex *int `json:"bip44AddressIndex,omitempty"` // The address_index in the derivation path of this address based on BIP44
}
type PostOptions struct {
Description string `json:"description,omitempty"`
CustomerRefID string `json:"customerRefId,omitempty"`
}
// GetVaultAccounts Deprecated, Gets all assets that are currently supported by Fireblocks,
func (sdk *FireblocksSDK) GetVaultAccounts(q *VaultAccountsFilter) (resp []*VaultAccountResponse, err error) {
query := BuildQuery(q).URLValues()
body, status, err := sdk.client.DoGetRequest("/vault/accounts", query)
if err == nil && status == http.StatusOK {
err = json.Unmarshal(body, &resp)
return
}
return resp, errors.Wrap(err, "failed to make request")
}
// GetVaultAccountsWithPageInfo Gets all assets that are currently supported by Fireblocks
// Retrieves all vault accounts in your workspace. This endpoint returns a limited amount of results and quick response time.
func (sdk *FireblocksSDK) GetVaultAccountsWithPageInfo(q *PagedVaultAccountsRequestFilters) (resp *PagedVaultAccountsResponse, err error) {
query := BuildQuery(q).URLValues()
body, status, err := sdk.client.DoGetRequest("/vault/accounts_paged", query)
if err == nil && status == http.StatusOK {
err = json.Unmarshal(body, &resp)
return
}
return resp, errors.Wrap(err, "failed to make request")
}
func (sdk *FireblocksSDK) GetVaultAccountsByID(vaultAccountID string) (resp *VaultAccountResponse, err error) {
body, status, err := sdk.client.DoGetRequest(fmt.Sprintf("/vault/accounts/%s", vaultAccountID), nil)
if err == nil && status == http.StatusOK {
err = json.Unmarshal(body, &resp)
return
}
return resp, errors.Wrap(err, "failed to make request")
}
// GetVaultAccountAsset Retrieves a wallet of a specific asset under a Fireblocks Vault Account.
func (sdk *FireblocksSDK) GetVaultAccountAsset(vaultAccountID, assetID string) (resp *AssetResponse, err error) {
body, status, err := sdk.client.DoGetRequest(fmt.Sprintf("/vault/accounts/%s/%s", vaultAccountID, assetID), nil)
if err == nil && status == http.StatusOK {
err = json.Unmarshal(body, &resp)
return
}
return resp, errors.Wrap(err, "failed to make request")
}
// GetDepositAddresses Retrieves a wallet of a specific asset under a Fireblocks Vault Account.
func (sdk *FireblocksSDK) GetDepositAddresses(vaultAccountID, assetID string) (resp []*DepositAddressResponse, err error) {
body, status, err := sdk.client.DoGetRequest(fmt.Sprintf("/vault/accounts/%s/%s/addresses", vaultAccountID, assetID), nil)
if err == nil && status == http.StatusOK {
err = json.Unmarshal(body, &resp)
return
}
return resp, errors.Wrap(err, "failed to make request")
}
// Response type supposed to be this - test it
/*
{
"input": {
"txHash": "string",
"index": "number"
},
"address": "string",
"amount": "string",
"confirmations": "number",
"status": "string"
}
*/
// GetUnspentInputs Returns unspent inputs of the requested asset in the Vault Account.
// Gets utxo list for an asset in a vault account
// vaultAccountId - The vault account ID
// assetId - The ID of the asset for which to get the utxo list
func (sdk *FireblocksSDK) GetUnspentInputs(vaultAccountID, assetID string) (resp []DepositAddressResponse, err error) {
body, status, err := sdk.client.DoGetRequest(fmt.Sprintf("/vault/accounts/%s/%s/unspent_inputs", vaultAccountID, assetID), nil)
if err == nil && status == http.StatusOK {
err = json.Unmarshal(body, &resp)
return
}
return resp, errors.Wrap(err, "failed to make request")
}
// GetPublicKeyInfoForVaultAccount Get the public key information for a vault account
func (sdk *FireblocksSDK) GetPublicKeyInfoForVaultAccount(
vaultAccountID, assetID string,
change int,
addressIndex int,
) (resp *PublicKeyInfoResponse, err error) {
body, status, err := sdk.client.DoGetRequest(fmt.Sprintf(
"/vault/accounts/%s/%s/%v/%v/public_key_info",
vaultAccountID,
assetID,
change,
addressIndex,
), nil)
if err == nil && status == http.StatusOK {
err = json.Unmarshal(body, &resp)
return
}
return resp, errors.Wrap(err, "failed to make request")
}
func (sdk *FireblocksSDK) GenerateNewAddress(vaultAccountID, assetID, description, customerRefID string, opts ...func(*PostRequestOption)) (resp *GenerateAddressResponse, err error) {
post := &PostOptions{
Description: description,
CustomerRefID: customerRefID,
}
body, status, err := sdk.client.DoPostRequest(
fmt.Sprintf("/vault/accounts/%s/%s/addresses", vaultAccountID, assetID),
post,
opts...,
)
if err == nil && status == http.StatusOK {
err = json.Unmarshal(body, &resp)
return
}
return resp, errors.Wrap(err, "failed to make request")
}
func (sdk *FireblocksSDK) CreateVaultAccount(name string, customerRefID string, hiddenOnUI *bool, autoFuel *bool, opts ...func(*PostRequestOption)) (resp VaultAccountResponse, err error) {
post := &VaultAccountRequest{
Name: name,
HiddenOnUI: hiddenOnUI,
CustomerRefID: customerRefID,
AutoFuel: autoFuel,
}
body, status, err := sdk.client.DoPostRequest(
"/vault/accounts",
post,
opts...,
)
if err == nil && status == http.StatusOK {
err = json.Unmarshal(body, &resp)
return
}
return resp, errors.Wrap(err, "failed to make request")
}