Skip to content

Commit

Permalink
chore(execute): Handle big comput
Browse files Browse the repository at this point in the history
  • Loading branch information
bguillaumat committed Aug 11, 2023
1 parent 404d481 commit 75ff21c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sqds/cli",
"version": "2.3.5",
"version": "2.3.6",
"description": "",
"main": "bin/index.js",
"scripts": {
Expand Down
8 changes: 8 additions & 0 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ class API{
return this.squads.executeInstruction(tx, ix);
};

executeTransactionBuilder = async (tx: PublicKey) => {
return this.squads.buildExecuteTransaction(tx);
};

executeInstructionBuilder = async (tx: PublicKey, ix: PublicKey) => {
return this.squads.buildExecuteInstruction(tx, ix);
};

approveTransaction = async (tx: PublicKey) => {
return this.squads.approveTransaction(tx);
}
Expand Down
24 changes: 21 additions & 3 deletions src/lib/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,18 +361,36 @@ class Menu{
const [ixPDA] = await getIxPDA(tx.publicKey, new anchor.BN(ixIndex), this.api.programId);
console.log("invoking instruction ", ixIndex);
try {
await this.api.executeInstruction(tx.publicKey, ixPDA);
const ix = await this.api.executeInstructionBuilder(tx.publicKey, ixPDA);
const {blockhash, lastValidBlockHeight} = await this.api.connection.getLatestBlockhash();
const executeIxTx = new Transaction({lastValidBlockHeight, blockhash, feePayer: this.wallet.publicKey});
executeIxTx.add(ix);
const signed = await this.wallet.signTransaction(executeIxTx);
const txid = await this.api.connection.sendRawTransaction(signed.serialize());
await this.api.connection.confirmTransaction(txid, "processed");
await this.api.squads.getTransaction(tx.publicKey)
}catch(e){
console.log("Error executing instruction, trying it again");
await this.api.squads.getTransaction(tx.publicKey);
await this.api.executeInstruction(tx.publicKey, ixPDA);
const ix = await this.api.executeInstructionBuilder(tx.publicKey, ixPDA);
const {blockhash, lastValidBlockHeight} = await this.api.connection.getLatestBlockhash();
const executeIxTx = new Transaction({lastValidBlockHeight, blockhash, feePayer: this.wallet.publicKey});
executeIxTx.add(ix);
const signed = await this.wallet.signTransaction(executeIxTx);
const txid = await this.api.connection.sendRawTransaction(signed.serialize());
await this.api.connection.confirmTransaction(txid, "processed");
}
await this.api.squads.getTransaction(tx.publicKey);
successfullyExecuted++;
}
} else {
await this.api.executeTransaction(tx.publicKey);
const ix = await this.api.executeTransactionBuilder(tx.publicKey);
const {blockhash, lastValidBlockHeight} = await this.api.connection.getLatestBlockhash();
const executeTx = new Transaction({lastValidBlockHeight, blockhash, feePayer: this.wallet.publicKey});
executeTx.add(ix);
const signed = await this.wallet.signTransaction(executeTx);
const txid = await this.api.connection.sendRawTransaction(signed.serialize());
await this.api.connection.confirmTransaction(txid, "processed");
}
status.stop();
const updatedTx = await this.api.squads.getTransaction(tx.publicKey);
Expand Down

0 comments on commit 75ff21c

Please sign in to comment.