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

feat: add isReadOnly helper for functions #2008

Merged
merged 26 commits into from
Apr 11, 2024
Merged

Conversation

Dhaiwat10
Copy link
Member

@Dhaiwat10 Dhaiwat10 commented Apr 3, 2024

Summary

This PR adds a new helper called isReadOnly to the InvokeFunction type that helps users identify if a given function is read-only or not.

Usage

  const isReadOnly = contract.functions.get_count.isReadOnly();

  if (isReadOnly) {
    await contract.functions.get_count().get();
  } else {
    await contract.functions.get_count().call();
  }

Closes #1931

@Dhaiwat10 Dhaiwat10 enabled auto-merge (squash) April 3, 2024 17:14
Dhaiwat10 and others added 2 commits April 4, 2024 00:13
Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>
@Dhaiwat10
Copy link
Member Author

@petertonysmith94 @danielbate I've improved the API so that people don't have to pass in arguments to the function just to check if it's read-only or not.

@Dhaiwat10 Dhaiwat10 requested a review from maschad April 9, 2024 07:20
Copy link
Member

@maschad maschad left a comment

Choose a reason for hiding this comment

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

Looks good, I've left some suggestions around wording in the docs.

apps/docs/src/guide/contracts/methods.md Outdated Show resolved Hide resolved
apps/docs/src/guide/contracts/methods.md Outdated Show resolved Hide resolved
packages/abi-coder/src/FunctionFragment.ts Show resolved Hide resolved
Dhaiwat10 and others added 2 commits April 10, 2024 18:18
Co-authored-by: Chad Nehemiah <chad.nehemiah94@gmail.com>
Co-authored-by: Chad Nehemiah <chad.nehemiah94@gmail.com>
@Dhaiwat10 Dhaiwat10 requested a review from maschad April 10, 2024 12:49
Copy link
Member

@maschad maschad left a comment

Choose a reason for hiding this comment

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

Great work!

Copy link
Contributor

Coverage Report:

Lines Branches Functions Statements
79.37%(-0.04%) 69.7%(+0.03%) 77.33%(-0.12%) 79.52%(-0.03%)
Changed Files:
Ok File (✨=New File) Lines Branches Functions Statements
🔴 packages/abi-coder/src/FunctionFragment.ts 71.01%
(-2.12%)
71.42%
(+0%)
73.33%
(-11.28%)
70.83%
(-3.08%)
🔴 packages/abi-coder/src/utils/utilities.ts 98.24%
(+0.03%)
90%
(+0%)
100%
(+0%)
98.36%
(+0.06%)
🔴 packages/account/src/predicate/predicate.ts 30%
(-1.37%)
35.71%
(+0%)
20%
(+0%)
30%
(-1.37%)
🔴 packages/program/src/contract.ts 78.94%
(-6.77%)
83.33%
(+0%)
50%
(+0%)
78.94%
(-1.06%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a helper that helps users identify if a given contract function is read-only or not
6 participants