feat: add preflightCommitment support (#12451)

This commit is contained in:
Justin Starry 2020-09-25 08:49:34 +08:00 committed by GitHub
parent 018cb5035a
commit 720f863937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

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

@ -48,11 +48,13 @@ declare module '@solana/web3.js' {
export type SendOptions = {
skipPreflight?: boolean;
preflightCommitment?: Commitment;
};
export type ConfirmOptions = {
commitment?: Commitment;
skipPreflight?: boolean;
preflightCommitment?: Commitment;
};
export type ConfirmedSignaturesForAddress2Options = {

View File

@ -62,11 +62,13 @@ declare module '@solana/web3.js' {
declare export type SendOptions = {
skipPreflight: ?boolean,
preflightCommitment: ?Commitment,
};
declare export type ConfirmOptions = {
commitment: ?Commitment,
skipPreflight: ?boolean,
preflightCommitment: ?Commitment,
};
declare export type ConfirmedSignaturesForAddress2Options = {

View File

@ -48,9 +48,11 @@ type Context = {
*
* @typedef {Object} SendOptions
* @property {boolean | undefined} skipPreflight disable transaction verification step
* @property {Commitment | undefined} preflightCommitment preflight commitment level
*/
export type SendOptions = {
skipPreflight?: boolean,
preflightCommitment?: Commitment,
};
/**
@ -59,10 +61,12 @@ export type SendOptions = {
* @typedef {Object} ConfirmOptions
* @property {boolean | undefined} skipPreflight disable transaction verification step
* @property {Commitment | undefined} commitment desired commitment level
* @property {Commitment | undefined} preflightCommitment preflight commitment level
*/
export type ConfirmOptions = {
skipPreflight?: boolean,
commitment?: Commitment,
preflightCommitment?: Commitment,
};
/**
@ -2755,7 +2759,20 @@ export class Connection {
): Promise<TransactionSignature> {
const args = [encodedTransaction];
const skipPreflight = options && options.skipPreflight;
if (skipPreflight) args.push({skipPreflight});
const preflightCommitment = options && options.preflightCommitment;
if (skipPreflight && preflightCommitment) {
throw new Error(
'cannot set preflightCommitment when skipPreflight is enabled',
);
}
if (skipPreflight) {
args.push({skipPreflight});
} else if (preflightCommitment) {
args.push({preflightCommitment});
}
const unsafeRes = await this._rpcRequest('sendTransaction', args);
const res = SendTransactionRpcResult(unsafeRes);
if (res.error) {