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

Check if isCompleted is undefined #315

Merged
merged 4 commits into from
Aug 22, 2023
Merged

Conversation

popenta
Copy link
Contributor

@popenta popenta commented Aug 10, 2023

This is done because in the new version of sdk-network-providers the isCompleted field has become optional. Nothing has changed for the ApiNetworkProvider, but for the ProxyNetworkProvider the isCompleted field will only be set if getTransaction() is called using withProcessStatus=true.

As you may know, the TransactionWatcher class needs a TransactionFetcher object when initialized. You can use both ApiNetworkProvider or ProxyNetworkProvider because both respect the interface.

In case you are using the proxy provider and you need the isCompleted field, a plain object that uses the proxy provider can be passed, defining a getTransaction() method that explicitly calls proxyProvider.getTransaction() using withProcessStatus=true. This can be done as bellow:

let provider = new ProxyNetworkProvider("http://localhost:7950", { timeout: 5000 });
let watcher = new TransactionWatcher({
    getTransaction: async (hash: string) => { return await provider.getTransaction(hash, true) }
});

Now, the completion checks are more strict, so it takes more time to check if a transaction is completed. The changes have been done in the following PR's:

@popenta popenta marked this pull request as draft August 10, 2023 13:51
@popenta popenta marked this pull request as ready for review August 11, 2023 10:56
@andreibancioiu andreibancioiu self-requested a review August 22, 2023 07:38
@@ -36,6 +36,7 @@
},
"devDependencies": {
"@multiversx/sdk-network-providers": "1.2.1",
"@multiversx/sdk-network-providers-next": "npm:@multiversx/[email protected]",
Copy link
Contributor

@andreibancioiu andreibancioiu Aug 22, 2023

Choose a reason for hiding this comment

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

All right for now (to reference the beta version), since it's used for tests only (dev dependency). Once sdk-core is compatible with both the old and the new sdk-network-providers (as of this PR), we can make a proper release there, as well. And afterwards, come back here to adjust the reference.

For sdk-core, let's bump the minor version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, got it. So after this PR is merged we make a proper release for sdk-network-providers, then come back here and reference the proper release. Will also make a new release for sdk-core increasing the minor version. 👍🏻

Copy link
Contributor

@andreibancioiu andreibancioiu Aug 22, 2023

Choose a reason for hiding this comment

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

First, release of this adjustment of sdk-core, then release sdk-network-providers. Afterwards, come back in sdk-core to adjust the version (this can be delayed anyway).

src/errors.ts Outdated

export class ErrIsCompletedFieldIsMissingOnTransaction extends Err {
public constructor() {
super("The transaction watcher requires the isCompleted property to be defined on the transaction object. Perhaps you've used the sdk-network-provider's getTransaction() and in that case you should also pass `withProcessStatus=true`.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps add quotes for isCompleted and getTransaction(), as did for withProcessStatus.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added quotes.

it("should send transactions", async function () {
this.timeout(30000);
it("should send transactions and wait for completion", async function () {
this.timeout(70000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yup. Because the completion checks are now much more strict, multiversx/mx-chain-proxy-go#386, and the wait time is increased.

Let's add links towards the following PRs in the description:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

let provider = createLocalnetProvider();
let newProvider = new ProxyNetworkProvider("http://localhost:7950", { timeout: 5000 });
let watcher = new TransactionWatcher({
getTransaction: async (hash: string) => { return await newProvider.getTransaction(hash, true) }
Copy link
Contributor

Choose a reason for hiding this comment

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

This snippet should be added in the PR description (and in the release notes).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in the PR description. Will also add in the release nodes when it's time.

@@ -155,6 +161,10 @@ export class TransactionWatcher {
} catch (error) {
Logger.debug("TransactionWatcher.awaitConditionally(): cannot (yet) fetch data.");

if (error instanceof ErrIsCompletedFieldIsMissingOnTransaction) {
Copy link
Contributor

Choose a reason for hiding this comment

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

bogdan-rosianu
bogdan-rosianu previously approved these changes Aug 22, 2023
@popenta popenta merged commit 5b5a69e into main Aug 22, 2023
1 check passed
@popenta popenta deleted the tx-watcher-is-completed-fix branch August 22, 2023 13: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