-
Notifications
You must be signed in to change notification settings - Fork 428
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
Shared external event definitions #809
Comments
Hi, the topic design of the current event seems to be related to the contract, and may also need to be considered. #[cfg(not(feature = "ink-as-dependency"))]
const _: () = {
impl ::ink_env::Topics for Transfer {
type RemainingTopics = [::ink_env::topics::state::HasRemainingTopics; 4usize];
fn topics<E, B>(
&self,
builder: ::ink_env::topics::TopicsBuilder<
::ink_env::topics::state::Uninit,
E,
B,
>,
) -> <B as ::ink_env::topics::TopicsBuilderBackend<E>>::Output
where
E: ::ink_env::Environment,
B: ::ink_env::topics::TopicsBuilderBackend<E>,
{
builder
.build::<Self>()
.push_topic::<::ink_env::topics::PrefixedValue<[u8; 15usize]>>(
&::ink_env::topics::PrefixedValue {
value: b"Erc20::Transfer",
prefix: b"",
},
)
.push_topic::<::ink_env::topics::PrefixedValue<Option<AccountId>>>(
&::ink_env::topics::PrefixedValue {
value: &self.from,
prefix: b"Erc20::Transfer::from",
},
)
.push_topic::<::ink_env::topics::PrefixedValue<Option<AccountId>>>(
&::ink_env::topics::PrefixedValue {
value: &self.to,
prefix: b"Erc20::Transfer::to",
},
)
.push_topic::<::ink_env::topics::PrefixedValue<Balance>>(
&::ink_env::topics::PrefixedValue {
value: &self.value,
prefix: b"Erc20::Transfer::value",
},
)
.finish()
}
}
}; These |
@Robbepop What do you think about the idea to change the way have we generated the metadata? I created an example of how we can add events to the metadata if they were defined in a separate crate. |
To achieve user-friendly events they should be independent. At the moment the user can define events only in the body of the contract(under We have to reason for that limitation:
Solution:
|
Due to ink!'s design it is not possible to share event definitions between multiple contracts since events can only be defined in the ink! module scope directly.
In order to more extensively use the upcoming trait features we want to make it possible for users to define events to be used in multiple contracts.
For this we will need a new attribute macro
#[ink::event_definition]
or just a derive macro#[derive(ink::Event)]
that will setup everything required for ink! events. There will be some initial limitations. E.g. events can only beenum
orstruct
with certain properties.However, this will allow to define events in some library and use the same event definition in many ink! smart contract or trait definitions.
The text was updated successfully, but these errors were encountered: