forked from mito-systems/sol-mem-gen
Implement transaction confirmation pattern
This commit is contained in:
parent
7c42a7cabb
commit
12a6174b13
@ -24,7 +24,7 @@ import {
|
||||
web3,
|
||||
workspace,
|
||||
} 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
|
||||
import { Locker } from '../../target/types/locker';
|
||||
@ -140,7 +140,7 @@ export async function createVestingPlanV2(params: CreateVestingPlanParams) {
|
||||
assert(tokenProgram);
|
||||
|
||||
try {
|
||||
const transaction = await program.methods
|
||||
await program.methods
|
||||
.createVestingEscrowV2(
|
||||
{
|
||||
vestingStartTime,
|
||||
@ -182,11 +182,20 @@ export async function createVestingPlanV2(params: CreateVestingPlanParams) {
|
||||
|
||||
return escrow;
|
||||
} catch (error) {
|
||||
if (error instanceof SendTransactionError) {
|
||||
console.error('Transaction failed:', error.message);
|
||||
console.error('Logs:', error.logs);
|
||||
if (error instanceof TransactionExpiredTimeoutError) {
|
||||
console.error('Transaction confirmation delayed for',error.signature);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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> {
|
||||
//const balance = await getMTMBalance(tokenLockerKeypair);
|
||||
|
||||
if (balance.eq(new BN(0))) {
|
||||
console.log('No balance available to create lock, skipping...');
|
||||
@ -88,7 +87,7 @@ export async function createLock(tokenLockerKeypair: anchor.web3.Keypair, recipi
|
||||
});
|
||||
|
||||
if (escrow) {
|
||||
console.log('Lock created successfully: ', escrow.toString());
|
||||
console.log('Lock created successfully:',escrow.toString());
|
||||
}
|
||||
|
||||
return escrow;
|
||||
|
Loading…
Reference in New Issue
Block a user