@@ -1057,9 +1057,10 @@ class AleoNetworkClient {
1057
1057
/**
1058
1058
* Returns the value of a program's mapping for a specific key.
1059
1059
*
1060
- * @param {string } programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1061
- * @param {string } mappingName - The name of the mapping to get the value of (e.g. "account")
1062
- * @param {string | Plaintext } key - The key to look up in the mapping (e.g. an address for the "account" mapping)
1060
+ * @param {Object } params
1061
+ * @param {string } params.programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1062
+ * @param {string } params.mappingName - The name of the mapping to get the value of (e.g. "account")
1063
+ * @param {string | Plaintext } params.key - The key to look up in the mapping (e.g. an address for the "account" mapping)
1063
1064
* @returns {Promise<string> } String representation of the value of the mapping
1064
1065
*
1065
1066
* @example
@@ -1069,33 +1070,38 @@ class AleoNetworkClient {
1069
1070
* const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
1070
1071
*
1071
1072
* // Get public balance of an account
1072
- * const mappingValue = networkClient.getMappingValue("credits.aleo", "account", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
1073
+ * const mappingValue = networkClient.getProgramMappingValue({
1074
+ * programId: "credits.aleo",
1075
+ * mappingName: "account",
1076
+ * key: "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
1077
+ * });
1073
1078
* const expectedValue = "0u64";
1074
1079
* assert(mappingValue === expectedValue);
1075
1080
*/
1076
- async getProgramMappingValue (
1081
+ async getProgramMappingValue ( params : {
1077
1082
programId : string ,
1078
1083
mappingName : string ,
1079
1084
key : string | Plaintext ,
1080
- ) : Promise < string > {
1085
+ } ) : Promise < string > {
1081
1086
try {
1082
- const keyString = key instanceof Plaintext ? key . toString ( ) : key ;
1087
+ const keyString = params . key instanceof Plaintext ? params . key . toString ( ) : params . key ;
1083
1088
return await this . fetchData < string > (
1084
- `/program/${ programId } /mapping/${ mappingName } /${ keyString } ` ,
1089
+ `/program/${ params . programId } /mapping/${ params . mappingName } /${ keyString } ` ,
1085
1090
) ;
1086
1091
} catch ( error ) {
1087
1092
throw new Error (
1088
- `Error fetching value for key '${ key } ' in mapping '${ mappingName } ' in program '${ programId } ' - ensure the mapping exists and the key is correct` ,
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` ,
1089
1094
) ;
1090
1095
}
1091
1096
}
1092
1097
1093
1098
/**
1094
1099
* 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.
1095
1100
*
1096
- * @param {string } programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1097
- * @param {string } mappingName - The name of the mapping to get the value of (e.g. "bonded")
1098
- * @param {string | Plaintext } key - The key to look up in the mapping (e.g. an address for the "bonded" mapping)
1101
+ * @param {Object } params
1102
+ * @param {string } params.programId - The program ID to get the mapping value of (e.g. "credits.aleo")
1103
+ * @param {string } params.mappingName - The name of the mapping to get the value of (e.g. "bonded")
1104
+ * @param {string | Plaintext } params.key - The key to look up in the mapping (e.g. an address for the "bonded" mapping)
1099
1105
* @returns {Promise<Plaintext> } String representation of the value of the mapping
1100
1106
*
1101
1107
* @example
@@ -1105,7 +1111,11 @@ class AleoNetworkClient {
1105
1111
* const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
1106
1112
*
1107
1113
* // Get the bond state as an account.
1108
- * const unbondedState = networkClient.getMappingPlaintext("credits.aleo", "bonded", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px");
1114
+ * const unbondedState = networkClient.getProgramMappingPlaintext({
1115
+ * programId: "credits.aleo",
1116
+ * mappingName: "bonded",
1117
+ * key: "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px",
1118
+ * });
1109
1119
*
1110
1120
* // Get the two members of the object individually.
1111
1121
* const validator = unbondedState.getMember("validator");
@@ -1124,15 +1134,15 @@ class AleoNetworkClient {
1124
1134
* };
1125
1135
* assert.equal(unbondedState, expectedState);
1126
1136
*/
1127
- async getProgramMappingPlaintext (
1137
+ async getProgramMappingPlaintext ( params : {
1128
1138
programId : string ,
1129
1139
mappingName : string ,
1130
1140
key : string | Plaintext ,
1131
- ) : Promise < Plaintext > {
1141
+ } ) : Promise < Plaintext > {
1132
1142
try {
1133
- const keyString = key instanceof Plaintext ? key . toString ( ) : key ;
1143
+ const keyString = params . key instanceof Plaintext ? params . key . toString ( ) : params . key ;
1134
1144
const value = await this . fetchRaw (
1135
- `/program/${ programId } /mapping/${ mappingName } /${ keyString } ` ,
1145
+ `/program/${ params . programId } /mapping/${ params . mappingName } /${ keyString } ` ,
1136
1146
) ;
1137
1147
return Plaintext . fromString ( JSON . parse ( value ) ) ;
1138
1148
} catch ( error ) {
@@ -1162,11 +1172,11 @@ class AleoNetworkClient {
1162
1172
try {
1163
1173
const addressString =
1164
1174
address instanceof Address ? address . to_string ( ) : address ;
1165
- const balanceStr = await this . getProgramMappingValue (
1166
- "credits.aleo" ,
1167
- "account" ,
1168
- addressString ,
1169
- ) ;
1175
+ const balanceStr = await this . getProgramMappingValue ( {
1176
+ programId : "credits.aleo" ,
1177
+ mappingName : "account" ,
1178
+ key : addressString ,
1179
+ } ) ;
1170
1180
return balanceStr ? parseInt ( balanceStr ) : 0 ;
1171
1181
} catch ( error ) {
1172
1182
throw new Error (
@@ -1464,9 +1474,10 @@ class AleoNetworkClient {
1464
1474
/**
1465
1475
* Await a submitted transaction to be confirmed or rejected on the Aleo network.
1466
1476
*
1467
- * @param {string } transactionId - The transaction ID to wait for confirmation
1468
- * @param {number } checkInterval - The interval in milliseconds to check for confirmation (default: 2000)
1469
- * @param {number } timeout - The maximum time in milliseconds to wait for confirmation (default: 45000)
1477
+ * @param {Object } params
1478
+ * @param {string } params.transactionId - The transaction ID to wait for confirmation
1479
+ * @param {number } [params.checkInterval=2000] - The interval in milliseconds to check for confirmation (default: 2000)
1480
+ * @param {number } [params.timeout=45000] - The maximum time in milliseconds to wait for confirmation (default: 45000)
1470
1481
* @returns {Promise<Transaction> } The confirmed transaction object that returns if the transaction is confirmed.
1471
1482
*
1472
1483
* @example
@@ -1488,11 +1499,15 @@ class AleoNetworkClient {
1488
1499
* // Wait for the transaction to be confirmed.
1489
1500
* const transaction = await networkClient.waitForTransactionConfirmation(transactionId);
1490
1501
*/
1491
- async waitForTransactionConfirmation (
1502
+ async waitForTransactionConfirmation ( {
1503
+ transactionId,
1504
+ checkInterval = 2000 ,
1505
+ timeout = 45000 ,
1506
+ } : {
1492
1507
transactionId : string ,
1493
- checkInterval : number = 2000 ,
1494
- timeout : number = 45000 ,
1495
- ) : Promise < ConfirmedTransactionJSON > {
1508
+ checkInterval : number ,
1509
+ timeout : number ,
1510
+ } ) : Promise < ConfirmedTransactionJSON > {
1496
1511
const startTime = Date . now ( ) ;
1497
1512
1498
1513
return new Promise ( ( resolve , reject ) => {
0 commit comments