Skip to content
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

lang: Add Event utility type to get events from bytes #2897

Merged

Conversation

acheroncrypto
Copy link
Collaborator

Problem

It's not easy to create an unknown event from bytes as described in #2885.

Summary of changes

  • Add utils module to the declare_program! macro.

  • 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> {
            // ...
        }
    }

Resolves #2885

Copy link

vercel bot commented Apr 9, 2024

@acheroncrypto is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@acheroncrypto acheroncrypto merged commit 0be5b00 into coral-xyz:master Apr 9, 2024
47 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: event bytes to enum of events (rust)
1 participant