Add getSignatureStatus()

This commit is contained in:
Michael Vines
2018-09-26 19:16:17 -07:00
parent 8ccbe888d3
commit 92af6e3341
5 changed files with 76 additions and 10 deletions

View File

@ -83,6 +83,21 @@ const ConfirmTransactionRpcResult = struct({
result: 'boolean?',
});
/**
* Expected JSON RPC response for the "getSignatureStatus" message
*/
const GetSignatureStatusRpcResult = struct({
jsonrpc: struct.literal('2.0'),
id: 'string',
error: 'any?',
result: struct.optional(struct.enum([
'Confirmed',
'SignatureNotFound',
'ProgramRuntimeError',
'GenericFailure',
])),
});
/**
* Expected JSON RPC response for the "getTransactionCount" message
*/
@ -147,6 +162,13 @@ type AccountInfo = {
userdata: Buffer | null,
}
/**
* Possible signature status values
*
* @typedef {string} SignatureStatus
*/
type SignatureStatus = 'Confirmed' | 'SignatureNotFound' | 'ProgramRuntimeError' | 'GenericFailure';
/**
* A connection to a fullnode JSON RPC endpoint
*/
@ -224,6 +246,20 @@ export class Connection {
return res.result;
}
/**
* Fetch the current transaction count of the network
*/
async getSignatureStatus(signature: TransactionSignature): Promise<SignatureStatus> {
const unsafeRes = await this._rpcRequest('getSignatureStatus', [signature]);
const res = GetSignatureStatusRpcResult(unsafeRes);
if (res.error) {
throw new Error(res.error.message);
}
assert(typeof res.result !== 'undefined');
return res.result;
}
/**
* Fetch the current transaction count of the network
*/