Skip to content

Commit 845cbf9

Browse files
committed
added private key check for methods that take in ExecuteOptions parameter
1 parent e453562 commit 845cbf9

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

sdk/src/program-manager.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,14 @@ class ProgramManager {
559559
const tx = <Transaction>await this.buildExecutionTransaction(options);
560560

561561
let feeAddress;
562-
if (this.account !== undefined) {
562+
563+
if (typeof options.privateKey !== "undefined") {
564+
feeAddress = Address.from_private_key(options.privateKey);
565+
} else if (this.account !== undefined) {
563566
feeAddress = this.account?.address();
564567
} else {
565568
throw Error(
566-
"No account set in the ProgramManager. Please set an account before executing a transaction.",
569+
"No private key provided and no private key set in the ProgramManager. Please set an account or provide a private key.",
567570
);
568571
}
569572

@@ -1390,7 +1393,10 @@ class ProgramManager {
13901393
);
13911394

13921395
let feeAddress;
1393-
if (this.account !== undefined) {
1396+
1397+
if (typeof options.privateKey !== "undefined") {
1398+
feeAddress = Address.from_private_key(options.privateKey);
1399+
} else if (this.account !== undefined) {
13941400
feeAddress = this.account?.address();
13951401
} else {
13961402
throw Error(
@@ -1531,7 +1537,9 @@ class ProgramManager {
15311537

15321538
let feeAddress;
15331539

1534-
if (this.account !== undefined) {
1540+
if (typeof options.privateKey !== "undefined") {
1541+
feeAddress = Address.from_private_key(options.privateKey);
1542+
} else if (this.account !== undefined) {
15351543
feeAddress = this.account?.address();
15361544
} else {
15371545
throw Error(
@@ -1657,7 +1665,9 @@ class ProgramManager {
16571665

16581666
let feeAddress;
16591667

1660-
if (this.account !== undefined) {
1668+
if (typeof options.privateKey !== "undefined") {
1669+
feeAddress = Address.from_private_key(options.privateKey);
1670+
} else if (this.account !== undefined) {
16611671
feeAddress = this.account?.address();
16621672
} else {
16631673
throw Error(
@@ -1774,7 +1784,9 @@ class ProgramManager {
17741784

17751785
let feeAddress;
17761786

1777-
if (this.account !== undefined) {
1787+
if (typeof options.privateKey !== "undefined") {
1788+
feeAddress = Address.from_private_key(options.privateKey);
1789+
} else if (this.account !== undefined) {
17781790
feeAddress = this.account?.address();
17791791
} else {
17801792
throw Error(
@@ -1904,7 +1916,9 @@ class ProgramManager {
19041916

19051917
let feeAddress;
19061918

1907-
if (this.account !== undefined) {
1919+
if (typeof options.privateKey !== "undefined") {
1920+
feeAddress = Address.from_private_key(options.privateKey);
1921+
} else if (this.account !== undefined) {
19081922
feeAddress = this.account?.address();
19091923
} else {
19101924
throw Error(

0 commit comments

Comments
 (0)