Implement transaction confirmation pattern

This commit is contained in:
AdityaSalunkhe21 2025-02-06 10:27:16 +05:30 committed by Adw8
parent 7c42a7cabb
commit 12a6174b13
2 changed files with 16 additions and 8 deletions

View File

@ -24,7 +24,7 @@ import {
web3, web3,
workspace, workspace,
} from '@coral-xyz/anchor'; } from '@coral-xyz/anchor';
import { AccountMeta, Connection, SendTransactionError } from '@solana/web3.js'; import { AccountMeta, Connection, TransactionExpiredTimeoutError } from '@solana/web3.js';
// TODO: Generate type file from IDL json // TODO: Generate type file from IDL json
import { Locker } from '../../target/types/locker'; import { Locker } from '../../target/types/locker';
@ -140,7 +140,7 @@ export async function createVestingPlanV2(params: CreateVestingPlanParams) {
assert(tokenProgram); assert(tokenProgram);
try { try {
const transaction = await program.methods await program.methods
.createVestingEscrowV2( .createVestingEscrowV2(
{ {
vestingStartTime, vestingStartTime,
@ -182,11 +182,20 @@ export async function createVestingPlanV2(params: CreateVestingPlanParams) {
return escrow; return escrow;
} catch (error) { } catch (error) {
if (error instanceof SendTransactionError) { if (error instanceof TransactionExpiredTimeoutError) {
console.error('Transaction failed:', error.message); console.error('Transaction confirmation delayed for',error.signature);
console.error('Logs:', error.logs); console.log('Confirming the transaction again...');
const confirmedTransaction = await connection.getTransaction(error.signature, {
commitment: 'confirmed',
maxSupportedTransactionVersion: 0
});
if(confirmedTransaction === null) {
console.error('Transaction failed for',error.signature);
}
return escrow;
} }
throw error;
} }
} }

View File

@ -62,7 +62,6 @@ export async function getMTMBalance (senderKeypair: anchor.web3.Keypair): Promis
}; };
export async function createLock(tokenLockerKeypair: anchor.web3.Keypair, recipientPubKey: anchor.web3.PublicKey, duration: BN, balance: BN): Promise<anchor.web3.PublicKey | void> { export async function createLock(tokenLockerKeypair: anchor.web3.Keypair, recipientPubKey: anchor.web3.PublicKey, duration: BN, balance: BN): Promise<anchor.web3.PublicKey | void> {
//const balance = await getMTMBalance(tokenLockerKeypair);
if (balance.eq(new BN(0))) { if (balance.eq(new BN(0))) {
console.log('No balance available to create lock, skipping...'); console.log('No balance available to create lock, skipping...');
@ -88,7 +87,7 @@ export async function createLock(tokenLockerKeypair: anchor.web3.Keypair, recipi
}); });
if (escrow) { if (escrow) {
console.log('Lock created successfully: ', escrow.toString()); console.log('Lock created successfully:',escrow.toString());
} }
return escrow; return escrow;