cadence icon indicating copy to clipboard operation
cadence copied to clipboard

Allow calling `getAuthAccount()` in `view` functions

Open joshuahannan opened this issue 1 year ago • 1 comments

Issue to be solved

Being able to get authorized account objects has been pretty useful for scripts since it was introduced. In a similar vein, view functions are not allowed to modify state, so it seems like it could be useful to allow calling getAuthAccount within view functions also. This would allow even transactions to access the private information in accounts without being able to modify it. It could be very useful.

Suggested Solution

???

joshuahannan avatar Oct 10 '24 21:10 joshuahannan

this is tricky; their result can leave view scope.

 var ref = view fun(): auth(Storage) &Account{
    return getAuthAccount<auth(Storage) &Account>(0x1) 
  }()

  ref.storage.save("deniz", to: /storage/x)

bluesign avatar Oct 10 '24 22:10 bluesign

This works as expected, tested with:

access(all) view fun main() {
    getAuthAccount<auth(Storage) &Account>(0x8c5303eaa26202d6)
}

turbolent avatar Oct 14 '25 17:10 turbolent