Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: make the comments on using the new confirmTransaction clearer #29251

Merged
merged 5 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions web3.js/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,13 @@ export type BaseTransactionConfirmationStrategy = Readonly<{
signature: TransactionSignature;
}>;

/**
* This type represents all transaction confirmation strategies
*/
export type TransactionConfirmationStrategy =
| BlockheightBasedTransactionConfirmationStrategy
| DurableNonceTransactionConfirmationStrategy;

/* @internal */
function assertEndpointUrl(putativeUrl: string) {
if (/^https?:/.test(putativeUrl) === false) {
Expand Down Expand Up @@ -3603,13 +3610,11 @@ export class Connection {
}

confirmTransaction(
strategy:
| BlockheightBasedTransactionConfirmationStrategy
| DurableNonceTransactionConfirmationStrategy,
strategy: TransactionConfirmationStrategy,
commitment?: Commitment,
): Promise<RpcResponseAndContext<SignatureResult>>;

/** @deprecated Instead, call `confirmTransaction` using a `TransactionConfirmationConfig` */
/** @deprecated Instead, call `confirmTransaction` and pass in {@link TransactionConfirmationStrategy} */
// eslint-disable-next-line no-dupe-class-members
confirmTransaction(
strategy: TransactionSignature,
Expand All @@ -3618,20 +3623,16 @@ export class Connection {

// eslint-disable-next-line no-dupe-class-members
async confirmTransaction(
strategy:
| BlockheightBasedTransactionConfirmationStrategy
| DurableNonceTransactionConfirmationStrategy
| TransactionSignature,
strategy: TransactionConfirmationStrategy | TransactionSignature,
commitment?: Commitment,
): Promise<RpcResponseAndContext<SignatureResult>> {
let rawSignature: string;

if (typeof strategy == 'string') {
rawSignature = strategy;
} else {
const config = strategy as
| BlockheightBasedTransactionConfirmationStrategy
| DurableNonceTransactionConfirmationStrategy;
const config = strategy as TransactionConfirmationStrategy;

if (config.abortSignal?.aborted) {
return Promise.reject(config.abortSignal.reason);
}
Expand Down
13 changes: 5 additions & 8 deletions web3.js/src/utils/send-and-confirm-raw-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
BlockheightBasedTransactionConfirmationStrategy,
Connection,
DurableNonceTransactionConfirmationStrategy,
TransactionConfirmationStrategy,
} from '../connection';
import type {TransactionSignature} from '../transaction';
import type {ConfirmOptions} from '../connection';
Expand All @@ -15,14 +16,14 @@ import type {ConfirmOptions} from '../connection';
*
* @param {Connection} connection
* @param {Buffer} rawTransaction
* @param {BlockheightBasedTransactionConfirmationStrategy} confirmationStrategy
* @param {TransactionConfirmationStrategy} confirmationStrategy
* @param {ConfirmOptions} [options]
* @returns {Promise<TransactionSignature>}
*/
export async function sendAndConfirmRawTransaction(
connection: Connection,
rawTransaction: Buffer,
confirmationStrategy: BlockheightBasedTransactionConfirmationStrategy,
confirmationStrategy: TransactionConfirmationStrategy,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, nice. You found a bug!

options?: ConfirmOptions,
): Promise<TransactionSignature>;

Expand All @@ -42,16 +43,12 @@ export async function sendAndConfirmRawTransaction(
connection: Connection,
rawTransaction: Buffer,
confirmationStrategyOrConfirmOptions:
| BlockheightBasedTransactionConfirmationStrategy
| DurableNonceTransactionConfirmationStrategy
| TransactionConfirmationStrategy
| ConfirmOptions
| undefined,
maybeConfirmOptions?: ConfirmOptions,
): Promise<TransactionSignature> {
let confirmationStrategy:
| BlockheightBasedTransactionConfirmationStrategy
| DurableNonceTransactionConfirmationStrategy
| undefined;
let confirmationStrategy: TransactionConfirmationStrategy | undefined;
let options: ConfirmOptions | undefined;
if (
confirmationStrategyOrConfirmOptions &&
Expand Down