@@ -102,15 +102,11 @@ class ProgramManager {
102
102
* Check if the fee is sufficient to pay for the transaction
103
103
*/
104
104
async checkFee ( address : string , feeAmount : bigint ) {
105
- const account_balance =
106
- await this . networkClient ?. getProgramMappingValue (
107
- "credits.aleo" ,
108
- "account" ,
109
- address ,
110
- ) ;
111
- if ( feeAmount > BigInt ( account_balance ) ) {
105
+ const balance =
106
+ BigInt ( await this . networkClient . getPublicBalance ( address ) ) ;
107
+ if ( feeAmount > balance ) {
112
108
throw Error (
113
- "Public balance is insufficient to execute the transacation." ,
109
+ `The desired execution requires a fee of ${ feeAmount } microcredits, but the account paying the fee has ${ balance } microcredits available.` ,
114
110
) ;
115
111
}
116
112
}
@@ -198,9 +194,18 @@ class ProgramManager {
198
194
feeRecord ?: string | RecordPlaintext ,
199
195
privateKey ?: PrivateKey ,
200
196
) : Promise < Transaction > {
197
+ // Ensure the program is valid.
198
+ let programObject ;
199
+ try {
200
+ programObject = Program . fromString ( program ) ;
201
+ } catch ( e : any ) {
202
+ logAndThrow (
203
+ `Error parsing program: '${ e . message } '. Please ensure the program is valid.` ,
204
+ ) ;
205
+ }
206
+
201
207
// Ensure the program is valid and does not exist on the network
202
208
try {
203
- const programObject = Program . fromString ( program ) ;
204
209
let programSource ;
205
210
try {
206
211
programSource = await this . networkClient . getProgram (
@@ -212,8 +217,8 @@ class ProgramManager {
212
217
`Program ${ programObject . id ( ) } does not exist on the network, deploying...` ,
213
218
) ;
214
219
}
215
- if ( typeof programSource == "string" ) {
216
- throw `Program ${ programObject . id ( ) } already exists on the network, please rename your program` ;
220
+ if ( typeof programSource === "string" ) {
221
+ throw Error ( `Program ${ programObject . id ( ) } already exists on the network, please rename your program` ) ;
217
222
}
218
223
} catch ( e : any ) {
219
224
logAndThrow ( `Error validating program: ${ e . message } ` ) ;
@@ -354,7 +359,7 @@ class ProgramManager {
354
359
}
355
360
356
361
// Check if the account has sufficient credits to pay for the transaction
357
- this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
362
+ await this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
358
363
359
364
return await this . networkClient . submitTransaction ( tx ) ;
360
365
}
@@ -572,7 +577,7 @@ class ProgramManager {
572
577
}
573
578
574
579
// Check if the account has sufficient credits to pay for the transaction
575
- this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
580
+ await this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
576
581
577
582
return await this . networkClient . submitTransaction ( tx ) ;
578
583
}
@@ -793,7 +798,7 @@ class ProgramManager {
793
798
) ;
794
799
795
800
// Check if the account has sufficient credits to pay for the transaction
796
- this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
801
+ await this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
797
802
798
803
return await this . networkClient . submitTransaction ( tx ) ;
799
804
}
@@ -1241,7 +1246,7 @@ class ProgramManager {
1241
1246
}
1242
1247
1243
1248
// Check if the account has sufficient credits to pay for the transaction
1244
- this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1249
+ await this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1245
1250
1246
1251
return await this . networkClient . submitTransaction ( tx ) ;
1247
1252
}
@@ -1376,7 +1381,7 @@ class ProgramManager {
1376
1381
}
1377
1382
1378
1383
// Check if the account has sufficient credits to pay for the transaction
1379
- this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1384
+ await this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1380
1385
1381
1386
return await this . networkClient . submitTransaction ( tx ) ;
1382
1387
}
@@ -1520,7 +1525,7 @@ class ProgramManager {
1520
1525
}
1521
1526
1522
1527
// Check if the account has sufficient credits to pay for the transaction
1523
- this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1528
+ await this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1524
1529
1525
1530
return await this . networkClient . submitTransaction ( tx ) ;
1526
1531
}
@@ -1649,7 +1654,7 @@ class ProgramManager {
1649
1654
}
1650
1655
1651
1656
// Check if the account has sufficient credits to pay for the transaction
1652
- this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1657
+ await this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1653
1658
1654
1659
return await this . networkClient . submitTransaction ( tx ) ;
1655
1660
}
@@ -1770,7 +1775,7 @@ class ProgramManager {
1770
1775
}
1771
1776
1772
1777
// Check if the account has sufficient credits to pay for the transaction
1773
- this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1778
+ await this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1774
1779
1775
1780
return await this . networkClient . submitTransaction ( tx ) ;
1776
1781
}
@@ -1903,7 +1908,7 @@ class ProgramManager {
1903
1908
}
1904
1909
1905
1910
// Check if the account has sufficient credits to pay for the transaction
1906
- this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1911
+ await this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1907
1912
1908
1913
return this . networkClient . submitTransaction ( tx ) ;
1909
1914
}
0 commit comments