Add autogenerated Event type inside the utils module:
/// An enum that includes all events of the declared program as a tuple variant.
///
/// See [`Self::try_from_bytes`] to create an instance from bytes.
pub enum Event {
SomeEvent(SomeEvent),
OtherEvent(OtherEvent),
}
impl Event {
/// Try to create an event based on the given bytes.
///
/// This method returns an error if the discriminator of the given bytes don't match
/// with any of the existing events, or if the deserialization fails.
pub fn try_from_bytes(bytes: &[u8]) -> Result<Self> {
// ...
}
}
Problem
It's not easy to create an unknown event from bytes as described in https://github.com/coral-xyz/anchor/issues/2885.
Summary of changes
utils
module to thedeclare_program!
macro.Add autogenerated
Event
type inside theutils
module:Resolves https://github.com/coral-xyz/anchor/issues/2885