Skip to content

Commit 79f8825

Browse files
committed
fixed lint errors
1 parent 3066191 commit 79f8825

File tree

1 file changed

+82
-63
lines changed

1 file changed

+82
-63
lines changed

sdk/src/program-manager.ts

Lines changed: 82 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "./function-key-provider";
1313

1414
import {
15+
Address,
1516
ExecutionResponse,
1617
Execution as FunctionExecution,
1718
OfflineQuery,
@@ -326,20 +327,20 @@ class ProgramManager {
326327
let feeAddress;
327328

328329
if (typeof privateKey !== "undefined") {
329-
feeAddress = privateKey.address();
330+
feeAddress = Address.fromPrivateKey(privateKey);
330331
} else {
331332
feeAddress = this.account?.address();
332333
}
333334

334-
// Check to make sure the public balance is sufficient to cover the execution fee.
335-
if (
336-
tx.feeAmount() >
337-
(await this.networkClient?.getProgramMappingValue(
335+
const account_balance =
336+
await this.networkClient?.getProgramMappingValue(
338337
"credits.aleo",
339338
"account",
340339
feeAddress,
341-
))
342-
) {
340+
);
341+
342+
// Check to make sure the public balance is sufficient to cover the execution fee.
343+
if (tx.feeAmount() > account_balance) {
343344
throw "Public balance is insufficient to execute the transacation.";
344345
}
345346

@@ -546,6 +547,19 @@ class ProgramManager {
546547
async execute(options: ExecuteOptions): Promise<string> {
547548
const tx = <Transaction>await this.buildExecutionTransaction(options);
548549

550+
let feeAddress = this.account?.address();
551+
const account_balance =
552+
await this.networkClient?.getProgramMappingValue(
553+
"credits.aleo",
554+
"account",
555+
feeAddress,
556+
);
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+
}
562+
549563
// Check to make sure the public balance is sufficient to cover the execution fee.
550564
if (
551565
tx.feeAmount() >
@@ -775,20 +789,20 @@ class ProgramManager {
775789
let feeAddress;
776790

777791
if (typeof privateKey !== "undefined") {
778-
feeAddress = privateKey.address();
792+
feeAddress = Address.fromPrivateKey(privateKey);
779793
} else {
780794
feeAddress = this.account?.address();
781795
}
782796

783-
// Check to make sure the public balance is sufficient to cover the execution fee.
784-
if (
785-
tx.feeAmount() >
786-
(await this.networkClient?.getProgramMappingValue(
797+
const account_balance =
798+
await this.networkClient?.getProgramMappingValue(
787799
"credits.aleo",
788800
"account",
789801
feeAddress,
790-
))
791-
) {
802+
);
803+
804+
// Check to make sure the public balance is sufficient to cover the execution fee.
805+
if (tx.feeAmount() > account_balance) {
792806
throw "Public balance is insufficient to execute the transacation.";
793807
}
794808

@@ -880,20 +894,20 @@ class ProgramManager {
880894
let feeAddress;
881895

882896
if (typeof privateKey !== "undefined") {
883-
feeAddress = privateKey.address();
897+
feeAddress = Address.fromPrivateKey(privateKey);
884898
} else {
885899
feeAddress = this.account?.address();
886900
}
887901

888-
// Check to make sure the public balance is sufficient to cover the execution fee.
889-
if (
890-
tx.feeAmount() >
891-
(await this.networkClient?.getProgramMappingValue(
902+
const account_balance =
903+
await this.networkClient?.getProgramMappingValue(
892904
"credits.aleo",
893905
"account",
894906
feeAddress,
895-
))
896-
) {
907+
);
908+
909+
// Check to make sure the public balance is sufficient to cover the execution fee.
910+
if (tx.feeAmount() > account_balance) {
897911
throw "Public balance is insufficient to execute the transacation.";
898912
}
899913

@@ -1259,20 +1273,20 @@ class ProgramManager {
12591273
let feeAddress;
12601274

12611275
if (typeof privateKey !== "undefined") {
1262-
feeAddress = privateKey.address();
1276+
feeAddress = Address.fromPrivateKey(privateKey);
12631277
} else {
12641278
feeAddress = this.account?.address();
12651279
}
12661280

1267-
// Check to make sure the public balance is sufficient to cover the execution fee.
1268-
if (
1269-
tx.feeAmount() >
1270-
(await this.networkClient?.getProgramMappingValue(
1281+
const account_balance =
1282+
await this.networkClient?.getProgramMappingValue(
12711283
"credits.aleo",
12721284
"account",
12731285
feeAddress,
1274-
))
1275-
) {
1286+
);
1287+
1288+
// Check to make sure the public balance is sufficient to cover the execution fee.
1289+
if (tx.feeAmount() > account_balance) {
12761290
throw "Public balance is insufficient to execute the transacation.";
12771291
}
12781292

@@ -1396,15 +1410,16 @@ class ProgramManager {
13961410
)
13971411
);
13981412

1399-
// Check to make sure the public balance is sufficient to cover the execution fee.
1400-
if (
1401-
tx.feeAmount() >
1402-
this.networkClient?.getProgramMappingValue(
1413+
let feeAddress = this.account?.address();
1414+
const account_balance =
1415+
await this.networkClient?.getProgramMappingValue(
14031416
"credits.aleo",
14041417
"account",
1405-
this.account?.address(),
1406-
)
1407-
) {
1418+
feeAddress,
1419+
);
1420+
1421+
// Check to make sure the public balance is sufficient to cover the execution fee.
1422+
if (tx.feeAmount() > account_balance) {
14081423
throw "Public balance is insufficient to execute the transacation.";
14091424
}
14101425

@@ -1537,15 +1552,16 @@ class ProgramManager {
15371552
)
15381553
);
15391554

1540-
// Check to make sure the public balance is sufficient to cover the execution fee.
1541-
if (
1542-
tx.feeAmount() >
1543-
this.networkClient?.getProgramMappingValue(
1555+
let feeAddress = this.account?.address();
1556+
const account_balance =
1557+
await this.networkClient?.getProgramMappingValue(
15441558
"credits.aleo",
15451559
"account",
1546-
this.account?.address(),
1547-
)
1548-
) {
1560+
feeAddress,
1561+
);
1562+
1563+
// Check to make sure the public balance is sufficient to cover the execution fee.
1564+
if (tx.feeAmount() > account_balance) {
15491565
throw "Public balance is insufficient to execute the transacation.";
15501566
}
15511567

@@ -1663,15 +1679,16 @@ class ProgramManager {
16631679
)
16641680
);
16651681

1666-
// Check to make sure the public balance is sufficient to cover the execution fee.
1667-
if (
1668-
tx.feeAmount() >
1669-
this.networkClient?.getProgramMappingValue(
1682+
let feeAddress = this.account?.address();
1683+
const account_balance =
1684+
await this.networkClient?.getProgramMappingValue(
16701685
"credits.aleo",
16711686
"account",
1672-
this.account?.address(),
1673-
)
1674-
) {
1687+
feeAddress,
1688+
);
1689+
1690+
// Check to make sure the public balance is sufficient to cover the execution fee.
1691+
if (tx.feeAmount() > account_balance) {
16751692
throw "Public balance is insufficient to execute the transacation.";
16761693
}
16771694

@@ -1780,15 +1797,16 @@ class ProgramManager {
17801797
)
17811798
);
17821799

1783-
// Check to make sure the public balance is sufficient to cover the execution fee.
1784-
if (
1785-
tx.feeAmount() >
1786-
this.networkClient?.getProgramMappingValue(
1800+
let feeAddress = this.account?.address();
1801+
const account_balance =
1802+
await this.networkClient?.getProgramMappingValue(
17871803
"credits.aleo",
17881804
"account",
1789-
this.account?.address(),
1790-
)
1791-
) {
1805+
feeAddress,
1806+
);
1807+
1808+
// Check to make sure the public balance is sufficient to cover the execution fee.
1809+
if (tx.feeAmount() > account_balance) {
17921810
throw "Public balance is insufficient to execute the transacation.";
17931811
}
17941812

@@ -1910,15 +1928,16 @@ class ProgramManager {
19101928
)
19111929
);
19121930

1913-
// Check to make sure the public balance is sufficient to cover the execution fee.
1914-
if (
1915-
tx.feeAmount() >
1916-
(await this.networkClient?.getProgramMappingValue(
1931+
let feeAddress = this.account?.address();
1932+
const account_balance =
1933+
await this.networkClient?.getProgramMappingValue(
19171934
"credits.aleo",
19181935
"account",
1919-
this.account?.address(),
1920-
))
1921-
) {
1936+
feeAddress,
1937+
);
1938+
1939+
// Check to make sure the public balance is sufficient to cover the execution fee.
1940+
if (tx.feeAmount() > account_balance) {
19221941
throw "Public balance is insufficient to execute the transacation.";
19231942
}
19241943

0 commit comments

Comments
 (0)