@@ -1158,9 +1158,10 @@ class AleoNetworkClient {
1158
1158
/**
1159
1159
* Returns the value of a program's mapping for a specific key.
1160
1160
*
1161
- * @param {string } programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1162
- * @param {string } mappingName - The name of the mapping to get the value of (e.g. "account")
1163
- * @param {string | Plaintext } key - The key to look up in the mapping (e.g. an address for the "account" mapping)
1161
+ * @param {Object } params
1162
+ * @param {string } params.programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1163
+ * @param {string } params.mappingName - The name of the mapping to get the value of (e.g. "account")
1164
+ * @param {string | Plaintext } params.key - The key to look up in the mapping (e.g. an address for the "account" mapping)
1164
1165
* @returns {Promise<string> } String representation of the value of the mapping
1165
1166
*
1166
1167
* @example
@@ -1170,25 +1171,35 @@ class AleoNetworkClient {
1170
1171
* const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
1171
1172
*
1172
1173
* // Get public balance of an account
1173
- * const mappingValue = networkClient.getMappingValue("credits.aleo", "account", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
1174
+ * const mappingValue = networkClient.getProgramMappingValue({
1175
+ * programId: "credits.aleo",
1176
+ * mappingName: "account",
1177
+ * key: "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
1178
+ * });
1174
1179
* const expectedValue = "0u64";
1175
1180
* assert(mappingValue === expectedValue);
1176
1181
*/
1177
- async getProgramMappingValue (
1182
+ async getProgramMappingValue ( params : {
1178
1183
programId : string ,
1179
1184
mappingName : string ,
1180
1185
key : string | Plaintext ,
1181
- ) : Promise < string > {
1186
+ } ) : Promise < string > {
1187
+ const { programId, mappingName, key } = params ;
1188
+
1189
+ this . ctx = { "X-ALEO-METHOD" : "getProgramMappingValue" } ;
1190
+
1182
1191
try {
1183
- this . ctx = { "X-ALEO-METHOD" : "getProgramMappingValue" } ;
1184
1192
const keyString = key instanceof Plaintext ? key . toString ( ) : key ;
1193
+
1185
1194
return await this . fetchData < string > (
1186
1195
`/program/${ programId } /mapping/${ mappingName } /${ keyString } ` ,
1187
1196
) ;
1197
+
1188
1198
} catch ( error ) {
1189
1199
throw new Error (
1190
1200
`Error fetching value for key '${ key } ' in mapping '${ mappingName } ' in program '${ programId } ' - ensure the mapping exists and the key is correct: ${ error } ` ,
1191
1201
) ;
1202
+
1192
1203
} finally {
1193
1204
this . ctx = { } ;
1194
1205
}
@@ -1197,9 +1208,10 @@ class AleoNetworkClient {
1197
1208
/**
1198
1209
* 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.
1199
1210
*
1200
- * @param {string } programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1201
- * @param {string } mappingName - The name of the mapping to get the value of (e.g. "bonded")
1202
- * @param {string | Plaintext } key - The key to look up in the mapping (e.g. an address for the "bonded" mapping)
1211
+ * @param {Object } params
1212
+ * @param {string } params.programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1213
+ * @param {string } params.mappingName - The name of the mapping to get the value of (e.g. "bonded")
1214
+ * @param {string | Plaintext } params.key - The key to look up in the mapping (e.g. an address for the "bonded" mapping)
1203
1215
* @returns {Promise<Plaintext> } String representation of the value of the mapping
1204
1216
*
1205
1217
* @example
@@ -1209,7 +1221,11 @@ class AleoNetworkClient {
1209
1221
* const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
1210
1222
*
1211
1223
* // Get the bond state as an account.
1212
- * const unbondedState = networkClient.getMappingPlaintext("credits.aleo", "bonded", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
1224
+ * const unbondedState = networkClient.getProgramMappingPlaintext({
1225
+ * programId: "credits.aleo",
1226
+ * mappingName: "bonded",
1227
+ * key: "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
1228
+ * });
1213
1229
*
1214
1230
* // Get the two members of the object individually.
1215
1231
* const validator = unbondedState.getMember("validator");
@@ -1228,20 +1244,25 @@ class AleoNetworkClient {
1228
1244
* };
1229
1245
* assert.equal(unbondedState, expectedState);
1230
1246
*/
1231
- async getProgramMappingPlaintext (
1247
+ async getProgramMappingPlaintext ( params : {
1232
1248
programId : string ,
1233
1249
mappingName : string ,
1234
1250
key : string | Plaintext ,
1235
- ) : Promise < Plaintext > {
1251
+ } ) : Promise < Plaintext > {
1252
+ this . ctx = { "X-ALEO-METHOD" : "getProgramMappingPlaintext" } ;
1253
+
1236
1254
try {
1237
- this . ctx = { "X-ALEO-METHOD" : "getProgramMappingPlaintext" } ;
1238
- const keyString = key instanceof Plaintext ? key . toString ( ) : key ;
1255
+ const keyString = params . key instanceof Plaintext ? params . key . toString ( ) : params . key ;
1256
+
1239
1257
const value = await this . fetchRaw (
1240
- `/program/${ programId } /mapping/${ mappingName } /${ keyString } ` ,
1258
+ `/program/${ params . programId } /mapping/${ params . mappingName } /${ keyString } ` ,
1241
1259
) ;
1260
+
1242
1261
return Plaintext . fromString ( JSON . parse ( value ) ) ;
1262
+
1243
1263
} catch ( error ) {
1244
1264
throw new Error ( "Failed to fetch mapping value." + error ) ;
1265
+
1245
1266
} finally {
1246
1267
this . ctx = { } ;
1247
1268
}
@@ -1270,11 +1291,11 @@ class AleoNetworkClient {
1270
1291
this . ctx = { "X-ALEO-METHOD" : "getPublicBalance" } ;
1271
1292
const addressString =
1272
1293
address instanceof Address ? address . to_string ( ) : address ;
1273
- const balanceStr = await this . getProgramMappingValue (
1274
- "credits.aleo" ,
1275
- "account" ,
1276
- addressString ,
1277
- ) ;
1294
+ const balanceStr = await this . getProgramMappingValue ( {
1295
+ programId : "credits.aleo" ,
1296
+ mappingName : "account" ,
1297
+ key : addressString ,
1298
+ } ) ;
1278
1299
return balanceStr ? parseInt ( balanceStr ) : 0 ;
1279
1300
} catch ( error ) {
1280
1301
throw new Error (
@@ -1599,9 +1620,10 @@ class AleoNetworkClient {
1599
1620
/**
1600
1621
* Await a submitted transaction to be confirmed or rejected on the Aleo network.
1601
1622
*
1602
- * @param {string } transactionId - The transaction ID to wait for confirmation
1603
- * @param {number } checkInterval - The interval in milliseconds to check for confirmation (default: 2000)
1604
- * @param {number } timeout - The maximum time in milliseconds to wait for confirmation (default: 45000)
1623
+ * @param {Object } params
1624
+ * @param {string } params.transactionId - The transaction ID to wait for confirmation
1625
+ * @param {number } [params.checkInterval=2000] - The interval in milliseconds to check for confirmation (default: 2000)
1626
+ * @param {number } [params.timeout=45000] - The maximum time in milliseconds to wait for confirmation (default: 45000)
1605
1627
* @returns {Promise<Transaction> } The confirmed transaction object that returns if the transaction is confirmed.
1606
1628
*
1607
1629
* @example
@@ -1623,11 +1645,15 @@ class AleoNetworkClient {
1623
1645
* // Wait for the transaction to be confirmed.
1624
1646
* const transaction = await networkClient.waitForTransactionConfirmation(transactionId);
1625
1647
*/
1626
- async waitForTransactionConfirmation (
1648
+ async waitForTransactionConfirmation ( {
1649
+ transactionId,
1650
+ checkInterval = 2000 ,
1651
+ timeout = 45000 ,
1652
+ } : {
1627
1653
transactionId : string ,
1628
- checkInterval : number = 2000 ,
1629
- timeout : number = 45000 ,
1630
- ) : Promise < ConfirmedTransactionJSON > {
1654
+ checkInterval : number ,
1655
+ timeout : number ,
1656
+ } ) : Promise < ConfirmedTransactionJSON > {
1631
1657
const startTime = Date . now ( ) ;
1632
1658
1633
1659
return new Promise ( ( resolve , reject ) => {
0 commit comments