@@ -248,16 +248,18 @@ class AleoNetworkClient {
248
248
nonces ?: string [ ] ,
249
249
privateKey ?: string | PrivateKey ,
250
250
} ) : Promise < Array < RecordPlaintext > > {
251
- if ( params . unspent == null ) {
252
- params . unspent = false ;
251
+ let { startHeight, endHeight, unspent, programs, amounts, maxMicrocredits, nonces, privateKey } = params ;
252
+
253
+ if ( unspent == null ) {
254
+ unspent = false ;
253
255
}
254
256
255
- if ( params . nonces == null ) {
256
- params . nonces = [ ] ;
257
+ if ( nonces == null ) {
258
+ nonces = [ ] ;
257
259
}
258
260
259
261
// Ensure start height is not negative
260
- if ( params . startHeight < 0 ) {
262
+ if ( startHeight < 0 ) {
261
263
throw new Error ( "Start height must be greater than or equal to 0" ) ;
262
264
}
263
265
@@ -271,7 +273,7 @@ class AleoNetworkClient {
271
273
let latestHeight : number ;
272
274
273
275
// Ensure a private key is present to find owned records
274
- if ( typeof params . privateKey === "undefined" ) {
276
+ if ( typeof privateKey === "undefined" ) {
275
277
if ( typeof this . account === "undefined" ) {
276
278
throw new Error (
277
279
"Private key must be specified in an argument to findOwnedRecords or set in the AleoNetworkClient" ,
@@ -282,9 +284,9 @@ class AleoNetworkClient {
282
284
} else {
283
285
try {
284
286
resolvedPrivateKey =
285
- params . privateKey instanceof PrivateKey
286
- ? params . privateKey
287
- : PrivateKey . from_string ( params . privateKey ) ;
287
+ privateKey instanceof PrivateKey
288
+ ? privateKey
289
+ : PrivateKey . from_string ( privateKey ) ;
288
290
} catch ( error ) {
289
291
throw new Error ( "Error parsing private key provided." ) ;
290
292
}
@@ -306,24 +308,24 @@ class AleoNetworkClient {
306
308
}
307
309
308
310
// If no end height is specified or is greater than the latest height, set the end height to the latest height
309
- if ( typeof params . endHeight === "number" && params . endHeight <= latestHeight ) {
310
- end = params . endHeight ;
311
+ if ( typeof endHeight === "number" && endHeight <= latestHeight ) {
312
+ end = endHeight ;
311
313
} else {
312
314
end = latestHeight ;
313
315
}
314
316
315
317
// If the starting is greater than the ending height, return an error
316
- if ( params . startHeight > end ) {
318
+ if ( startHeight > end ) {
317
319
throw new Error (
318
320
"Start height must be less than or equal to end height." ,
319
321
) ;
320
322
}
321
323
322
324
// Iterate through blocks in reverse order in chunks of 50
323
- while ( end > params . startHeight ) {
325
+ while ( end > startHeight ) {
324
326
start = end - 50 ;
325
- if ( start < params . startHeight ) {
326
- start = params . startHeight ;
327
+ if ( start < startHeight ) {
328
+ start = startHeight ;
327
329
}
328
330
try {
329
331
// Get 50 blocks (or the difference between the start and end if less than 50)
@@ -360,10 +362,10 @@ class AleoNetworkClient {
360
362
] ;
361
363
// Only search for unspent records in the specified programs.
362
364
if (
363
- ! ( typeof params . programs === "undefined" )
365
+ ! ( typeof programs === "undefined" )
364
366
) {
365
367
if (
366
- ! params . programs . includes (
368
+ ! programs . includes (
367
369
transition . program ,
368
370
)
369
371
) {
@@ -406,14 +408,14 @@ class AleoNetworkClient {
406
408
const nonce =
407
409
recordPlaintext . nonce ( ) ;
408
410
if (
409
- params . nonces . includes (
411
+ nonces . includes (
410
412
nonce ,
411
413
)
412
414
) {
413
415
continue ;
414
416
}
415
417
416
- if ( params . unspent ) {
418
+ if ( unspent ) {
417
419
const recordViewKey = recordPlaintext . recordViewKey ( viewKey ) . toString ( ) ;
418
420
419
421
// Otherwise record the nonce that has been found
@@ -441,13 +443,13 @@ class AleoNetworkClient {
441
443
}
442
444
443
445
// Add the record to the list of records if the user did not specify amounts.
444
- if ( ! params . amounts ) {
446
+ if ( ! amounts ) {
445
447
records . push (
446
448
recordPlaintext ,
447
449
) ;
448
450
// If the user specified a maximum number of microcredits, check if the search has found enough
449
451
if (
450
- typeof params . maxMicrocredits ===
452
+ typeof maxMicrocredits ===
451
453
"number"
452
454
) {
453
455
totalRecordValue +=
@@ -456,7 +458,7 @@ class AleoNetworkClient {
456
458
if (
457
459
totalRecordValue >=
458
460
BigInt (
459
- params . maxMicrocredits ,
461
+ maxMicrocredits ,
460
462
)
461
463
) {
462
464
return records ;
@@ -467,15 +469,15 @@ class AleoNetworkClient {
467
469
// If the user specified a list of amounts, check if the search has found them
468
470
if (
469
471
! (
470
- typeof params . amounts ===
472
+ typeof amounts ===
471
473
"undefined"
472
474
) &&
473
- params . amounts . length > 0
475
+ amounts . length > 0
474
476
) {
475
477
let amounts_found = 0 ;
476
478
if (
477
479
recordPlaintext . microcredits ( ) >
478
- params . amounts [
480
+ amounts [
479
481
amounts_found
480
482
]
481
483
) {
@@ -485,7 +487,7 @@ class AleoNetworkClient {
485
487
) ;
486
488
// If the user specified a maximum number of microcredits, check if the search has found enough
487
489
if (
488
- typeof params . maxMicrocredits ===
490
+ typeof maxMicrocredits ===
489
491
"number"
490
492
) {
491
493
totalRecordValue +=
@@ -494,15 +496,15 @@ class AleoNetworkClient {
494
496
if (
495
497
totalRecordValue >=
496
498
BigInt (
497
- params . maxMicrocredits ,
499
+ maxMicrocredits ,
498
500
)
499
501
) {
500
502
return records ;
501
503
}
502
504
}
503
505
if (
504
506
records . length >=
505
- params . amounts . length
507
+ amounts . length
506
508
) {
507
509
return records ;
508
510
}
@@ -1281,13 +1283,15 @@ class AleoNetworkClient {
1281
1283
mappingName : string ,
1282
1284
key : string | Plaintext ,
1283
1285
} ) : Promise < Plaintext > {
1286
+ const { programId, mappingName, key } = params ;
1287
+
1284
1288
this . ctx = { "X-ALEO-METHOD" : "getProgramMappingPlaintext" } ;
1285
1289
1286
1290
try {
1287
- const keyString = params . key instanceof Plaintext ? params . key . toString ( ) : params . key ;
1291
+ const keyString = key instanceof Plaintext ? key . toString ( ) : key ;
1288
1292
1289
1293
const value = await this . fetchRaw (
1290
- `/program/${ params . programId } /mapping/${ params . mappingName } /${ keyString } ` ,
1294
+ `/program/${ programId } /mapping/${ mappingName } /${ keyString } ` ,
1291
1295
) ;
1292
1296
1293
1297
return Plaintext . fromString ( JSON . parse ( value ) ) ;
@@ -1717,15 +1721,13 @@ class AleoNetworkClient {
1717
1721
* // Wait for the transaction to be confirmed.
1718
1722
* const transaction = await networkClient.waitForTransactionConfirmation({ transactionId });
1719
1723
*/
1720
- async waitForTransactionConfirmation ( {
1721
- transactionId,
1722
- checkInterval = 2000 ,
1723
- timeout = 45000 ,
1724
- } : {
1724
+ async waitForTransactionConfirmation ( params : {
1725
1725
transactionId : string ,
1726
1726
checkInterval ?: number ,
1727
1727
timeout ?: number ,
1728
1728
} ) : Promise < ConfirmedTransactionJSON > {
1729
+ const { transactionId, checkInterval = 2000 , timeout = 45000 } = params ;
1730
+
1729
1731
const startTime = Date . now ( ) ;
1730
1732
1731
1733
return new Promise ( ( resolve , reject ) => {
0 commit comments