fix: Appease flow
This commit is contained in:
committed by
Michael Vines
parent
663f9c76d8
commit
507fac06ee
@@ -126,11 +126,8 @@ const ConfirmTransactionRpcResult = jsonRpcResult('boolean');
|
||||
const GetSignatureStatusRpcResult = jsonRpcResult(
|
||||
struct.union([
|
||||
'null',
|
||||
struct.union([
|
||||
struct({Ok: 'null'}),
|
||||
struct({Err: 'string'})
|
||||
])
|
||||
])
|
||||
struct.union([struct({Ok: 'null'}), struct({Err: 'object'})]),
|
||||
]),
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -212,16 +209,22 @@ type ProgramAccountSubscriptionInfo = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Possible signature status values
|
||||
* Signature status: Success
|
||||
*
|
||||
* @typedef {string} SignatureStatus
|
||||
* @typedef {Object} SignatureSuccess
|
||||
*/
|
||||
export type SignatureStatus =
|
||||
| 'Confirmed'
|
||||
| 'AccountInUse'
|
||||
| 'SignatureNotFound'
|
||||
| 'ProgramRuntimeError'
|
||||
| 'GenericFailure';
|
||||
export type SignatureSuccess = {|
|
||||
Ok: null,
|
||||
|};
|
||||
|
||||
/**
|
||||
* Signature status: TransactionError
|
||||
*
|
||||
* @typedef {Object} TransactionError
|
||||
*/
|
||||
export type TransactionError = {|
|
||||
Err: Object,
|
||||
|};
|
||||
|
||||
/**
|
||||
* A connection to a fullnode JSON RPC endpoint
|
||||
@@ -338,7 +341,7 @@ export class Connection {
|
||||
*/
|
||||
async getSignatureStatus(
|
||||
signature: TransactionSignature,
|
||||
): Promise<SignatureStatus> {
|
||||
): Promise<SignatureSuccess | TransactionError | null> {
|
||||
const unsafeRes = await this._rpcRequest('getSignatureStatus', [signature]);
|
||||
const res = GetSignatureStatusRpcResult(unsafeRes);
|
||||
if (res.error) {
|
||||
|
@@ -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)})`);
|
||||
}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user