@@ -23,39 +23,53 @@ interface RecordProvider {
23
23
/**
24
24
* Find a credits.aleo record with a given number of microcredits from the chosen provider
25
25
*
26
- * @param {number } microcredits The number of microcredits to search for
27
- * @param {boolean } unspent Whether or not the record is unspent
28
- * @param {string[] } nonces Nonces of records already found so they are not found again
29
- * @param {RecordSearchParams } searchParameters Additional parameters to search for
26
+ * @param {Object } params
27
+ * @param {number } params.microcredits The number of microcredits to search for
28
+ * @param {boolean } params.unspent Whether or not the record is unspent
29
+ * @param {string[] } [params.nonces] Nonces of records already found so they are not found again
30
+ * @param {RecordSearchParams } [params.searchParameters] Additional parameters to search for
30
31
* @returns {Promise<RecordPlaintext> } The record if found, otherwise an error
31
32
*
32
33
* @example
33
34
* // A class implementing record provider can be used to find a record with a given number of microcredits
34
- * const record = await recordProvider.findCreditsRecord(5000, true, []);
35
+ * const record = await recordProvider.findCreditsRecord({
36
+ * microcredits: 5000,
37
+ * unspent: true,
38
+ * nonces: [],
39
+ * });
35
40
*
36
41
* // When a record is found but not yet used, its nonce should be added to the nonces array so that it is not
37
42
* // found again if a subsequent search is performed
38
- * const record2 = await recordProvider.findCreditsRecord(5000, true, [record.nonce()]);
43
+ * const record2 = await recordProvider.findCreditsRecord({
44
+ * microcredits: 5000,
45
+ * unspent: true,
46
+ * nonces: [record.nonce()],
47
+ * });
39
48
*
40
49
* // When the program manager is initialized with the record provider it will be used to find automatically find
41
50
* // fee records and amount records for value transfers so that they do not need to be specified manually
42
51
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
43
52
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
44
53
*/
45
- findCreditsRecord ( microcredits : number , unspent : boolean , nonces ?: string [ ] , searchParameters ?: RecordSearchParams ) : Promise < RecordPlaintext > ;
54
+ findCreditsRecord ( params : { microcredits : number , unspent : boolean , nonces ?: string [ ] , searchParameters ?: RecordSearchParams } ) : Promise < RecordPlaintext > ;
46
55
47
56
/**
48
57
* Find a list of credit.aleo records with a given number of microcredits from the chosen provider
49
58
*
50
- * @param {number } microcreditAmounts A list of separate microcredit amounts to search for (e.g. [5000, 100000])
51
- * @param {boolean } unspent Whether or not the record is unspent
52
- * @param {string[] } nonces Nonces of records already found so that they are not found again
53
- * @param {RecordSearchParams } searchParameters Additional parameters to search for
59
+ * @param {Object } params
60
+ * @param {number } params.microcreditAmounts A list of separate microcredit amounts to search for (e.g. [5000, 100000])
61
+ * @param {boolean } params.unspent Whether or not the record is unspent
62
+ * @param {string[] } [params.nonces] Nonces of records already found so that they are not found again
63
+ * @param {RecordSearchParams } [params.searchParameters] Additional parameters to search for
54
64
* @returns {Promise<RecordPlaintext[]> } A list of records with a value greater or equal to the amounts specified if such records exist, otherwise an error
55
65
*
56
66
* @example
57
67
* // A class implementing record provider can be used to find a record with a given number of microcredits
58
- * const records = await recordProvider.findCreditsRecords([5000, 5000], true, []);
68
+ * const records = await recordProvider.findCreditsRecords({
69
+ * microcredits: [5000, 5000],
70
+ * unspent: true,
71
+ * nonces: [],
72
+ * });
59
73
*
60
74
* // When a record is found but not yet used, it's nonce should be added to the nonces array so that it is not
61
75
* // found again if a subsequent search is performed
@@ -68,13 +82,14 @@ interface RecordProvider {
68
82
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
69
83
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
70
84
*/
71
- findCreditsRecords ( microcreditAmounts : number [ ] , unspent : boolean , nonces ?: string [ ] , searchParameters ?: RecordSearchParams ) : Promise < RecordPlaintext [ ] > ;
85
+ findCreditsRecords ( params : { microcredits : number [ ] , unspent : boolean , nonces ?: string [ ] , searchParameters ?: RecordSearchParams } ) : Promise < RecordPlaintext [ ] > ;
72
86
73
87
/**
74
88
* Find an arbitrary record
75
- * @param {boolean } unspent Whether or not the record is unspent
76
- * @param {string[] } nonces Nonces of records already found so that they are not found again
77
- * @param {RecordSearchParams } searchParameters Additional parameters to search for
89
+ * @param {Object } params
90
+ * @param {boolean } params.unspent Whether or not the record is unspent
91
+ * @param {string[] } [params.nonces] Nonces of records already found so that they are not found again
92
+ * @param {RecordSearchParams } [params.searchParameters] Additional parameters to search for
78
93
* @returns {Promise<RecordPlaintext> } The record if found, otherwise an error
79
94
*
80
95
* @example
@@ -99,16 +114,21 @@ interface RecordProvider {
99
114
*
100
115
* const params = new CustomRecordSearch(0, 100, 5000, "credits.aleo", "credits");
101
116
*
102
- * const record = await recordProvider.findRecord(true, [], params);
117
+ * const record = await recordProvider.findRecord({
118
+ * unspent: true,
119
+ * nonces: [],
120
+ * searchParameters: params,
121
+ * });
103
122
*/
104
- findRecord ( unspent : boolean , nonces ?: string [ ] , searchParameters ?: RecordSearchParams ) : Promise < RecordPlaintext > ;
123
+ findRecord ( params : { unspent : boolean , nonces ?: string [ ] , searchParameters ?: RecordSearchParams } ) : Promise < RecordPlaintext > ;
105
124
106
125
/**
107
126
* Find multiple records from arbitrary programs
108
127
*
109
- * @param {boolean } unspent Whether or not the record is unspent
110
- * @param {string[] } nonces Nonces of records already found so that they are not found again
111
- * @param {RecordSearchParams } searchParameters Additional parameters to search for
128
+ * @param {Object } params
129
+ * @param {boolean } params.unspent Whether or not the record is unspent
130
+ * @param {string[] } [params.nonces] Nonces of records already found so that they are not found again
131
+ * @param {RecordSearchParams } [params.searchParameters] Additional parameters to search for
112
132
* @returns {Promise<RecordPlaintext> } The record if found, otherwise an error
113
133
*
114
134
* // The RecordSearchParams interface can be used to create parameters for custom record searches which can then
@@ -133,9 +153,13 @@ interface RecordProvider {
133
153
* }
134
154
*
135
155
* const params = new CustomRecordSearch(0, 100, 5000, 2, "credits.aleo", "credits");
136
- * const records = await recordProvider.findRecord(true, [], params);
156
+ * const records = await recordProvider.findRecords({
157
+ * unspent: true,
158
+ * nonces: [],
159
+ * searchParameters: params,
160
+ * });
137
161
*/
138
- findRecords ( unspent : boolean , nonces ?: string [ ] , searchParameters ?: RecordSearchParams ) : Promise < RecordPlaintext [ ] > ;
162
+ findRecords ( params : { unspent : boolean , nonces ?: string [ ] , searchParameters ?: RecordSearchParams } ) : Promise < RecordPlaintext [ ] > ;
139
163
}
140
164
141
165
/**
@@ -145,6 +169,7 @@ interface RecordProvider {
145
169
class NetworkRecordProvider implements RecordProvider {
146
170
account : Account ;
147
171
networkClient : AleoNetworkClient ;
172
+
148
173
constructor ( account : Account , networkClient : AleoNetworkClient ) {
149
174
this . account = account ;
150
175
this . networkClient = networkClient ;
@@ -162,10 +187,11 @@ class NetworkRecordProvider implements RecordProvider {
162
187
/**
163
188
* Find a list of credit records with a given number of microcredits by via the official Aleo API
164
189
*
165
- * @param {number[] } microcredits The number of microcredits to search for
166
- * @param {boolean } unspent Whether or not the record is unspent
167
- * @param {string[] } nonces Nonces of records already found so that they are not found again
168
- * @param {RecordSearchParams } searchParameters Additional parameters to search for
190
+ * @param {Object } params
191
+ * @param {number[] } params.microcredits The number of microcredits to search for
192
+ * @param {boolean } params.unspent Whether or not the record is unspent
193
+ * @param {string[] } [params.nonces] Nonces of records already found so that they are not found again
194
+ * @param {RecordSearchParams } [params.searchParameters] Additional parameters to search for
169
195
* @returns {Promise<RecordPlaintext> } The record if found, otherwise an error
170
196
*
171
197
* @example
@@ -179,15 +205,26 @@ class NetworkRecordProvider implements RecordProvider {
179
205
*
180
206
* // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
181
207
* // found again if a subsequent search is performed
182
- * const records = await recordProvider.findCreditsRecords(5000, true, [record.nonce()]);
208
+ * const records = await recordProvider.findCreditsRecords({
209
+ * microcredits: [5000],
210
+ * unspent: true,
211
+ * nonces: [record.nonce()],
212
+ * });
183
213
*
184
214
* // When the program manager is initialized with the record provider it will be used to find automatically find
185
215
* // fee records and amount records for value transfers so that they do not need to be specified manually
186
216
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
187
217
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
188
218
*
189
219
* */
190
- async findCreditsRecords ( microcredits : number [ ] , unspent : boolean , nonces ?: string [ ] , searchParameters ?: RecordSearchParams ) : Promise < RecordPlaintext [ ] > {
220
+ async findCreditsRecords ( params : {
221
+ microcredits : number [ ] ,
222
+ unspent : boolean ,
223
+ nonces ?: string [ ] ,
224
+ searchParameters ?: RecordSearchParams ,
225
+ } ) : Promise < RecordPlaintext [ ] > {
226
+ let { microcredits, unspent, nonces, searchParameters } = params ;
227
+
191
228
let startHeight = 0 ;
192
229
let endHeight = 0 ;
193
230
let maxAmount = undefined ;
@@ -240,10 +277,11 @@ class NetworkRecordProvider implements RecordProvider {
240
277
/**
241
278
* Find a credit record with a given number of microcredits by via the official Aleo API
242
279
*
243
- * @param {number } microcredits The number of microcredits to search for
244
- * @param {boolean } unspent Whether or not the record is unspent
245
- * @param {string[] } nonces Nonces of records already found so that they are not found again
246
- * @param {RecordSearchParams } searchParameters Additional parameters to search for
280
+ * @param {Object } params
281
+ * @param {number } params.microcredits The number of microcredits to search for
282
+ * @param {boolean } params.unspent Whether or not the record is unspent
283
+ * @param {string[] } [params.nonces] Nonces of records already found so that they are not found again
284
+ * @param {RecordSearchParams } [params.searchParameters] Additional parameters to search for
247
285
* @returns {Promise<RecordPlaintext> } The record if found, otherwise an error
248
286
*
249
287
* @example
@@ -253,7 +291,11 @@ class NetworkRecordProvider implements RecordProvider {
253
291
* const recordProvider = new NetworkRecordProvider(account, networkClient);
254
292
*
255
293
* // The record provider can be used to find records with a given number of microcredits
256
- * const record = await recordProvider.findCreditsRecord(5000, true, []);
294
+ * const record = await recordProvider.findCreditsRecord({
295
+ * microcredits: 5000,
296
+ * unspent: true,
297
+ * nonces: [],
298
+ * });
257
299
*
258
300
* // When a record is found but not yet used, it's nonce should be added to the nonces parameter so that it is not
259
301
* // found again if a subsequent search is performed
@@ -264,11 +306,23 @@ class NetworkRecordProvider implements RecordProvider {
264
306
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
265
307
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
266
308
*/
267
- async findCreditsRecord ( microcredits : number , unspent : boolean , nonces ?: string [ ] , searchParameters ?: RecordSearchParams ) : Promise < RecordPlaintext > {
309
+ async findCreditsRecord ( params : {
310
+ microcredits : number ,
311
+ unspent : boolean ,
312
+ nonces ?: string [ ] ,
313
+ searchParameters ?: RecordSearchParams ,
314
+ } ) : Promise < RecordPlaintext > {
315
+ const { microcredits, unspent, nonces, searchParameters } = params ;
316
+
268
317
let records = null ;
269
318
270
319
try {
271
- records = await this . findCreditsRecords ( [ microcredits ] , unspent , nonces , searchParameters ) ;
320
+ records = await this . findCreditsRecords ( {
321
+ microcredits : [ microcredits ] ,
322
+ unspent,
323
+ nonces,
324
+ searchParameters,
325
+ } ) ;
272
326
} catch ( e ) {
273
327
console . log ( "No records found with error:" , e ) ;
274
328
}
@@ -284,14 +338,24 @@ class NetworkRecordProvider implements RecordProvider {
284
338
/**
285
339
* Find an arbitrary record. WARNING: This function is not implemented yet and will throw an error.
286
340
*/
287
- async findRecord ( unspent : boolean , nonces ?: string [ ] , searchParameters ?: RecordSearchParams ) : Promise < RecordPlaintext > {
341
+ async findRecord ( params : {
342
+ unspent : boolean ,
343
+ nonces ?: string [ ] ,
344
+ searchParameters ?: RecordSearchParams ,
345
+ } ) : Promise < RecordPlaintext > {
288
346
throw new Error ( "Not implemented" ) ;
289
347
}
290
348
291
349
/**
292
350
* Find multiple records from a specified program.
293
351
*/
294
- async findRecords ( unspent : boolean , nonces ?: string [ ] , searchParameters ?: RecordSearchParams ) : Promise < RecordPlaintext [ ] > {
352
+ async findRecords ( params : {
353
+ unspent : boolean ,
354
+ nonces ?: string [ ] ,
355
+ searchParameters ?: RecordSearchParams ,
356
+ } ) : Promise < RecordPlaintext [ ] > {
357
+ let { unspent, nonces, searchParameters } = params ;
358
+
295
359
let startHeight = 0 ;
296
360
let endHeight = 0 ;
297
361
let amounts = undefined ;
@@ -363,7 +427,7 @@ class NetworkRecordProvider implements RecordProvider {
363
427
*
364
428
* @example
365
429
* // Create a new BlockHeightSearch
366
- * const params = new BlockHeightSearch(89995, 99995);
430
+ * const params = new BlockHeightSearch({ startHeight: 89995, endHeight: 99995 } );
367
431
*
368
432
* // Create a new NetworkRecordProvider
369
433
* const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
@@ -372,15 +436,20 @@ class NetworkRecordProvider implements RecordProvider {
372
436
*
373
437
* // The record provider can be used to find records with a given number of microcredits and the block height search
374
438
* // can be used to find records within a given block height range
375
- * const record = await recordProvider.findCreditsRecord(5000, true, [], params);
439
+ * const record = await recordProvider.findCreditsRecord({
440
+ * microcredits: 5000,
441
+ * unspent: true,
442
+ * nonces: [],
443
+ * searchParameters: params,
444
+ * });
376
445
*
377
446
*/
378
447
class BlockHeightSearch implements RecordSearchParams {
379
448
startHeight : number ;
380
449
endHeight : number ;
381
- constructor ( startHeight : number , endHeight : number ) {
382
- this . startHeight = startHeight ;
383
- this . endHeight = endHeight ;
450
+ constructor ( params : { startHeight : number , endHeight : number } ) {
451
+ this . startHeight = params . startHeight ;
452
+ this . endHeight = params . endHeight ;
384
453
}
385
454
}
386
455
0 commit comments