-
Notifications
You must be signed in to change notification settings - Fork 258
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
feat: Blacklist attributes not to forward to ContractExt methods #952
Conversation
Another open PR that's about to use attributes with use darling::util::PathList;
use darling::FromMeta;
#[derive(Default, FromMeta, Clone, Debug)]
pub struct MacroConfig {
pub events: Option<EventsConfig>,
pub blacklist_ext_fn_attrs: Option<PathList>,
}
pub struct EventsConfig {
standard: String,
another_config_value: T, // darling supports many types
} Using #[near_bindgen(events(standard = "nepXXX", another_config_value = "..."))]
pub enum MyEvents { /* ... */ }
#[near_bindgen(blacklist_ext_fn_attrs(some_plugin_attr))]
impl Contract { /* ... */ } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine. A little unfortunate to add a dependency like this for something that doesn't affect the vast majority, but this seems reasonable if it enables more tooling.
None of the _Ext
methods should require the attributes in general, possibly an oversight there. I'm not sure what developers would prefer in general.
I can't think of any attribute that a developer would want to keep, seems like there might be another option of just removing the attributes and if developers mention breakages we could do something like this? Just seems like a bit of an unintuitive pattern to have the #[near_bindgen(blacklist_ext_fn_attrs(attr1, attr2))]
pattern. @itegulov wdyt?
Also, one other thought is that blocklist
naming would be more clear, just as an alternative to consider.
Yes, also blacklisting is an extra step that has to be taken by contract developers that use plugin attributes. So not having to do this because attributes aren't forwarded to |
Closing this since it shouldn't be required anymore now that #959 is merged. If there'll ever be a need to allow contracts dev to whitelist some attributes to forward to |
Background
Smart contract plugins like
near-plugins
use attribute macros to modify contract methods.For example,
access_control_any
in the following snippet injects code that panics if the caller is not a grantee ofRole::A
orRole::B
:Problem
#[near_bindgen]
will create a structContractExt
with:Proposed solution
Make
#[near_bindgen]
accept a blacklist of attributes which it should not forward to methods of the automatically generated*Ext
type. This PR addsblacklist_ext_fn_attrs
for this purpose:Implementation overview
MacroConfig
which allows configuring the behavior of macros.ContractExt
methods are created.Backwards compatibility
This should be backwards compatible since:
near_bindgen
are ignored (ref. Remove unused tokens in compilation test #951).#[near_bindgen]
without attributes will result in using the default value ofMacroConfig
which does not alter behavior.Thoughts / Question
Maybe function attributes shouldn't be forwarded to
Ext
methods by default? In that case, it should be possible to turn the blacklist feature proposed here into a whitelist feature. Though that would be a breaking change.