feat: update confirmation status typing and validations

This commit is contained in:
Justin Starry
2021-03-15 09:52:52 +08:00
committed by Justin Starry
parent d40dc06d6a
commit a5c840e672
3 changed files with 24 additions and 5 deletions

2
web3.js/module.d.ts vendored
View File

@ -106,7 +106,7 @@ declare module '@solana/web3.js' {
slot: number; slot: number;
err: TransactionError | null; err: TransactionError | null;
confirmations: number | null; confirmations: number | null;
confirmationStatus: TransactionConfirmationStatus | null; confirmationStatus?: TransactionConfirmationStatus;
}; };
export type ConfirmedSignatureInfo = { export type ConfirmedSignatureInfo = {

View File

@ -119,7 +119,7 @@ declare module '@solana/web3.js' {
slot: number, slot: number,
err: TransactionError | null, err: TransactionError | null,
confirmations: number | null, confirmations: number | null,
confirmationStatus: TransactionConfirmationStatus | null, confirmationStatus?: TransactionConfirmationStatus,
}; };
declare export type ConfirmedSignatureInfo = { declare export type ConfirmedSignatureInfo = {

View File

@ -1054,11 +1054,17 @@ const GetVoteAccounts = jsonRpcResult(
}), }),
); );
const ConfirmationStatus = union([
literal('processed'),
literal('confirmed'),
literal('finalized'),
]);
const SignatureStatusResponse = pick({ const SignatureStatusResponse = pick({
slot: number(), slot: number(),
confirmations: nullable(number()), confirmations: nullable(number()),
err: TransactionErrorResult, err: TransactionErrorResult,
confirmationStatus: optional(nullable(string())), confirmationStatus: optional(ConfirmationStatus),
}); });
/** /**
@ -1500,6 +1506,19 @@ export type SignatureResult = {|
*/ */
export type TransactionError = {}; export type TransactionError = {};
/**
* Transaction confirmation status
* <pre>
* 'processed': Transaction landed in a block which has reached 1 confirmation by the connected node
* 'confirmed': Transaction landed in a block which has reached 1 confirmation by the cluster
* 'finalized': Transaction landed in a block which has been finalized by the cluster
* </pre>
*/
export type TransactionConfirmationStatus =
| 'processed'
| 'confirmed'
| 'finalized';
/** /**
* Signature status * Signature status
* *
@ -1507,13 +1526,13 @@ export type TransactionError = {};
* @property {number} slot when the transaction was processed * @property {number} slot when the transaction was processed
* @property {number | null} confirmations the number of blocks that have been confirmed and voted on in the fork containing `slot` (TODO) * @property {number | null} confirmations the number of blocks that have been confirmed and voted on in the fork containing `slot` (TODO)
* @property {TransactionError | null} err error, if any * @property {TransactionError | null} err error, if any
* @property {string | null} confirmationStatus the transaction's cluster confirmation status, if data available. Possible non-null responses: `processed`, `confirmed`, `finalized` * @property {?TransactionConfirmationStatus} confirmationStatus the transaction's cluster confirmation status, if data available. Possible responses: `processed`, `confirmed`, `finalized`
*/ */
export type SignatureStatus = { export type SignatureStatus = {
slot: number, slot: number,
confirmations: number | null, confirmations: number | null,
err: TransactionError | null, err: TransactionError | null,
confirmationStatus: string | null, confirmationStatus?: TransactionConfirmationStatus,
}; };
/** /**