feat: update getSignatureStatus
This commit is contained in:
committed by
Michael Vines
parent
ac8660b2e9
commit
1c31e527e2
@@ -452,7 +452,15 @@ const GetVoteAccounts = jsonRpcResult(
|
||||
* Expected JSON RPC response for the "getSignatureStatus" message
|
||||
*/
|
||||
const GetSignatureStatusRpcResult = jsonRpcResult(
|
||||
struct.union(['null', SignatureStatusResult]),
|
||||
struct.array([
|
||||
struct.union([
|
||||
'null',
|
||||
struct({
|
||||
slot: 'number',
|
||||
status: SignatureStatusResult,
|
||||
}),
|
||||
]),
|
||||
]),
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -660,6 +668,18 @@ export type TransactionError = {|
|
||||
Err: Object,
|
||||
|};
|
||||
|
||||
/**
|
||||
* Signature status
|
||||
*
|
||||
* @typedef {Object} SignatureStatus
|
||||
* @property {number} slot when the transaction was processed
|
||||
* @property {SignatureStatus | TransactionError} status
|
||||
*/
|
||||
export type SignatureStatus = {
|
||||
slot: number,
|
||||
status: SignatureSuccess | TransactionError,
|
||||
};
|
||||
|
||||
/**
|
||||
* A connection to a fullnode JSON RPC endpoint
|
||||
*/
|
||||
@@ -944,8 +964,20 @@ export class Connection {
|
||||
async getSignatureStatus(
|
||||
signature: TransactionSignature,
|
||||
commitment: ?Commitment,
|
||||
): Promise<SignatureSuccess | TransactionError | null> {
|
||||
const args = this._argsWithCommitment([signature], commitment);
|
||||
): Promise<SignatureStatus | null> {
|
||||
const res = await this.getSignatureStatusBatch([signature], commitment);
|
||||
assert(res.length === 1);
|
||||
return res[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the current status of a signature
|
||||
*/
|
||||
async getSignatureStatusBatch(
|
||||
signatures: Array<TransactionSignature>,
|
||||
commitment: ?Commitment,
|
||||
): Promise<Array<SignatureStatus | null>> {
|
||||
const args = this._argsWithCommitment([signatures], commitment);
|
||||
const unsafeRes = await this._rpcRequest('getSignatureStatus', args);
|
||||
const res = GetSignatureStatusRpcResult(unsafeRes);
|
||||
if (res.error) {
|
||||
|
@@ -39,7 +39,7 @@ export async function sendAndConfirmRawTransaction(
|
||||
}
|
||||
}
|
||||
|
||||
if (status && 'Ok' in status) {
|
||||
if (status && status.status && 'Ok' in status.status) {
|
||||
return signature;
|
||||
}
|
||||
|
||||
|
@@ -65,7 +65,7 @@ async function _sendAndConfirmTransaction(
|
||||
await sleep((500 * DEFAULT_TICKS_PER_SLOT) / NUM_TICKS_PER_SECOND);
|
||||
}
|
||||
|
||||
if (status && 'Ok' in status) {
|
||||
if (status && 'Ok' in status.status) {
|
||||
break;
|
||||
}
|
||||
if (--sendRetries <= 0) {
|
||||
@@ -77,7 +77,7 @@ async function _sendAndConfirmTransaction(
|
||||
);
|
||||
}
|
||||
|
||||
if (status && status.Err && !('AccountInUse' in status.Err)) {
|
||||
if (status && status.status.Err && !('AccountInUse' in status.status.Err)) {
|
||||
throw new Error(
|
||||
`Transaction ${signature} failed (${JSON.stringify(status)})`,
|
||||
);
|
||||
|
Reference in New Issue
Block a user