cadence
cadence copied to clipboard
Allow calling `getAuthAccount()` in `view` functions
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
???
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)
This works as expected, tested with:
access(all) view fun main() {
getAuthAccount<auth(Storage) &Account>(0x8c5303eaa26202d6)
}