@@ -96,16 +96,16 @@ class AleoNetworkClient {
96
96
97
97
/**
98
98
* Set a header in the `AleoNetworkClient`s header map
99
- *
99
+ *
100
100
* @param {string } headerName The name of the header to set
101
101
* @param {string } value The header value
102
- *
102
+ *
103
103
* @example
104
104
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
105
- *
105
+ *
106
106
* // Create a networkClient
107
107
* const networkClient = new AleoNetworkClient();
108
- *
108
+ *
109
109
* // Set the value of the `Accept-Language` header to `en-US`
110
110
* networkClient.setHeader('Accept-Language', 'en-US');
111
111
*/
@@ -115,20 +115,20 @@ class AleoNetworkClient {
115
115
116
116
/**
117
117
* Remove a header from the `AleoNetworkClient`s header map
118
- *
118
+ *
119
119
* @param {string } headerName The name of the header to be removed
120
- *
120
+ *
121
121
* @example
122
122
* import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
123
- *
123
+ *
124
124
* // Create a networkClient
125
125
* const networkClient = new AleoNetworkClient();
126
- *
126
+ *
127
127
* // Remove the default `X-Aleo-SDK-Version` header
128
128
* networkClient.removeHeader('X-Aleo-SDK-Version');
129
129
*/
130
130
removeHeader ( headerName : string ) {
131
- delete this . headers [ headerName ]
131
+ delete this . headers [ headerName ] ;
132
132
}
133
133
134
134
/**
@@ -137,12 +137,12 @@ class AleoNetworkClient {
137
137
* @param url The URL to fetch data from.
138
138
*/
139
139
async fetchData < Type > ( url = "/" ) : Promise < Type > {
140
- try {
141
- const raw = await retryWithBackoff ( ( ) => this . fetchRaw ( url ) ) ;
142
- return parseJSON ( raw ) ;
143
- } catch ( error ) {
144
- throw new Error ( `Error fetching data: ${ error } ` ) ;
145
- }
140
+ try {
141
+ const raw = await this . fetchRaw ( url ) ;
142
+ return parseJSON ( raw ) ;
143
+ } catch ( error ) {
144
+ throw new Error ( `Error fetching data: ${ error } ` ) ;
145
+ }
146
146
}
147
147
148
148
/**
@@ -154,23 +154,17 @@ class AleoNetworkClient {
154
154
* @param url
155
155
*/
156
156
async fetchRaw ( url = "/" ) : Promise < string > {
157
- try {
158
- return await retryWithBackoff ( async ( ) => {
159
- const response = await get ( this . host + url , {
160
- headers : this . headers ,
157
+ try {
158
+ return await retryWithBackoff ( async ( ) => {
159
+ const response = await get ( this . host + url , {
160
+ headers : this . headers ,
161
+ } ) ;
162
+ return await response . text ( ) ;
161
163
} ) ;
162
- return await response . text ( ) ;
163
- } , {
164
- shouldRetry : ( err ) => {
165
- const msg = err ?. message ?. toLowerCase ?.( ) || "" ;
166
- return msg . includes ( "network" ) || msg . includes ( "timeout" ) ;
167
- }
168
- } ) ;
169
- } catch ( error ) {
170
- throw new Error ( `Error fetching data: ${ error } ` ) ;
171
- }
172
- }
173
-
164
+ } catch ( error ) {
165
+ throw new Error ( `Error fetching data: ${ error } ` ) ;
166
+ }
167
+ }
174
168
175
169
/**
176
170
* Wrapper around the POST helper to allow mocking in tests. Not meant for use in production.
@@ -179,9 +173,9 @@ class AleoNetworkClient {
179
173
* @param options The RequestInit options for the POST request.
180
174
* @returns The Response object from the POST request.
181
175
*/
182
- private async sendPost ( url : string , options : RequestInit ) {
183
- return post ( url , options ) ;
184
- }
176
+ private async _sendPost ( url : string , options : RequestInit ) {
177
+ return post ( url , options ) ;
178
+ }
185
179
186
180
/**
187
181
* Attempt to find records in the Aleo blockchain.
@@ -384,27 +378,28 @@ class AleoNetworkClient {
384
378
}
385
379
386
380
if ( unspent ) {
387
- // Otherwise record the nonce that has been found
388
- const serialNumber = recordPlaintext . serialNumberString (
389
- resolvedPrivateKey ,
390
- "credits.aleo" ,
391
- "credits" ,
392
- ) ;
393
- // Attempt to see if the serial number is spent
394
- try {
395
- await retryWithBackoff ( ( ) => this . getTransitionId ( serialNumber ) , {
396
- retryOnStatus : [ 500 , 502 , 503 , 504 ] ,
397
- shouldRetry : ( err ) => {
398
- const msg = err ?. message ?. toLowerCase ?.( ) || "" ;
399
- return msg . includes ( "timeout" ) || msg . includes ( "503" ) || msg . includes ( "network" ) ;
400
- }
401
- } ) ;
402
- // If it succeeds, it means the record was spent → skip it
403
- continue ;
404
- } catch ( error ) {
405
- console . log ( "Found unspent record!" ) ;
406
- }
407
- }
381
+ // Otherwise record the nonce that has been found
382
+ const serialNumber =
383
+ recordPlaintext . serialNumberString (
384
+ resolvedPrivateKey ,
385
+ "credits.aleo" ,
386
+ "credits" ,
387
+ ) ;
388
+ // Attempt to see if the serial number is spent
389
+ try {
390
+ await retryWithBackoff (
391
+ ( ) =>
392
+ this . getTransitionId (
393
+ serialNumber ,
394
+ ) ,
395
+ ) ;
396
+ continue ;
397
+ } catch ( error ) {
398
+ console . log (
399
+ "Found unspent record!" ,
400
+ ) ;
401
+ }
402
+ }
408
403
409
404
// Add the record to the list of records if the user did not specify amounts.
410
405
if ( ! amounts ) {
@@ -1406,13 +1401,14 @@ class AleoNetworkClient {
1406
1401
? transaction . toString ( )
1407
1402
: transaction ;
1408
1403
try {
1409
- const response = await retryWithBackoff ( ( ) =>
1410
- this . sendPost ( this . host + "/transaction/broadcast" , {
1411
- body : transaction_string ,
1412
- headers : Object . assign ( { } , this . headers , {
1413
- "Content-Type" : "application/json" ,
1414
- } ) ,
1415
- } ) ) ;
1404
+ const response = await retryWithBackoff ( ( ) =>
1405
+ this . _sendPost ( this . host + "/transaction/broadcast" , {
1406
+ body : transaction_string ,
1407
+ headers : Object . assign ( { } , this . headers , {
1408
+ "Content-Type" : "application/json" ,
1409
+ } ) ,
1410
+ } ) ,
1411
+ ) ;
1416
1412
1417
1413
try {
1418
1414
const text = await response . text ( ) ;
@@ -1436,30 +1432,30 @@ class AleoNetworkClient {
1436
1432
* @returns {Promise<string> } The solution id of the submitted solution or the resulting error.
1437
1433
*/
1438
1434
async submitSolution ( solution : string ) : Promise < string > {
1439
- try {
1440
- const response = await retryWithBackoff ( ( ) =>
1441
- post ( this . host + "/solution/broadcast" , {
1442
- body : solution ,
1443
- headers : Object . assign ( { } , this . headers , {
1444
- "Content-Type" : "application/json" ,
1445
- } ) ,
1446
- } ) ,
1447
- ) ;
1448
-
1449
- try {
1450
- const text = await response . text ( ) ;
1451
- return parseJSON ( text ) ;
1452
- } catch ( error : any ) {
1453
- throw new Error (
1454
- `Error posting solution. Aleo network response: ${ error . message } ` ,
1455
- ) ;
1456
- }
1457
- } catch ( error : any ) {
1458
- throw new Error (
1459
- `Error posting solution: No response received: ${ error . message } ` ,
1460
- ) ;
1461
- }
1462
- }
1435
+ try {
1436
+ const response = await retryWithBackoff ( ( ) =>
1437
+ post ( this . host + "/solution/broadcast" , {
1438
+ body : solution ,
1439
+ headers : Object . assign ( { } , this . headers , {
1440
+ "Content-Type" : "application/json" ,
1441
+ } ) ,
1442
+ } ) ,
1443
+ ) ;
1444
+
1445
+ try {
1446
+ const text = await response . text ( ) ;
1447
+ return parseJSON ( text ) ;
1448
+ } catch ( error : any ) {
1449
+ throw new Error (
1450
+ `Error posting solution. Aleo network response: ${ error . message } ` ,
1451
+ ) ;
1452
+ }
1453
+ } catch ( error : any ) {
1454
+ throw new Error (
1455
+ `Error posting solution: No response received: ${ error . message } ` ,
1456
+ ) ;
1457
+ }
1458
+ }
1463
1459
/**
1464
1460
* Await a submitted transaction to be confirmed or rejected on the Aleo network.
1465
1461
*
0 commit comments