feat: add preflightCommitment support (#12451)
This commit is contained in:
2
web3.js/module.d.ts
vendored
2
web3.js/module.d.ts
vendored
@ -48,11 +48,13 @@ declare module '@solana/web3.js' {
|
|||||||
|
|
||||||
export type SendOptions = {
|
export type SendOptions = {
|
||||||
skipPreflight?: boolean;
|
skipPreflight?: boolean;
|
||||||
|
preflightCommitment?: Commitment;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ConfirmOptions = {
|
export type ConfirmOptions = {
|
||||||
commitment?: Commitment;
|
commitment?: Commitment;
|
||||||
skipPreflight?: boolean;
|
skipPreflight?: boolean;
|
||||||
|
preflightCommitment?: Commitment;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ConfirmedSignaturesForAddress2Options = {
|
export type ConfirmedSignaturesForAddress2Options = {
|
||||||
|
@ -62,11 +62,13 @@ declare module '@solana/web3.js' {
|
|||||||
|
|
||||||
declare export type SendOptions = {
|
declare export type SendOptions = {
|
||||||
skipPreflight: ?boolean,
|
skipPreflight: ?boolean,
|
||||||
|
preflightCommitment: ?Commitment,
|
||||||
};
|
};
|
||||||
|
|
||||||
declare export type ConfirmOptions = {
|
declare export type ConfirmOptions = {
|
||||||
commitment: ?Commitment,
|
commitment: ?Commitment,
|
||||||
skipPreflight: ?boolean,
|
skipPreflight: ?boolean,
|
||||||
|
preflightCommitment: ?Commitment,
|
||||||
};
|
};
|
||||||
|
|
||||||
declare export type ConfirmedSignaturesForAddress2Options = {
|
declare export type ConfirmedSignaturesForAddress2Options = {
|
||||||
|
@ -48,9 +48,11 @@ type Context = {
|
|||||||
*
|
*
|
||||||
* @typedef {Object} SendOptions
|
* @typedef {Object} SendOptions
|
||||||
* @property {boolean | undefined} skipPreflight disable transaction verification step
|
* @property {boolean | undefined} skipPreflight disable transaction verification step
|
||||||
|
* @property {Commitment | undefined} preflightCommitment preflight commitment level
|
||||||
*/
|
*/
|
||||||
export type SendOptions = {
|
export type SendOptions = {
|
||||||
skipPreflight?: boolean,
|
skipPreflight?: boolean,
|
||||||
|
preflightCommitment?: Commitment,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,10 +61,12 @@ export type SendOptions = {
|
|||||||
* @typedef {Object} ConfirmOptions
|
* @typedef {Object} ConfirmOptions
|
||||||
* @property {boolean | undefined} skipPreflight disable transaction verification step
|
* @property {boolean | undefined} skipPreflight disable transaction verification step
|
||||||
* @property {Commitment | undefined} commitment desired commitment level
|
* @property {Commitment | undefined} commitment desired commitment level
|
||||||
|
* @property {Commitment | undefined} preflightCommitment preflight commitment level
|
||||||
*/
|
*/
|
||||||
export type ConfirmOptions = {
|
export type ConfirmOptions = {
|
||||||
skipPreflight?: boolean,
|
skipPreflight?: boolean,
|
||||||
commitment?: Commitment,
|
commitment?: Commitment,
|
||||||
|
preflightCommitment?: Commitment,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2755,7 +2759,20 @@ export class Connection {
|
|||||||
): Promise<TransactionSignature> {
|
): Promise<TransactionSignature> {
|
||||||
const args = [encodedTransaction];
|
const args = [encodedTransaction];
|
||||||
const skipPreflight = options && options.skipPreflight;
|
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 unsafeRes = await this._rpcRequest('sendTransaction', args);
|
||||||
const res = SendTransactionRpcResult(unsafeRes);
|
const res = SendTransactionRpcResult(unsafeRes);
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
|
Reference in New Issue
Block a user