-
Notifications
You must be signed in to change notification settings - Fork 249
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
Private view methods #1026
Comments
I did a bit a of testing now with this contract: #[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize)]
pub struct Contract {
message: String,
}
#[near_bindgen]
impl Contract {
pub fn get_greeting(&self) -> String {
return self.private_get_greeting();
}
#[private] pub fn private_get_greeting(&self) -> String {
return self.message.clone();
}
} And I found that I can call |
This is because you're not using the For reference, the code I'm referring to: pub fn get_greeting() -> Promise {
Self::ext(env::current_account_id()).private_get_greeting()
}
#[private] pub fn private_get_greeting(&self) -> String {
"test".to_string()
} Where I don't think there is an issue, since these can both just be called in a transaction rather than a view call, but the semantics are a bit muddied because |
Thanks for clarifying @austinabell ! I managed to reproduce the error with my code when calling I'm still not 100% clear on why the error doesn't occur when calling Btw while testing this I ran some circles, because I didn't realize that the |
@agostbiro
I only trust the source code: near-sdk-rs/near-sdk-macros/src/core_impl/code_generator/item_impl_info.rs Lines 36 to 52 in e4cb471
|
Ah got it, thanks @frol ! So the conclusion seems to me that there are no changes needed regarding private view functions. Did I understand that correctly? |
@agostbiro Well, given that there is no use for private view functions (they will just fail), it would be great to forbid them at compilation time ( |
@frol yeah it's a very small change. I tried it now and the following tests are failing after disallowing private view methods: Failing examplesnear-sdk-rs/examples/callback-results/src/lib.rs Lines 27 to 28 in c39fba3
near-sdk-rs/examples/callback-results/src/lib.rs Lines 49 to 55 in c39fba3
near-sdk-rs/examples/cross-contract-calls/high-level/src/lib.rs Lines 26 to 27 in c39fba3
Failing unit tests
With this many tests failing I'm a little concerned about breaking a lot of code in the wild if we disallow private view methods, but if that's unfounded I'm happy to adjust the tests. |
@frol the main issue here is that a lot of contracts in the wild have methods that are view according to their |
The purpose of this issue is to follow up the conversation from #890 and #1025 on private view methods. I quote here the comments to make it easier to overview. Related issue: #937.
In #890 @itegulov asked:
In #890 @austinabell replied:
In #1025 @agostbiro wrote:
In #1025 @itegulov replied:
The text was updated successfully, but these errors were encountered: