fix: sendAndConfirmTransaction now returns the transaction signature
This commit is contained in:
parent
c424b48cd2
commit
9a043344d5
|
@ -232,5 +232,5 @@ declare module '@solana/web3.js' {
|
|||
from: Account,
|
||||
transaction: Transaction,
|
||||
runtimeErrorOk?: boolean,
|
||||
): Promise<void>;
|
||||
): Promise<TransactionSignature>;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import {Connection} from '../connection';
|
|||
import {Transaction} from '../transaction';
|
||||
import {sleep} from './sleep';
|
||||
import type {Account} from '../account';
|
||||
import type {TransactionSignature} from '../transaction';
|
||||
|
||||
/**
|
||||
* Sign, send and confirm a transaction
|
||||
|
@ -13,12 +14,13 @@ export async function sendAndConfirmTransaction(
|
|||
from: Account,
|
||||
transaction: Transaction,
|
||||
runtimeErrorOk: boolean = false
|
||||
): Promise<void> {
|
||||
): Promise<?TransactionSignature> {
|
||||
|
||||
let sendRetries = 10;
|
||||
let signature;
|
||||
for (;;) {
|
||||
const start = Date.now();
|
||||
const signature = await connection.sendTransaction(from, transaction);
|
||||
signature = await connection.sendTransaction(from, transaction);
|
||||
|
||||
// Wait up to a couple seconds for a confirmation
|
||||
let status = 'SignatureNotFound';
|
||||
|
@ -38,7 +40,7 @@ export async function sendAndConfirmTransaction(
|
|||
|
||||
if ( (status === 'Confirmed') ||
|
||||
(status === 'ProgramRuntimeError' && runtimeErrorOk) ) {
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
if (status !== 'AccountInUse' || --sendRetries <= 0) {
|
||||
|
@ -48,5 +50,7 @@ export async function sendAndConfirmTransaction(
|
|||
// Retry in 0..100ms to try to avoid another collision
|
||||
await sleep(Math.random() * 100);
|
||||
}
|
||||
|
||||
return signature;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue