@@ -222,16 +222,18 @@ class AleoNetworkClient {
222
222
nonces ?: string [ ] ,
223
223
privateKey ?: string | PrivateKey ,
224
224
} ) : Promise < Array < RecordPlaintext > > {
225
- if ( params . unspent == null ) {
226
- params . unspent = false ;
225
+ let { startHeight, endHeight, unspent, programs, amounts, maxMicrocredits, nonces, privateKey } = params ;
226
+
227
+ if ( unspent == null ) {
228
+ unspent = false ;
227
229
}
228
230
229
- if ( params . nonces == null ) {
230
- params . nonces = [ ] ;
231
+ if ( nonces == null ) {
232
+ nonces = [ ] ;
231
233
}
232
234
233
235
// Ensure start height is not negative
234
- if ( params . startHeight < 0 ) {
236
+ if ( startHeight < 0 ) {
235
237
throw new Error ( "Start height must be greater than or equal to 0" ) ;
236
238
}
237
239
@@ -245,7 +247,7 @@ class AleoNetworkClient {
245
247
let latestHeight : number ;
246
248
247
249
// Ensure a private key is present to find owned records
248
- if ( typeof params . privateKey === "undefined" ) {
250
+ if ( typeof privateKey === "undefined" ) {
249
251
if ( typeof this . account === "undefined" ) {
250
252
throw new Error (
251
253
"Private key must be specified in an argument to findOwnedRecords or set in the AleoNetworkClient" ,
@@ -256,9 +258,9 @@ class AleoNetworkClient {
256
258
} else {
257
259
try {
258
260
resolvedPrivateKey =
259
- params . privateKey instanceof PrivateKey
260
- ? params . privateKey
261
- : PrivateKey . from_string ( params . privateKey ) ;
261
+ privateKey instanceof PrivateKey
262
+ ? privateKey
263
+ : PrivateKey . from_string ( privateKey ) ;
262
264
} catch ( error ) {
263
265
throw new Error ( "Error parsing private key provided." ) ;
264
266
}
@@ -280,24 +282,24 @@ class AleoNetworkClient {
280
282
}
281
283
282
284
// If no end height is specified or is greater than the latest height, set the end height to the latest height
283
- if ( typeof params . endHeight === "number" && params . endHeight <= latestHeight ) {
284
- end = params . endHeight ;
285
+ if ( typeof endHeight === "number" && endHeight <= latestHeight ) {
286
+ end = endHeight ;
285
287
} else {
286
288
end = latestHeight ;
287
289
}
288
290
289
291
// If the starting is greater than the ending height, return an error
290
- if ( params . startHeight > end ) {
292
+ if ( startHeight > end ) {
291
293
throw new Error (
292
294
"Start height must be less than or equal to end height." ,
293
295
) ;
294
296
}
295
297
296
298
// Iterate through blocks in reverse order in chunks of 50
297
- while ( end > params . startHeight ) {
299
+ while ( end > startHeight ) {
298
300
start = end - 50 ;
299
- if ( start < params . startHeight ) {
300
- start = params . startHeight ;
301
+ if ( start < startHeight ) {
302
+ start = startHeight ;
301
303
}
302
304
try {
303
305
// Get 50 blocks (or the difference between the start and end if less than 50)
@@ -334,10 +336,10 @@ class AleoNetworkClient {
334
336
] ;
335
337
// Only search for unspent records in the specified programs.
336
338
if (
337
- ! ( typeof params . programs === "undefined" )
339
+ ! ( typeof programs === "undefined" )
338
340
) {
339
341
if (
340
- ! params . programs . includes (
342
+ ! programs . includes (
341
343
transition . program ,
342
344
)
343
345
) {
@@ -380,14 +382,14 @@ class AleoNetworkClient {
380
382
const nonce =
381
383
recordPlaintext . nonce ( ) ;
382
384
if (
383
- params . nonces . includes (
385
+ nonces . includes (
384
386
nonce ,
385
387
)
386
388
) {
387
389
continue ;
388
390
}
389
391
390
- if ( params . unspent ) {
392
+ if ( unspent ) {
391
393
// Otherwise record the nonce that has been found
392
394
const serialNumber =
393
395
recordPlaintext . serialNumberString (
@@ -412,13 +414,13 @@ class AleoNetworkClient {
412
414
}
413
415
414
416
// Add the record to the list of records if the user did not specify amounts.
415
- if ( ! params . amounts ) {
417
+ if ( ! amounts ) {
416
418
records . push (
417
419
recordPlaintext ,
418
420
) ;
419
421
// If the user specified a maximum number of microcredits, check if the search has found enough
420
422
if (
421
- typeof params . maxMicrocredits ===
423
+ typeof maxMicrocredits ===
422
424
"number"
423
425
) {
424
426
totalRecordValue +=
@@ -427,7 +429,7 @@ class AleoNetworkClient {
427
429
if (
428
430
totalRecordValue >=
429
431
BigInt (
430
- params . maxMicrocredits ,
432
+ maxMicrocredits ,
431
433
)
432
434
) {
433
435
return records ;
@@ -438,16 +440,16 @@ class AleoNetworkClient {
438
440
// If the user specified a list of amounts, check if the search has found them
439
441
if (
440
442
! (
441
- typeof params . amounts ===
443
+ typeof amounts ===
442
444
"undefined"
443
445
) &&
444
- params . amounts . length >
446
+ amounts . length >
445
447
0
446
448
) {
447
449
let amounts_found = 0 ;
448
450
if (
449
451
recordPlaintext . microcredits ( ) >
450
- params . amounts [
452
+ amounts [
451
453
amounts_found
452
454
]
453
455
) {
@@ -457,7 +459,7 @@ class AleoNetworkClient {
457
459
) ;
458
460
// If the user specified a maximum number of microcredits, check if the search has found enough
459
461
if (
460
- typeof params . maxMicrocredits ===
462
+ typeof maxMicrocredits ===
461
463
"number"
462
464
) {
463
465
totalRecordValue +=
@@ -466,15 +468,15 @@ class AleoNetworkClient {
466
468
if (
467
469
totalRecordValue >=
468
470
BigInt (
469
- params . maxMicrocredits ,
471
+ maxMicrocredits ,
470
472
)
471
473
) {
472
474
return records ;
473
475
}
474
476
}
475
477
if (
476
478
records . length >=
477
- params . amounts . length
479
+ amounts . length
478
480
) {
479
481
return records ;
480
482
}
@@ -1083,14 +1085,16 @@ class AleoNetworkClient {
1083
1085
mappingName : string ,
1084
1086
key : string | Plaintext ,
1085
1087
} ) : Promise < string > {
1088
+ const { programId, mappingName, key } = params ;
1089
+
1086
1090
try {
1087
- const keyString = params . key instanceof Plaintext ? params . key . toString ( ) : params . key ;
1091
+ const keyString = key instanceof Plaintext ? key . toString ( ) : key ;
1088
1092
return await this . fetchData < string > (
1089
- `/program/${ params . programId } /mapping/${ params . mappingName } /${ keyString } ` ,
1093
+ `/program/${ programId } /mapping/${ mappingName } /${ keyString } ` ,
1090
1094
) ;
1091
1095
} catch ( error ) {
1092
1096
throw new Error (
1093
- `Error fetching value for key '${ params . key } ' in mapping '${ params . mappingName } ' in program '${ params . programId } ' - ensure the mapping exists and the key is correct` ,
1097
+ `Error fetching value for key '${ key } ' in mapping '${ mappingName } ' in program '${ programId } ' - ensure the mapping exists and the key is correct` ,
1094
1098
) ;
1095
1099
}
1096
1100
}
@@ -1139,10 +1143,12 @@ class AleoNetworkClient {
1139
1143
mappingName : string ,
1140
1144
key : string | Plaintext ,
1141
1145
} ) : Promise < Plaintext > {
1146
+ const { programId, mappingName, key } = params ;
1147
+
1142
1148
try {
1143
- const keyString = params . key instanceof Plaintext ? params . key . toString ( ) : params . key ;
1149
+ const keyString = key instanceof Plaintext ? key . toString ( ) : key ;
1144
1150
const value = await this . fetchRaw (
1145
- `/program/${ params . programId } /mapping/${ params . mappingName } /${ keyString } ` ,
1151
+ `/program/${ programId } /mapping/${ mappingName } /${ keyString } ` ,
1146
1152
) ;
1147
1153
return Plaintext . fromString ( JSON . parse ( value ) ) ;
1148
1154
} catch ( error ) {
@@ -1499,15 +1505,13 @@ class AleoNetworkClient {
1499
1505
* // Wait for the transaction to be confirmed.
1500
1506
* const transaction = await networkClient.waitForTransactionConfirmation({ transactionId });
1501
1507
*/
1502
- async waitForTransactionConfirmation ( {
1503
- transactionId,
1504
- checkInterval = 2000 ,
1505
- timeout = 45000 ,
1506
- } : {
1508
+ async waitForTransactionConfirmation ( params : {
1507
1509
transactionId : string ,
1508
1510
checkInterval ?: number ,
1509
1511
timeout ?: number ,
1510
1512
} ) : Promise < ConfirmedTransactionJSON > {
1513
+ const { transactionId, checkInterval = 2000 , timeout = 45000 } = params ;
1514
+
1511
1515
const startTime = Date . now ( ) ;
1512
1516
1513
1517
return new Promise ( ( resolve , reject ) => {
0 commit comments