Skip to content

Commit

Permalink
docs: make the comments on using the new confirmTransaction clearer (#…
Browse files Browse the repository at this point in the history
…29251)

* docs: make the comments on using the new connection.confirmTransaction clearer

* docs: add TransactionConfirmataionStrategy type

* refactor: change param type in sendAndConfirmRawTransaction

* docs: fix typo
  • Loading branch information
GHesericsu authored Dec 19, 2022
1 parent 456a819 commit 710ac01
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
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,
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

0 comments on commit 710ac01

Please sign in to comment.