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

Refactor TransactionWatcher to accept either Transaction or hash #404

Merged
merged 5 commits into from
Mar 19, 2024

Conversation

popenta
Copy link
Contributor

@popenta popenta commented Mar 18, 2024

The methods of the TransactionWatcher can be called using either the transaction object or the hash of the transaction.

public async awaitCompleted(transactionOrTxHash: ITransaction | string): Promise<ITransactionOnNetwork> {...}

@popenta popenta self-assigned this Mar 18, 2024
andreibancioiu
andreibancioiu previously approved these changes Mar 19, 2024
Copy link
Contributor

@andreibancioiu andreibancioiu left a comment

Choose a reason for hiding this comment

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

👍 This undoes a breaking change.


await Promise.all([
provider.mockTransactionTimelineByHash(hash, [new Wait(40), new TransactionStatus("pending"), new Wait(40), new TransactionStatus("executed"), new MarkCompleted()]),
watcher.awaitCompleted(dummyTransaction)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

import { ITransactionFetcher } from "./interface";
import { ITransactionEvent, ITransactionOnNetwork, ITransactionStatus } from "./interfaceOfNetwork";
import { Logger } from "./logger";

export type PredicateIsAwaitedStatus = (status: ITransactionStatus) => boolean;

/**
* Internal interface: a transaction, as seen from the perspective of a {@link TransactionWatcher}.
Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, for backwards compatibility (legacy).

};

const doFetch = async () => await this.fetcher.getTransaction(txHash);
const doFetch = async () => {
const hash = typeof transactionOrTxHash === "string" ? transactionOrTxHash : transactionOrTxHash.getHash().hex();
Copy link
Contributor

Choose a reason for hiding this comment

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

Since logic is in several places, could have been extracted to a private function e.g. transactionOrTxHashToTxHash(...): string.

Can also stay as it is, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

extracted to a private method.

andreibancioiu
andreibancioiu previously approved these changes Mar 19, 2024
}

private transactionOrTxHashToTxHash(transactionOrTxHash: ITransaction | string): string {
return typeof transactionOrTxHash === "string" ? transactionOrTxHash : transactionOrTxHash.getHash().hex();
Copy link
Contributor

Choose a reason for hiding this comment

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

could also check the validity of the hash. it can be "invalid tx hash" instead of 64 hex chars

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@popenta popenta merged commit ee7e2d4 into feat/next Mar 19, 2024
1 check passed
@popenta popenta deleted the tx-watcher-for-old-transactions branch March 19, 2024 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants