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

read-only functions can not call trait functions even if the implementation uses a read-only function #67

Open
obycode opened this issue Jun 26, 2023 · 0 comments

Comments

@obycode
Copy link
Collaborator

obycode commented Jun 26, 2023

This is duplicated from stacks-network/stacks-core#1981:

The following code

(define-read-only (symbol)
  (contract-call? 'ST3J2GVMMM2R07ZFBJDWTYEYAR8FZH5WKDTFJ9AHA.swapr symbol 'ST3J2GVMMM2R07ZFBJDWTYEYAR8FZH5WKDTFJ9AHA.plaid-token 'ST3J2GVMMM2R07ZFBJDWTYEYAR8FZH5WKDTFJ9AHA.stx-token)
)

generates an error expecting read-only statements, detected a writing operation. (i.e. WriteAttemptedInReadOnly) when deploying, even if contract-call? is calling an other define-read-only function.

This should be allowed.

The latest proposal from the issue suggests adding a map to the trait definition with a field indicating if the function must be read-only:

(define-trait src20-trait
  (
    ;; Transfer from the caller to a new principal
    (transfer (principal uint) (response bool uint))

    ;; the human readable name of the token
    (name () (response (string-ascii 32) uint) {read-only: true})

    ;; the ticker symbol, or empty if none
    (symbol () (response (string-ascii 32) uint) {read-only: true})

    ;; the number of decimals used, e.g. 6 would mean 1_000_000 represents 1 token
    (decimals () (response uint uint) {read-only: true})

    ;; the balance of the passed principal
    (balance-of (principal) (response uint uint) {read-only: true})

    ;; the current total supply (which does not need to be a constant)
    (total-supply () (response uint uint) {read-only: true})
  )
)
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

No branches or pull requests

1 participant