@@ -1190,9 +1190,10 @@ class AleoNetworkClient {
1190
1190
/**
1191
1191
* Returns the value of a program's mapping for a specific key.
1192
1192
*
1193
- * @param {string } programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1194
- * @param {string } mappingName - The name of the mapping to get the value of (e.g. "account")
1195
- * @param {string | Plaintext } key - The key to look up in the mapping (e.g. an address for the "account" mapping)
1193
+ * @param {Object } params
1194
+ * @param {string } params.programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1195
+ * @param {string } params.mappingName - The name of the mapping to get the value of (e.g. "account")
1196
+ * @param {string | Plaintext } params.key - The key to look up in the mapping (e.g. an address for the "account" mapping)
1196
1197
* @returns {Promise<string> } String representation of the value of the mapping
1197
1198
*
1198
1199
* @example
@@ -1202,25 +1203,35 @@ class AleoNetworkClient {
1202
1203
* const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
1203
1204
*
1204
1205
* // Get public balance of an account
1205
- * const mappingValue = networkClient.getMappingValue("credits.aleo", "account", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
1206
+ * const mappingValue = networkClient.getProgramMappingValue({
1207
+ * programId: "credits.aleo",
1208
+ * mappingName: "account",
1209
+ * key: "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
1210
+ * });
1206
1211
* const expectedValue = "0u64";
1207
1212
* assert(mappingValue === expectedValue);
1208
1213
*/
1209
- async getProgramMappingValue (
1214
+ async getProgramMappingValue ( params : {
1210
1215
programId : string ,
1211
1216
mappingName : string ,
1212
1217
key : string | Plaintext ,
1213
- ) : Promise < string > {
1218
+ } ) : Promise < string > {
1219
+ const { programId, mappingName, key } = params ;
1220
+
1221
+ this . ctx = { "X-ALEO-METHOD" : "getProgramMappingValue" } ;
1222
+
1214
1223
try {
1215
- this . ctx = { "X-ALEO-METHOD" : "getProgramMappingValue" } ;
1216
1224
const keyString = key instanceof Plaintext ? key . toString ( ) : key ;
1225
+
1217
1226
return await this . fetchData < string > (
1218
1227
`/program/${ programId } /mapping/${ mappingName } /${ keyString } ` ,
1219
1228
) ;
1229
+
1220
1230
} catch ( error ) {
1221
1231
throw new Error (
1222
1232
`Error fetching value for key '${ key } ' in mapping '${ mappingName } ' in program '${ programId } ' - ensure the mapping exists and the key is correct: ${ error } ` ,
1223
1233
) ;
1234
+
1224
1235
} finally {
1225
1236
this . ctx = { } ;
1226
1237
}
@@ -1229,9 +1240,10 @@ class AleoNetworkClient {
1229
1240
/**
1230
1241
* Returns the value of a mapping as a wasm Plaintext object. Returning an object in this format allows it to be converted to a Js type and for its internal members to be inspected if it's a struct or array.
1231
1242
*
1232
- * @param {string } programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1233
- * @param {string } mappingName - The name of the mapping to get the value of (e.g. "bonded")
1234
- * @param {string | Plaintext } key - The key to look up in the mapping (e.g. an address for the "bonded" mapping)
1243
+ * @param {Object } params
1244
+ * @param {string } params.programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1245
+ * @param {string } params.mappingName - The name of the mapping to get the value of (e.g. "bonded")
1246
+ * @param {string | Plaintext } params.key - The key to look up in the mapping (e.g. an address for the "bonded" mapping)
1235
1247
* @returns {Promise<Plaintext> } String representation of the value of the mapping
1236
1248
*
1237
1249
* @example
@@ -1241,7 +1253,11 @@ class AleoNetworkClient {
1241
1253
* const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
1242
1254
*
1243
1255
* // Get the bond state as an account.
1244
- * const unbondedState = networkClient.getMappingPlaintext("credits.aleo", "bonded", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
1256
+ * const unbondedState = networkClient.getProgramMappingPlaintext({
1257
+ * programId: "credits.aleo",
1258
+ * mappingName: "bonded",
1259
+ * key: "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
1260
+ * });
1245
1261
*
1246
1262
* // Get the two members of the object individually.
1247
1263
* const validator = unbondedState.getMember("validator");
@@ -1260,20 +1276,25 @@ class AleoNetworkClient {
1260
1276
* };
1261
1277
* assert.equal(unbondedState, expectedState);
1262
1278
*/
1263
- async getProgramMappingPlaintext (
1279
+ async getProgramMappingPlaintext ( params : {
1264
1280
programId : string ,
1265
1281
mappingName : string ,
1266
1282
key : string | Plaintext ,
1267
- ) : Promise < Plaintext > {
1283
+ } ) : Promise < Plaintext > {
1284
+ this . ctx = { "X-ALEO-METHOD" : "getProgramMappingPlaintext" } ;
1285
+
1268
1286
try {
1269
- this . ctx = { "X-ALEO-METHOD" : "getProgramMappingPlaintext" } ;
1270
- const keyString = key instanceof Plaintext ? key . toString ( ) : key ;
1287
+ const keyString = params . key instanceof Plaintext ? params . key . toString ( ) : params . key ;
1288
+
1271
1289
const value = await this . fetchRaw (
1272
- `/program/${ programId } /mapping/${ mappingName } /${ keyString } ` ,
1290
+ `/program/${ params . programId } /mapping/${ params . mappingName } /${ keyString } ` ,
1273
1291
) ;
1292
+
1274
1293
return Plaintext . fromString ( JSON . parse ( value ) ) ;
1294
+
1275
1295
} catch ( error ) {
1276
1296
throw new Error ( "Failed to fetch mapping value." + error ) ;
1297
+
1277
1298
} finally {
1278
1299
this . ctx = { } ;
1279
1300
}
@@ -1302,11 +1323,11 @@ class AleoNetworkClient {
1302
1323
this . ctx = { "X-ALEO-METHOD" : "getPublicBalance" } ;
1303
1324
const addressString =
1304
1325
address instanceof Address ? address . to_string ( ) : address ;
1305
- const balanceStr = await this . getProgramMappingValue (
1306
- "credits.aleo" ,
1307
- "account" ,
1308
- addressString ,
1309
- ) ;
1326
+ const balanceStr = await this . getProgramMappingValue ( {
1327
+ programId : "credits.aleo" ,
1328
+ mappingName : "account" ,
1329
+ key : addressString ,
1330
+ } ) ;
1310
1331
return balanceStr ? parseInt ( balanceStr ) : 0 ;
1311
1332
} catch ( error ) {
1312
1333
throw new Error (
@@ -1671,9 +1692,10 @@ class AleoNetworkClient {
1671
1692
/**
1672
1693
* Await a submitted transaction to be confirmed or rejected on the Aleo network.
1673
1694
*
1674
- * @param {string } transactionId - The transaction ID to wait for confirmation
1675
- * @param {number } checkInterval - The interval in milliseconds to check for confirmation (default: 2000)
1676
- * @param {number } timeout - The maximum time in milliseconds to wait for confirmation (default: 45000)
1695
+ * @param {Object } params
1696
+ * @param {string } params.transactionId - The transaction ID to wait for confirmation
1697
+ * @param {number } [params.checkInterval=2000] - The interval in milliseconds to check for confirmation (default: 2000)
1698
+ * @param {number } [params.timeout=45000] - The maximum time in milliseconds to wait for confirmation (default: 45000)
1677
1699
* @returns {Promise<Transaction> } The confirmed transaction object that returns if the transaction is confirmed.
1678
1700
*
1679
1701
* @example
@@ -1695,11 +1717,15 @@ class AleoNetworkClient {
1695
1717
* // Wait for the transaction to be confirmed.
1696
1718
* const transaction = await networkClient.waitForTransactionConfirmation(transactionId);
1697
1719
*/
1698
- async waitForTransactionConfirmation (
1720
+ async waitForTransactionConfirmation ( {
1721
+ transactionId,
1722
+ checkInterval = 2000 ,
1723
+ timeout = 45000 ,
1724
+ } : {
1699
1725
transactionId : string ,
1700
- checkInterval : number = 2000 ,
1701
- timeout : number = 45000 ,
1702
- ) : Promise < ConfirmedTransactionJSON > {
1726
+ checkInterval : number ,
1727
+ timeout : number ,
1728
+ } ) : Promise < ConfirmedTransactionJSON > {
1703
1729
const startTime = Date . now ( ) ;
1704
1730
1705
1731
return new Promise ( ( resolve , reject ) => {
0 commit comments