@marinade.finance/web3js-common
Advanced tools
Comparing version 2.2.1 to 2.2.2
{ | ||
"name": "@marinade.finance/web3js-common", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "Web3 JS reusable utilities", | ||
@@ -25,3 +25,3 @@ "repository": { | ||
"@solana/web3.js": "^1.78.5", | ||
"@marinade.finance/ts-common": "2.2.1", | ||
"@marinade.finance/ts-common": "2.2.2", | ||
"bn.js": "^5.2.1", | ||
@@ -33,3 +33,3 @@ "borsh": "^0.7.0", | ||
"@solana/web3.js": "^1.78.5", | ||
"@marinade.finance/ts-common": "2.2.1", | ||
"@marinade.finance/ts-common": "2.2.2", | ||
"bn.js": "^5.2.1", | ||
@@ -36,0 +36,0 @@ "borsh": "^0.7.0", |
@@ -6,3 +6,3 @@ import { Connection, Transaction, VersionedTransactionResponse, SimulatedTransactionResponse, Keypair, Signer, TransactionInstruction, TransactionResponse, PublicKey, SendOptions, VersionedTransaction, Finality } from '@solana/web3.js'; | ||
export declare function transaction(connection: Connection | Provider, feePayer?: PublicKey | Wallet | Keypair | Signer): Promise<Transaction>; | ||
export declare function executeTx({ connection, transaction, signers, errMessage, simulate, printOnly, logger, sendOpts, confirmOpts, }: { | ||
export type ExecuteTxParams = { | ||
connection: Connection; | ||
@@ -17,4 +17,6 @@ transaction: Transaction; | ||
confirmOpts?: Finality; | ||
}): Promise<VersionedTransactionResponse | SimulatedTransactionResponse | undefined>; | ||
}; | ||
export declare function executeTx({ connection, transaction, signers, errMessage, simulate, printOnly, logger, sendOpts, confirmOpts, }: ExecuteTxParams): Promise<VersionedTransactionResponse | SimulatedTransactionResponse | undefined>; | ||
export declare function executeTxSimple(connection: Connection, transaction: Transaction, signers?: (Wallet | Keypair | Signer)[], sendOpts?: SendOptions, confirmOpts?: Finality): Promise<VersionedTransactionResponse | SimulatedTransactionResponse | undefined>; | ||
export declare function executeTxWithExceededBlockhashRetry(txParams: ExecuteTxParams): Promise<VersionedTransactionResponse | SimulatedTransactionResponse | undefined>; | ||
/** | ||
@@ -21,0 +23,0 @@ * Type guard for TransactionResponse and SimulatedTransactionResponse. It does not accept `undefined` as a valid input. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.debugStr = exports.splitAndExecuteTx = exports.TRANSACTION_SAFE_SIZE = exports.filterSignersForInstruction = exports.isVersionedTransaction = exports.isSimulatedTransactionResponse = exports.executeTxSimple = exports.executeTx = exports.transaction = void 0; | ||
exports.debugStr = exports.splitAndExecuteTx = exports.TRANSACTION_SAFE_SIZE = exports.filterSignersForInstruction = exports.isVersionedTransaction = exports.isSimulatedTransactionResponse = exports.executeTxWithExceededBlockhashRetry = exports.executeTxSimple = exports.executeTx = exports.transaction = void 0; | ||
const web3_js_1 = require("@solana/web3.js"); | ||
@@ -42,5 +42,6 @@ const wallet_1 = require("./wallet"); | ||
} | ||
const currentBlockhash = await connection.getLatestBlockhash(); | ||
if (transaction.recentBlockhash === undefined || | ||
transaction.lastValidBlockHeight === undefined || | ||
transaction.feePayer === undefined) { | ||
const currentBlockhash = await connection.getLatestBlockhash(); | ||
transaction.lastValidBlockHeight = currentBlockhash.lastValidBlockHeight; | ||
@@ -130,2 +131,24 @@ transaction.recentBlockhash = currentBlockhash.blockhash; | ||
exports.executeTxSimple = executeTxSimple; | ||
async function executeTxWithExceededBlockhashRetry(txParams) { | ||
try { | ||
return await executeTx(txParams); | ||
} | ||
catch (e) { | ||
if (checkErrorMessage(e, 'block height exceeded')) { | ||
txParams.transaction.recentBlockhash = undefined; | ||
return await executeTx(txParams); | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
} | ||
exports.executeTxWithExceededBlockhashRetry = executeTxWithExceededBlockhashRetry; | ||
function checkErrorMessage(e, message) { | ||
return (typeof e === 'object' && | ||
e !== null && | ||
'message' in e && | ||
typeof e.message === 'string' && | ||
e.message.includes(message.toString())); | ||
} | ||
/** | ||
@@ -265,12 +288,2 @@ * Type guard for TransactionResponse and SimulatedTransactionResponse. It does not accept `undefined` as a valid input. | ||
} | ||
// sign all transactions with fee payer at once | ||
if ((0, wallet_1.instanceOfWallet)(feePayerSigner)) { | ||
// partial signing by this call | ||
await feePayerSigner.signAllTransactions(transactions); | ||
} | ||
else { | ||
for (const transaction of transactions) { | ||
transaction.partialSign(feePayerSigner); | ||
} | ||
} | ||
let executionCounter = 0; | ||
@@ -280,3 +293,4 @@ resultTransactions.push(...transactions); | ||
const txSigners = filterSignersForInstruction(transaction.instructions, signers).filter(s => !s.publicKey.equals(feePayerDefined)); | ||
const executeResult = await executeTx({ | ||
txSigners.push(feePayerSigner); | ||
const executeResult = await executeTxWithExceededBlockhashRetry({ | ||
connection, | ||
@@ -286,2 +300,3 @@ transaction, | ||
signers: txSigners, | ||
simulate, | ||
logger, | ||
@@ -288,0 +303,0 @@ sendOpts, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62855
957