Near-One / near-plugins

Implementation of common patterns used for NEAR smart contracts.
Creative Commons Zero v1.0 Universal
27 stars 12 forks source link

`Ownable::owner_is(&self)` fails when called via `view` #58

Closed mooori closed 1 year ago

mooori commented 1 year ago

The error is:

FunctionCallError(HostError(ProhibitedInView { method_name: "predecessor_account_id" })

Since owner_is takes &self, it might be assumed it’s eligible for view. I couldn’t find a precise definition of when a function is eligible for view, hence I’m not sure how to handle this. Is it ok to simply mention in docs that owner_is cannot be called via view?

The method’s default implementation is here:

https://github.com/aurora-is-near/near-plugins/blob/df8473232c76d6b75cfcb255e55975d8a5d9c7ff/near-plugins-derive/src/ownable.rs#L76-L80


Another option could be changing the signature:

/// Returns whether `account_id` is the owner of the contract.
fn owner_is(&self, account_id: AccountId) -> bool

It would remove the problem and make the method more general, though it would also be a breaking change.

mooori commented 1 year ago

cc @birchmd

birchmd commented 1 year ago

I think it is fine to document that owner_is does not work as a view call. If a user wants to check the owner in a view call then they should use owner_get instead (assuming that works).