@@ -230,16 +230,18 @@ class AleoNetworkClient {
230
230
nonces ?: string [ ] ,
231
231
privateKey ?: string | PrivateKey ,
232
232
} ) : Promise < Array < RecordPlaintext > > {
233
- if ( params . unspent == null ) {
234
- params . unspent = false ;
233
+ let { startHeight, endHeight, unspent, programs, amounts, maxMicrocredits, nonces, privateKey } = params ;
234
+
235
+ if ( unspent == null ) {
236
+ unspent = false ;
235
237
}
236
238
237
- if ( params . nonces == null ) {
238
- params . nonces = [ ] ;
239
+ if ( nonces == null ) {
240
+ nonces = [ ] ;
239
241
}
240
242
241
243
// Ensure start height is not negative
242
- if ( params . startHeight < 0 ) {
244
+ if ( startHeight < 0 ) {
243
245
throw new Error ( "Start height must be greater than or equal to 0" ) ;
244
246
}
245
247
@@ -253,7 +255,7 @@ class AleoNetworkClient {
253
255
let latestHeight : number ;
254
256
255
257
// Ensure a private key is present to find owned records
256
- if ( typeof params . privateKey === "undefined" ) {
258
+ if ( typeof privateKey === "undefined" ) {
257
259
if ( typeof this . account === "undefined" ) {
258
260
throw new Error (
259
261
"Private key must be specified in an argument to findOwnedRecords or set in the AleoNetworkClient" ,
@@ -264,9 +266,9 @@ class AleoNetworkClient {
264
266
} else {
265
267
try {
266
268
resolvedPrivateKey =
267
- params . privateKey instanceof PrivateKey
268
- ? params . privateKey
269
- : PrivateKey . from_string ( params . privateKey ) ;
269
+ privateKey instanceof PrivateKey
270
+ ? privateKey
271
+ : PrivateKey . from_string ( privateKey ) ;
270
272
} catch ( error ) {
271
273
throw new Error ( "Error parsing private key provided." ) ;
272
274
}
@@ -288,24 +290,24 @@ class AleoNetworkClient {
288
290
}
289
291
290
292
// If no end height is specified or is greater than the latest height, set the end height to the latest height
291
- if ( typeof params . endHeight === "number" && params . endHeight <= latestHeight ) {
292
- end = params . endHeight ;
293
+ if ( typeof endHeight === "number" && endHeight <= latestHeight ) {
294
+ end = endHeight ;
293
295
} else {
294
296
end = latestHeight ;
295
297
}
296
298
297
299
// If the starting is greater than the ending height, return an error
298
- if ( params . startHeight > end ) {
300
+ if ( startHeight > end ) {
299
301
throw new Error (
300
302
"Start height must be less than or equal to end height." ,
301
303
) ;
302
304
}
303
305
304
306
// Iterate through blocks in reverse order in chunks of 50
305
- while ( end > params . startHeight ) {
307
+ while ( end > startHeight ) {
306
308
start = end - 50 ;
307
- if ( start < params . startHeight ) {
308
- start = params . startHeight ;
309
+ if ( start < startHeight ) {
310
+ start = startHeight ;
309
311
}
310
312
try {
311
313
// Get 50 blocks (or the difference between the start and end if less than 50)
@@ -342,10 +344,10 @@ class AleoNetworkClient {
342
344
] ;
343
345
// Only search for unspent records in the specified programs.
344
346
if (
345
- ! ( typeof params . programs === "undefined" )
347
+ ! ( typeof programs === "undefined" )
346
348
) {
347
349
if (
348
- ! params . programs . includes (
350
+ ! programs . includes (
349
351
transition . program ,
350
352
)
351
353
) {
@@ -388,14 +390,14 @@ class AleoNetworkClient {
388
390
const nonce =
389
391
recordPlaintext . nonce ( ) ;
390
392
if (
391
- params . nonces . includes (
393
+ nonces . includes (
392
394
nonce ,
393
395
)
394
396
) {
395
397
continue ;
396
398
}
397
399
398
- if ( params . unspent ) {
400
+ if ( unspent ) {
399
401
const recordViewKey = recordPlaintext . recordViewKey ( viewKey ) . toString ( ) ;
400
402
401
403
// Otherwise record the nonce that has been found
@@ -423,13 +425,13 @@ class AleoNetworkClient {
423
425
}
424
426
425
427
// Add the record to the list of records if the user did not specify amounts.
426
- if ( ! params . amounts ) {
428
+ if ( ! amounts ) {
427
429
records . push (
428
430
recordPlaintext ,
429
431
) ;
430
432
// If the user specified a maximum number of microcredits, check if the search has found enough
431
433
if (
432
- typeof params . maxMicrocredits ===
434
+ typeof maxMicrocredits ===
433
435
"number"
434
436
) {
435
437
totalRecordValue +=
@@ -438,7 +440,7 @@ class AleoNetworkClient {
438
440
if (
439
441
totalRecordValue >=
440
442
BigInt (
441
- params . maxMicrocredits ,
443
+ maxMicrocredits ,
442
444
)
443
445
) {
444
446
return records ;
@@ -449,15 +451,15 @@ class AleoNetworkClient {
449
451
// If the user specified a list of amounts, check if the search has found them
450
452
if (
451
453
! (
452
- typeof params . amounts ===
454
+ typeof amounts ===
453
455
"undefined"
454
456
) &&
455
- params . amounts . length > 0
457
+ amounts . length > 0
456
458
) {
457
459
let amounts_found = 0 ;
458
460
if (
459
461
recordPlaintext . microcredits ( ) >
460
- params . amounts [
462
+ amounts [
461
463
amounts_found
462
464
]
463
465
) {
@@ -467,7 +469,7 @@ class AleoNetworkClient {
467
469
) ;
468
470
// If the user specified a maximum number of microcredits, check if the search has found enough
469
471
if (
470
- typeof params . maxMicrocredits ===
472
+ typeof maxMicrocredits ===
471
473
"number"
472
474
) {
473
475
totalRecordValue +=
@@ -476,15 +478,15 @@ class AleoNetworkClient {
476
478
if (
477
479
totalRecordValue >=
478
480
BigInt (
479
- params . maxMicrocredits ,
481
+ maxMicrocredits ,
480
482
)
481
483
) {
482
484
return records ;
483
485
}
484
486
}
485
487
if (
486
488
records . length >=
487
- params . amounts . length
489
+ amounts . length
488
490
) {
489
491
return records ;
490
492
}
@@ -1263,13 +1265,15 @@ class AleoNetworkClient {
1263
1265
mappingName : string ,
1264
1266
key : string | Plaintext ,
1265
1267
} ) : Promise < Plaintext > {
1268
+ const { programId, mappingName, key } = params ;
1269
+
1266
1270
this . ctx = { "X-ALEO-METHOD" : "getProgramMappingPlaintext" } ;
1267
1271
1268
1272
try {
1269
- const keyString = params . key instanceof Plaintext ? params . key . toString ( ) : params . key ;
1273
+ const keyString = key instanceof Plaintext ? key . toString ( ) : key ;
1270
1274
1271
1275
const value = await this . fetchRaw (
1272
- `/program/${ params . programId } /mapping/${ params . mappingName } /${ keyString } ` ,
1276
+ `/program/${ programId } /mapping/${ mappingName } /${ keyString } ` ,
1273
1277
) ;
1274
1278
1275
1279
return Plaintext . fromString ( JSON . parse ( value ) ) ;
@@ -1698,15 +1702,13 @@ class AleoNetworkClient {
1698
1702
* // Wait for the transaction to be confirmed.
1699
1703
* const transaction = await networkClient.waitForTransactionConfirmation({ transactionId });
1700
1704
*/
1701
- async waitForTransactionConfirmation ( {
1702
- transactionId,
1703
- checkInterval = 2000 ,
1704
- timeout = 45000 ,
1705
- } : {
1705
+ async waitForTransactionConfirmation ( params : {
1706
1706
transactionId : string ,
1707
1707
checkInterval ?: number ,
1708
1708
timeout ?: number ,
1709
1709
} ) : Promise < ConfirmedTransactionJSON > {
1710
+ const { transactionId, checkInterval = 2000 , timeout = 45000 } = params ;
1711
+
1710
1712
const startTime = Date . now ( ) ;
1711
1713
1712
1714
return new Promise ( ( resolve , reject ) => {
0 commit comments