From 75ff21c36c6fadc046d173d582eb3b467882acf8 Mon Sep 17 00:00:00 2001 From: bguillaumat Date: Fri, 11 Aug 2023 14:12:02 +0200 Subject: [PATCH] chore(execute): Handle big comput --- package.json | 2 +- src/lib/api.ts | 8 ++++++++ src/lib/menu.ts | 24 +++++++++++++++++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index bf8e6b7..26e427b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sqds/cli", - "version": "2.3.5", + "version": "2.3.6", "description": "", "main": "bin/index.js", "scripts": { diff --git a/src/lib/api.ts b/src/lib/api.ts index 21b9ad2..0bb29df 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -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); } diff --git a/src/lib/menu.ts b/src/lib/menu.ts index fac09fd..206a823 100644 --- a/src/lib/menu.ts +++ b/src/lib/menu.ts @@ -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);