fix: Appease flow

This commit is contained in:
Tyera Eulberg
2019-04-10 14:40:49 -07:00
committed by Michael Vines
parent 663f9c76d8
commit 507fac06ee
6 changed files with 44 additions and 41 deletions

View File

@@ -16,11 +16,11 @@ export async function sendAndConfirmRawTransaction(
let signature = await connection.sendRawTransaction(rawTransaction);
// Wait up to a couple slots for a confirmation
let status = '';
let status = null;
let statusRetries = 6;
for (;;) {
status = await connection.getSignatureStatus(signature);
if (status !== 'SignatureNotFound') {
if (status) {
break;
}
@@ -32,14 +32,14 @@ export async function sendAndConfirmRawTransaction(
throw new Error(
`Raw Transaction '${signature}' was not confirmed in ${duration.toFixed(
2,
)} seconds (${status})`,
)} seconds (${JSON.stringify(status)})`,
);
}
}
if (status === 'Confirmed') {
if (status && 'Ok' in status) {
return signature;
}
throw new Error(`Raw transaction ${signature} failed (${status})`);
throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
}

View File

@@ -24,7 +24,7 @@ export async function sendAndConfirmTransaction(
signature = await connection.sendTransaction(transaction, ...signers);
// Wait up to a couple slots for a confirmation
let status = 'SignatureNotFound';
let status = null;
let statusRetries = 6;
for (;;) {
status = await connection.getSignatureStatus(signature);
@@ -39,7 +39,7 @@ export async function sendAndConfirmTransaction(
await sleep((500 * DEFAULT_TICKS_PER_SLOT) / NUM_TICKS_PER_SECOND);
}
if ('Ok' in status) {
if (status && 'Ok' in status) {
break;
}
if (--sendRetries <= 0) {
@@ -47,12 +47,12 @@ export async function sendAndConfirmTransaction(
throw new Error(
`Transaction '${signature}' was not confirmed in ${duration.toFixed(
2,
)} seconds (${status})`,
)} seconds (${JSON.stringify(status)})`,
);
}
if ('Err' in status && !status.includes('AccountInUse')) {
throw new Error(`Transaction ${signature} failed (${status})`);
if (status && status.Err && !('AccountInUse' in status.Err)) {
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
}
// Retry in 0..100ms to try to avoid another AccountInUse collision