@@ -1172,9 +1172,10 @@ class AleoNetworkClient {
1172
1172
/**
1173
1173
* Returns the value of a program's mapping for a specific key.
1174
1174
*
1175
- * @param {string } programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1176
- * @param {string } mappingName - The name of the mapping to get the value of (e.g. "account")
1177
- * @param {string | Plaintext } key - The key to look up in the mapping (e.g. an address for the "account" mapping)
1175
+ * @param {Object } params
1176
+ * @param {string } params.programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1177
+ * @param {string } params.mappingName - The name of the mapping to get the value of (e.g. "account")
1178
+ * @param {string | Plaintext } params.key - The key to look up in the mapping (e.g. an address for the "account" mapping)
1178
1179
* @returns {Promise<string> } String representation of the value of the mapping
1179
1180
*
1180
1181
* @example
@@ -1184,25 +1185,35 @@ class AleoNetworkClient {
1184
1185
* const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
1185
1186
*
1186
1187
* // Get public balance of an account
1187
- * const mappingValue = networkClient.getMappingValue("credits.aleo", "account", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
1188
+ * const mappingValue = networkClient.getProgramMappingValue({
1189
+ * programId: "credits.aleo",
1190
+ * mappingName: "account",
1191
+ * key: "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
1192
+ * });
1188
1193
* const expectedValue = "0u64";
1189
1194
* assert(mappingValue === expectedValue);
1190
1195
*/
1191
- async getProgramMappingValue (
1196
+ async getProgramMappingValue ( params : {
1192
1197
programId : string ,
1193
1198
mappingName : string ,
1194
1199
key : string | Plaintext ,
1195
- ) : Promise < string > {
1200
+ } ) : Promise < string > {
1201
+ const { programId, mappingName, key } = params ;
1202
+
1203
+ this . ctx = { "X-ALEO-METHOD" : "getProgramMappingValue" } ;
1204
+
1196
1205
try {
1197
- this . ctx = { "X-ALEO-METHOD" : "getProgramMappingValue" } ;
1198
1206
const keyString = key instanceof Plaintext ? key . toString ( ) : key ;
1207
+
1199
1208
return await this . fetchData < string > (
1200
1209
`/program/${ programId } /mapping/${ mappingName } /${ keyString } ` ,
1201
1210
) ;
1211
+
1202
1212
} catch ( error ) {
1203
1213
throw new Error (
1204
1214
`Error fetching value for key '${ key } ' in mapping '${ mappingName } ' in program '${ programId } ' - ensure the mapping exists and the key is correct: ${ error } ` ,
1205
1215
) ;
1216
+
1206
1217
} finally {
1207
1218
this . ctx = { } ;
1208
1219
}
@@ -1211,9 +1222,10 @@ class AleoNetworkClient {
1211
1222
/**
1212
1223
* 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.
1213
1224
*
1214
- * @param {string } programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1215
- * @param {string } mappingName - The name of the mapping to get the value of (e.g. "bonded")
1216
- * @param {string | Plaintext } key - The key to look up in the mapping (e.g. an address for the "bonded" mapping)
1225
+ * @param {Object } params
1226
+ * @param {string } params.programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1227
+ * @param {string } params.mappingName - The name of the mapping to get the value of (e.g. "bonded")
1228
+ * @param {string | Plaintext } params.key - The key to look up in the mapping (e.g. an address for the "bonded" mapping)
1217
1229
* @returns {Promise<Plaintext> } String representation of the value of the mapping
1218
1230
*
1219
1231
* @example
@@ -1223,7 +1235,11 @@ class AleoNetworkClient {
1223
1235
* const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
1224
1236
*
1225
1237
* // Get the bond state as an account.
1226
- * const unbondedState = networkClient.getMappingPlaintext("credits.aleo", "bonded", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
1238
+ * const unbondedState = networkClient.getProgramMappingPlaintext({
1239
+ * programId: "credits.aleo",
1240
+ * mappingName: "bonded",
1241
+ * key: "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
1242
+ * });
1227
1243
*
1228
1244
* // Get the two members of the object individually.
1229
1245
* const validator = unbondedState.getMember("validator");
@@ -1242,20 +1258,25 @@ class AleoNetworkClient {
1242
1258
* };
1243
1259
* assert.equal(unbondedState, expectedState);
1244
1260
*/
1245
- async getProgramMappingPlaintext (
1261
+ async getProgramMappingPlaintext ( params : {
1246
1262
programId : string ,
1247
1263
mappingName : string ,
1248
1264
key : string | Plaintext ,
1249
- ) : Promise < Plaintext > {
1265
+ } ) : Promise < Plaintext > {
1266
+ this . ctx = { "X-ALEO-METHOD" : "getProgramMappingPlaintext" } ;
1267
+
1250
1268
try {
1251
- this . ctx = { "X-ALEO-METHOD" : "getProgramMappingPlaintext" } ;
1252
- const keyString = key instanceof Plaintext ? key . toString ( ) : key ;
1269
+ const keyString = params . key instanceof Plaintext ? params . key . toString ( ) : params . key ;
1270
+
1253
1271
const value = await this . fetchRaw (
1254
- `/program/${ programId } /mapping/${ mappingName } /${ keyString } ` ,
1272
+ `/program/${ params . programId } /mapping/${ params . mappingName } /${ keyString } ` ,
1255
1273
) ;
1274
+
1256
1275
return Plaintext . fromString ( JSON . parse ( value ) ) ;
1276
+
1257
1277
} catch ( error ) {
1258
1278
throw new Error ( "Failed to fetch mapping value." + error ) ;
1279
+
1259
1280
} finally {
1260
1281
this . ctx = { } ;
1261
1282
}
@@ -1284,11 +1305,11 @@ class AleoNetworkClient {
1284
1305
this . ctx = { "X-ALEO-METHOD" : "getPublicBalance" } ;
1285
1306
const addressString =
1286
1307
address instanceof Address ? address . to_string ( ) : address ;
1287
- const balanceStr = await this . getProgramMappingValue (
1288
- "credits.aleo" ,
1289
- "account" ,
1290
- addressString ,
1291
- ) ;
1308
+ const balanceStr = await this . getProgramMappingValue ( {
1309
+ programId : "credits.aleo" ,
1310
+ mappingName : "account" ,
1311
+ key : addressString ,
1312
+ } ) ;
1292
1313
return balanceStr ? parseInt ( balanceStr ) : 0 ;
1293
1314
} catch ( error ) {
1294
1315
throw new Error (
@@ -1652,9 +1673,10 @@ class AleoNetworkClient {
1652
1673
/**
1653
1674
* Await a submitted transaction to be confirmed or rejected on the Aleo network.
1654
1675
*
1655
- * @param {string } transactionId - The transaction ID to wait for confirmation
1656
- * @param {number } checkInterval - The interval in milliseconds to check for confirmation (default: 2000)
1657
- * @param {number } timeout - The maximum time in milliseconds to wait for confirmation (default: 45000)
1676
+ * @param {Object } params
1677
+ * @param {string } params.transactionId - The transaction ID to wait for confirmation
1678
+ * @param {number } [params.checkInterval=2000] - The interval in milliseconds to check for confirmation (default: 2000)
1679
+ * @param {number } [params.timeout=45000] - The maximum time in milliseconds to wait for confirmation (default: 45000)
1658
1680
* @returns {Promise<Transaction> } The confirmed transaction object that returns if the transaction is confirmed.
1659
1681
*
1660
1682
* @example
@@ -1676,11 +1698,15 @@ class AleoNetworkClient {
1676
1698
* // Wait for the transaction to be confirmed.
1677
1699
* const transaction = await networkClient.waitForTransactionConfirmation(transactionId);
1678
1700
*/
1679
- async waitForTransactionConfirmation (
1701
+ async waitForTransactionConfirmation ( {
1702
+ transactionId,
1703
+ checkInterval = 2000 ,
1704
+ timeout = 45000 ,
1705
+ } : {
1680
1706
transactionId : string ,
1681
- checkInterval : number = 2000 ,
1682
- timeout : number = 45000 ,
1683
- ) : Promise < ConfirmedTransactionJSON > {
1707
+ checkInterval : number ,
1708
+ timeout : number ,
1709
+ } ) : Promise < ConfirmedTransactionJSON > {
1684
1710
const startTime = Date . now ( ) ;
1685
1711
1686
1712
return new Promise ( ( resolve , reject ) => {
0 commit comments