-
Notifications
You must be signed in to change notification settings - Fork 665
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
read-only functions can not call trait functions even if the implementation uses a read-only function #1981
Comments
This is actually a bit more subtle and specific to traits. Traits definition do not specify whether a function is read-only or not, so read-only detection can only be done either at run time, or call time, not deploy time. If calling a read-only function from an other contract, this works fine. More specifically, here's a full example that fails with the same error:
updated the title to reflect the actual issue. One possibility is to relax the implementation of An other possibility would be to change the trait definition to be able to specify some functions should only be defined as Fixing #1641 would also allow calling such functions if you give up on using I tend to favor the first option. Thoughts? |
A third option would be to introduce |
My personal philosophy on this is to "never put off until runtime that which can be done at compile-time" and to "make invalid states unrepresentable." I'm in favor of updating |
yes, I can see your point. So here's my proposal (using the trait swapr uses for tokens, so far):
I'm using a list, so potentially you can have other attributes, such as A function with the |
Looks good to me as well, thank you @psq! |
great, will get a PR ready |
@psq Consider using a record structure for properties such as declaring trait functions to be read-only. Like: (balance-of (principal) (response uint uint) {read-only: true}) |
Temporarily assigning to @obycode for now, so this has an owner. Please re-assign as you see fit. |
The following code
generates an error
expecting read-only statements, detected a writing operation.
(i.e.WriteAttemptedInReadOnly
) when deploying, even ifcontract-call?
is calling an otherdefine-read-only
function.This should be allowed.
Fix may be related to what is needed for #1641, and the 2 issues prevent using the RPC read-only call to call any function using
contract-call
(if you make the functiondefine public
then #1641 prevents you as well.The text was updated successfully, but these errors were encountered: