What helped me to get a glimpse of this is to cargo expand
a simple lib.rs file.
I added two events
to the flipper contract:
#[ink(event)]
pub struct Created {
value: bool,
}
#[ink(event)]
pub struct Flipped {
#[ink(topic)]
value: bool,
}
I executed cargo expand --lib > expanded_lib.rs
and somewhere you can find the code where the topics
are pushed (push_topic
) to the TopicsBuilderBackend
.
const _: () = {
impl ::ink::env::Topics for Created {
type RemainingTopics = [::ink::env::topics::state::HasRemainingTopics; 1usize];
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; 13usize]>,
>(
&::ink::env::topics::PrefixedValue {
value: b"Test::Created",
prefix: b"",
},
)
.finish()
}
}
};
const _: () = {
impl ::ink::env::Topics for Flipped {
type RemainingTopics = [::ink::env::topics::state::HasRemainingTopics; 2usize];
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; 13usize]>,
>(
&::ink::env::topics::PrefixedValue {
value: b"Test::Flipped",
prefix: b"",
},
)
.push_topic::<
::ink::env::topics::PrefixedValue<bool>,
>(
&::ink::env::topics::PrefixedValue {
value: &self.value,
prefix: b"Test::Flipped::value",
},
)
.finish()
}
}
};
The first topic is the PrefixedValue
of the event itself:
PrefixedValue { value: b"Test::Created", prefix: b"" }
The second topic is the actual #[ink(topic)]
in the struct:
PrefixedValue { value: &self.value, prefix: b"Test::Flipped::value" }
When we add the anonymous
attribute we get something like:
const _: () = {
impl ::ink::env::Topics for Created {
type RemainingTopics = ::ink::env::topics::state::NoRemainingTopics;
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>().finish()
}
}
};
Where you can see that no topics are pushed to TopicsBuilderBackend
.
Additional info: erc20 tests for emitted events.
Hope this helps.