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

[JS->TS] Migrate invokeViewFunction.js #815

Merged
merged 3 commits into from
May 29, 2020
Merged

Conversation

bh2smith
Copy link
Contributor

Partially fulfills #330. Unfortunately, I have not been able to get expected values returned from this script just yet. This snippet is the closest example in the current code base

await contract.methods
.getEncodedUsersPaginated(currentUser, currentOffSet, pageSize)
.call(),

I can verify that logging contract.methods does indeed contain the methods as strings.

Test Plan

npx truffle exec build/common/scripts/invoke_view_function.js --network mainnet getCurrentBatchId

Currently getting back undefined.

Using network 'mainnet'.

2020-05-28 17:39:53,393 INFO [scripts.invoke_view_function] undefined

Copy link
Contributor

@nlordell nlordell left a comment

Choose a reason for hiding this comment

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

This one is tricky in TypeScript since you need to invoke a method by name with parameters at runtime. This means TypeScript can't really properly check that the use of the exchange type is valid since it won't know what method is being called until runtime.

@bh2smith bh2smith force-pushed the 330/migrate_invoke_view branch from c747b04 to e0d5563 Compare May 28, 2020 17:26
}
const [functionName, ...arg] = args;
const exchange = await getBatchExchange(artifacts);
const info = await (exchange as any)[functionName].call(...arg);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sadly... This was unsuccessful.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, not sure then

Copy link
Contributor

Choose a reason for hiding this comment

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

info is of type BN which doesn't seem to print well with log.info (it works with console.log)

@bh2smith
Copy link
Contributor Author

If nobody is opposed, I'd like to take the opportunity to remove this function that is not used anywhere. However, in the essence of making everything TS compatible, I would endure and see this through if desired.

@bh2smith bh2smith marked this pull request as ready for review May 29, 2020 07:52
}
const [functionName, ...arg] = args;
const exchange = await getBatchExchange(artifacts);
const info = await (exchange as any)[functionName].call(...arg);
Copy link
Contributor

Choose a reason for hiding this comment

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

info is of type BN which doesn't seem to print well with log.info (it works with console.log)

@bh2smith bh2smith merged commit 9b52240 into master May 29, 2020
@bh2smith bh2smith deleted the 330/migrate_invoke_view branch May 29, 2020 08:08
// one would usually grep for the results of this execution. Thus,
// the raw output is printed rather than include irrelevant log details.
// eslint-disable-next-line no-console
console.log(info);
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious, is there a reason you didn't use info.toString() ?

Copy link
Contributor Author

@bh2smith bh2smith May 30, 2020

Choose a reason for hiding this comment

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

Actually I think I meant to although this printed fine with getCurrentBatchId

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