@@ -215,16 +215,18 @@ class AleoNetworkClient {
215
215
nonces ?: string [ ] ,
216
216
privateKey ?: string | PrivateKey ,
217
217
} ) : Promise < Array < RecordPlaintext > > {
218
- if ( params . unspent == null ) {
219
- params . unspent = false ;
218
+ let { startHeight, endHeight, unspent, programs, amounts, maxMicrocredits, nonces, privateKey } = params ;
219
+
220
+ if ( unspent == null ) {
221
+ unspent = false ;
220
222
}
221
223
222
- if ( params . nonces == null ) {
223
- params . nonces = [ ] ;
224
+ if ( nonces == null ) {
225
+ nonces = [ ] ;
224
226
}
225
227
226
228
// Ensure start height is not negative
227
- if ( params . startHeight < 0 ) {
229
+ if ( startHeight < 0 ) {
228
230
throw new Error ( "Start height must be greater than or equal to 0" ) ;
229
231
}
230
232
@@ -238,7 +240,7 @@ class AleoNetworkClient {
238
240
let latestHeight : number ;
239
241
240
242
// Ensure a private key is present to find owned records
241
- if ( typeof params . privateKey === "undefined" ) {
243
+ if ( typeof privateKey === "undefined" ) {
242
244
if ( typeof this . account === "undefined" ) {
243
245
throw new Error (
244
246
"Private key must be specified in an argument to findOwnedRecords or set in the AleoNetworkClient" ,
@@ -249,9 +251,9 @@ class AleoNetworkClient {
249
251
} else {
250
252
try {
251
253
resolvedPrivateKey =
252
- params . privateKey instanceof PrivateKey
253
- ? params . privateKey
254
- : PrivateKey . from_string ( params . privateKey ) ;
254
+ privateKey instanceof PrivateKey
255
+ ? privateKey
256
+ : PrivateKey . from_string ( privateKey ) ;
255
257
} catch ( error ) {
256
258
throw new Error ( "Error parsing private key provided." ) ;
257
259
}
@@ -273,24 +275,24 @@ class AleoNetworkClient {
273
275
}
274
276
275
277
// If no end height is specified or is greater than the latest height, set the end height to the latest height
276
- if ( typeof params . endHeight === "number" && params . endHeight <= latestHeight ) {
277
- end = params . endHeight ;
278
+ if ( typeof endHeight === "number" && endHeight <= latestHeight ) {
279
+ end = endHeight ;
278
280
} else {
279
281
end = latestHeight ;
280
282
}
281
283
282
284
// If the starting is greater than the ending height, return an error
283
- if ( params . startHeight > end ) {
285
+ if ( startHeight > end ) {
284
286
throw new Error (
285
287
"Start height must be less than or equal to end height." ,
286
288
) ;
287
289
}
288
290
289
291
// Iterate through blocks in reverse order in chunks of 50
290
- while ( end > params . startHeight ) {
292
+ while ( end > startHeight ) {
291
293
start = end - 50 ;
292
- if ( start < params . startHeight ) {
293
- start = params . startHeight ;
294
+ if ( start < startHeight ) {
295
+ start = startHeight ;
294
296
}
295
297
try {
296
298
// Get 50 blocks (or the difference between the start and end if less than 50)
@@ -327,10 +329,10 @@ class AleoNetworkClient {
327
329
] ;
328
330
// Only search for unspent records in the specified programs.
329
331
if (
330
- ! ( typeof params . programs === "undefined" )
332
+ ! ( typeof programs === "undefined" )
331
333
) {
332
334
if (
333
- ! params . programs . includes (
335
+ ! programs . includes (
334
336
transition . program ,
335
337
)
336
338
) {
@@ -373,14 +375,14 @@ class AleoNetworkClient {
373
375
const nonce =
374
376
recordPlaintext . nonce ( ) ;
375
377
if (
376
- params . nonces . includes (
378
+ nonces . includes (
377
379
nonce ,
378
380
)
379
381
) {
380
382
continue ;
381
383
}
382
384
383
- if ( params . unspent ) {
385
+ if ( unspent ) {
384
386
const recordViewKey = recordPlaintext . recordViewKey ( viewKey ) . toString ( ) ;
385
387
386
388
// Otherwise record the nonce that has been found
@@ -408,13 +410,13 @@ class AleoNetworkClient {
408
410
}
409
411
410
412
// Add the record to the list of records if the user did not specify amounts.
411
- if ( ! params . amounts ) {
413
+ if ( ! amounts ) {
412
414
records . push (
413
415
recordPlaintext ,
414
416
) ;
415
417
// If the user specified a maximum number of microcredits, check if the search has found enough
416
418
if (
417
- typeof params . maxMicrocredits ===
419
+ typeof maxMicrocredits ===
418
420
"number"
419
421
) {
420
422
totalRecordValue +=
@@ -423,7 +425,7 @@ class AleoNetworkClient {
423
425
if (
424
426
totalRecordValue >=
425
427
BigInt (
426
- params . maxMicrocredits ,
428
+ maxMicrocredits ,
427
429
)
428
430
) {
429
431
return records ;
@@ -434,15 +436,15 @@ class AleoNetworkClient {
434
436
// If the user specified a list of amounts, check if the search has found them
435
437
if (
436
438
! (
437
- typeof params . amounts ===
439
+ typeof amounts ===
438
440
"undefined"
439
441
) &&
440
- params . amounts . length > 0
442
+ amounts . length > 0
441
443
) {
442
444
let amounts_found = 0 ;
443
445
if (
444
446
recordPlaintext . microcredits ( ) >
445
- params . amounts [
447
+ amounts [
446
448
amounts_found
447
449
]
448
450
) {
@@ -452,7 +454,7 @@ class AleoNetworkClient {
452
454
) ;
453
455
// If the user specified a maximum number of microcredits, check if the search has found enough
454
456
if (
455
- typeof params . maxMicrocredits ===
457
+ typeof maxMicrocredits ===
456
458
"number"
457
459
) {
458
460
totalRecordValue +=
@@ -461,15 +463,15 @@ class AleoNetworkClient {
461
463
if (
462
464
totalRecordValue >=
463
465
BigInt (
464
- params . maxMicrocredits ,
466
+ maxMicrocredits ,
465
467
)
466
468
) {
467
469
return records ;
468
470
}
469
471
}
470
472
if (
471
473
records . length >=
472
- params . amounts . length
474
+ amounts . length
473
475
) {
474
476
return records ;
475
477
}
@@ -1249,13 +1251,15 @@ class AleoNetworkClient {
1249
1251
mappingName : string ,
1250
1252
key : string | Plaintext ,
1251
1253
} ) : Promise < Plaintext > {
1254
+ const { programId, mappingName, key } = params ;
1255
+
1252
1256
this . ctx = { "X-ALEO-METHOD" : "getProgramMappingPlaintext" } ;
1253
1257
1254
1258
try {
1255
- const keyString = params . key instanceof Plaintext ? params . key . toString ( ) : params . key ;
1259
+ const keyString = key instanceof Plaintext ? key . toString ( ) : key ;
1256
1260
1257
1261
const value = await this . fetchRaw (
1258
- `/program/${ params . programId } /mapping/${ params . mappingName } /${ keyString } ` ,
1262
+ `/program/${ programId } /mapping/${ mappingName } /${ keyString } ` ,
1259
1263
) ;
1260
1264
1261
1265
return Plaintext . fromString ( JSON . parse ( value ) ) ;
@@ -1645,15 +1649,13 @@ class AleoNetworkClient {
1645
1649
* // Wait for the transaction to be confirmed.
1646
1650
* const transaction = await networkClient.waitForTransactionConfirmation({ transactionId });
1647
1651
*/
1648
- async waitForTransactionConfirmation ( {
1649
- transactionId,
1650
- checkInterval = 2000 ,
1651
- timeout = 45000 ,
1652
- } : {
1652
+ async waitForTransactionConfirmation ( params : {
1653
1653
transactionId : string ,
1654
1654
checkInterval ?: number ,
1655
1655
timeout ?: number ,
1656
1656
} ) : Promise < ConfirmedTransactionJSON > {
1657
+ const { transactionId, checkInterval = 2000 , timeout = 45000 } = params ;
1658
+
1657
1659
const startTime = Date . now ( ) ;
1658
1660
1659
1661
return new Promise ( ( resolve , reject ) => {
0 commit comments