@@ -98,6 +98,23 @@ class ProgramManager {
98
98
this . recordProvider = recordProvider ;
99
99
}
100
100
101
+ /**
102
+ * Check if the fee is sufficient to pay for the transaction
103
+ */
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 ) ) {
112
+ throw Error (
113
+ "Public balance is insufficient to execute the transacation." ,
114
+ ) ;
115
+ }
116
+ }
117
+
101
118
/**
102
119
* Set the account to use for transaction submission to the Aleo network
103
120
*
@@ -327,23 +344,17 @@ class ProgramManager {
327
344
let feeAddress ;
328
345
329
346
if ( typeof privateKey !== "undefined" ) {
330
- feeAddress = Address . fromPrivateKey ( privateKey ) ;
331
- } else {
347
+ feeAddress = Address . from_private_key ( privateKey ) ;
348
+ } else if ( this . account !== undefined ) {
332
349
feeAddress = this . account ?. address ( ) ;
333
- }
334
-
335
- const account_balance =
336
- await this . networkClient ?. getProgramMappingValue (
337
- "credits.aleo" ,
338
- "account" ,
339
- feeAddress ,
350
+ } else {
351
+ throw Error (
352
+ "No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key." ,
340
353
) ;
341
-
342
- // Check to make sure the public balance is sufficient to cover the execution fee.
343
- if ( tx . feeAmount ( ) > account_balance ) {
344
- throw "Public balance is insufficient to execute the transacation." ;
345
354
}
346
355
356
+ this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
357
+
347
358
return await this . networkClient . submitTransaction ( tx ) ;
348
359
}
349
360
@@ -547,30 +558,16 @@ class ProgramManager {
547
558
async execute ( options : ExecuteOptions ) : Promise < string > {
548
559
const tx = < Transaction > await this . buildExecutionTransaction ( options ) ;
549
560
550
- let feeAddress = this . account ?. address ( ) ;
551
- const account_balance =
552
- await this . networkClient ?. getProgramMappingValue (
553
- "credits.aleo" ,
554
- "account" ,
555
- feeAddress ,
561
+ let feeAddress ;
562
+ if ( this . account !== undefined ) {
563
+ feeAddress = this . account ?. address ( ) ;
564
+ } else {
565
+ throw Error (
566
+ "No account set in the ProgramManager. Please set an account before executing a transaction." ,
556
567
) ;
557
-
558
- // Check to make sure the public balance is sufficient to cover the execution fee.
559
- if ( tx . feeAmount ( ) > account_balance ) {
560
- throw "Public balance is insufficient to execute the transacation." ;
561
568
}
562
569
563
- // Check to make sure the public balance is sufficient to cover the execution fee.
564
- if (
565
- tx . feeAmount ( ) >
566
- this . networkClient ?. getProgramMappingValue (
567
- "credits.aleo" ,
568
- "account" ,
569
- this . account ?. address ( ) ,
570
- )
571
- ) {
572
- throw "Public balance is insufficient to execute the transacation." ;
573
- }
570
+ this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
574
571
575
572
return await this . networkClient . submitTransaction ( tx ) ;
576
573
}
@@ -789,23 +786,17 @@ class ProgramManager {
789
786
let feeAddress ;
790
787
791
788
if ( typeof privateKey !== "undefined" ) {
792
- feeAddress = Address . fromPrivateKey ( privateKey ) ;
793
- } else {
789
+ feeAddress = Address . from_private_key ( privateKey ) ;
790
+ } else if ( this . account !== undefined ) {
794
791
feeAddress = this . account ?. address ( ) ;
795
- }
796
-
797
- const account_balance =
798
- await this . networkClient ?. getProgramMappingValue (
799
- "credits.aleo" ,
800
- "account" ,
801
- feeAddress ,
792
+ } else {
793
+ throw Error (
794
+ "No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key." ,
802
795
) ;
803
-
804
- // Check to make sure the public balance is sufficient to cover the execution fee.
805
- if ( tx . feeAmount ( ) > account_balance ) {
806
- throw "Public balance is insufficient to execute the transacation." ;
807
796
}
808
797
798
+ this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
799
+
809
800
return await this . networkClient . submitTransaction ( tx ) ;
810
801
}
811
802
@@ -894,23 +885,17 @@ class ProgramManager {
894
885
let feeAddress ;
895
886
896
887
if ( typeof privateKey !== "undefined" ) {
897
- feeAddress = Address . fromPrivateKey ( privateKey ) ;
898
- } else {
888
+ feeAddress = Address . from_private_key ( privateKey ) ;
889
+ } else if ( this . account !== undefined ) {
899
890
feeAddress = this . account ?. address ( ) ;
900
- }
901
-
902
- const account_balance =
903
- await this . networkClient ?. getProgramMappingValue (
904
- "credits.aleo" ,
905
- "account" ,
906
- feeAddress ,
891
+ } else {
892
+ throw Error (
893
+ "No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key." ,
907
894
) ;
908
-
909
- // Check to make sure the public balance is sufficient to cover the execution fee.
910
- if ( tx . feeAmount ( ) > account_balance ) {
911
- throw "Public balance is insufficient to execute the transacation." ;
912
895
}
913
896
897
+ this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
898
+
914
899
return await this . networkClient . submitTransaction ( tx ) ;
915
900
}
916
901
@@ -1273,23 +1258,17 @@ class ProgramManager {
1273
1258
let feeAddress ;
1274
1259
1275
1260
if ( typeof privateKey !== "undefined" ) {
1276
- feeAddress = Address . fromPrivateKey ( privateKey ) ;
1277
- } else {
1261
+ feeAddress = Address . from_private_key ( privateKey ) ;
1262
+ } else if ( this . account !== undefined ) {
1278
1263
feeAddress = this . account ?. address ( ) ;
1279
- }
1280
-
1281
- const account_balance =
1282
- await this . networkClient ?. getProgramMappingValue (
1283
- "credits.aleo" ,
1284
- "account" ,
1285
- feeAddress ,
1264
+ } else {
1265
+ throw Error (
1266
+ "No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key." ,
1286
1267
) ;
1287
-
1288
- // Check to make sure the public balance is sufficient to cover the execution fee.
1289
- if ( tx . feeAmount ( ) > account_balance ) {
1290
- throw "Public balance is insufficient to execute the transacation." ;
1291
1268
}
1292
1269
1270
+ this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1271
+
1293
1272
return await this . networkClient . submitTransaction ( tx ) ;
1294
1273
}
1295
1274
@@ -1410,19 +1389,17 @@ class ProgramManager {
1410
1389
)
1411
1390
) ;
1412
1391
1413
- let feeAddress = this . account ?. address ( ) ;
1414
- const account_balance =
1415
- await this . networkClient ?. getProgramMappingValue (
1416
- "credits.aleo" ,
1417
- "account" ,
1418
- feeAddress ,
1392
+ let feeAddress ;
1393
+ if ( this . account !== undefined ) {
1394
+ feeAddress = this . account ?. address ( ) ;
1395
+ } else {
1396
+ throw Error (
1397
+ "No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key." ,
1419
1398
) ;
1420
-
1421
- // Check to make sure the public balance is sufficient to cover the execution fee.
1422
- if ( tx . feeAmount ( ) > account_balance ) {
1423
- throw "Public balance is insufficient to execute the transacation." ;
1424
1399
}
1425
1400
1401
+ this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1402
+
1426
1403
return await this . networkClient . submitTransaction ( tx ) ;
1427
1404
}
1428
1405
@@ -1552,19 +1529,18 @@ class ProgramManager {
1552
1529
)
1553
1530
) ;
1554
1531
1555
- let feeAddress = this . account ?. address ( ) ;
1556
- const account_balance =
1557
- await this . networkClient ?. getProgramMappingValue (
1558
- "credits.aleo" ,
1559
- "account" ,
1560
- feeAddress ,
1561
- ) ;
1532
+ let feeAddress ;
1562
1533
1563
- // Check to make sure the public balance is sufficient to cover the execution fee.
1564
- if ( tx . feeAmount ( ) > account_balance ) {
1565
- throw "Public balance is insufficient to execute the transacation." ;
1534
+ if ( this . account !== undefined ) {
1535
+ feeAddress = this . account ?. address ( ) ;
1536
+ } else {
1537
+ throw Error (
1538
+ "No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key." ,
1539
+ ) ;
1566
1540
}
1567
1541
1542
+ this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1543
+
1568
1544
return await this . networkClient . submitTransaction ( tx ) ;
1569
1545
}
1570
1546
@@ -1679,19 +1655,18 @@ class ProgramManager {
1679
1655
)
1680
1656
) ;
1681
1657
1682
- let feeAddress = this . account ?. address ( ) ;
1683
- const account_balance =
1684
- await this . networkClient ?. getProgramMappingValue (
1685
- "credits.aleo" ,
1686
- "account" ,
1687
- feeAddress ,
1688
- ) ;
1658
+ let feeAddress ;
1689
1659
1690
- // Check to make sure the public balance is sufficient to cover the execution fee.
1691
- if ( tx . feeAmount ( ) > account_balance ) {
1692
- throw "Public balance is insufficient to execute the transacation." ;
1660
+ if ( this . account !== undefined ) {
1661
+ feeAddress = this . account ?. address ( ) ;
1662
+ } else {
1663
+ throw Error (
1664
+ "No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key." ,
1665
+ ) ;
1693
1666
}
1694
1667
1668
+ this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1669
+
1695
1670
return await this . networkClient . submitTransaction ( tx ) ;
1696
1671
}
1697
1672
@@ -1797,19 +1772,18 @@ class ProgramManager {
1797
1772
)
1798
1773
) ;
1799
1774
1800
- let feeAddress = this . account ?. address ( ) ;
1801
- const account_balance =
1802
- await this . networkClient ?. getProgramMappingValue (
1803
- "credits.aleo" ,
1804
- "account" ,
1805
- feeAddress ,
1806
- ) ;
1775
+ let feeAddress ;
1807
1776
1808
- // Check to make sure the public balance is sufficient to cover the execution fee.
1809
- if ( tx . feeAmount ( ) > account_balance ) {
1810
- throw "Public balance is insufficient to execute the transacation." ;
1777
+ if ( this . account !== undefined ) {
1778
+ feeAddress = this . account ?. address ( ) ;
1779
+ } else {
1780
+ throw Error (
1781
+ "No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key." ,
1782
+ ) ;
1811
1783
}
1812
1784
1785
+ this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1786
+
1813
1787
return await this . networkClient . submitTransaction ( tx ) ;
1814
1788
}
1815
1789
@@ -1879,7 +1853,7 @@ class ProgramManager {
1879
1853
...additionalOptions ,
1880
1854
} ;
1881
1855
1882
- return await this . execute ( executeOptions ) ;
1856
+ return await this . buildExecutionTransaction ( executeOptions ) ;
1883
1857
}
1884
1858
1885
1859
/**
@@ -1928,19 +1902,18 @@ class ProgramManager {
1928
1902
)
1929
1903
) ;
1930
1904
1931
- let feeAddress = this . account ?. address ( ) ;
1932
- const account_balance =
1933
- await this . networkClient ?. getProgramMappingValue (
1934
- "credits.aleo" ,
1935
- "account" ,
1936
- feeAddress ,
1937
- ) ;
1905
+ let feeAddress ;
1938
1906
1939
- // Check to make sure the public balance is sufficient to cover the execution fee.
1940
- if ( tx . feeAmount ( ) > account_balance ) {
1941
- throw "Public balance is insufficient to execute the transacation." ;
1907
+ if ( this . account !== undefined ) {
1908
+ feeAddress = this . account ?. address ( ) ;
1909
+ } else {
1910
+ throw Error (
1911
+ "No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key." ,
1912
+ ) ;
1942
1913
}
1943
1914
1915
+ this . checkFee ( feeAddress . to_string ( ) , tx . feeAmount ( ) ) ;
1916
+
1944
1917
return this . networkClient . submitTransaction ( tx ) ;
1945
1918
}
1946
1919
0 commit comments