coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.59k stars 1.32k forks source link

feature: event bytes to enum of events (rust) #2885

Closed ckamm closed 5 months ago

ckamm commented 6 months ago

It would be helpful if anchor generated a function like:

fn event_from_bytes(bytes: &[u8]) -> Result<Event>;

enum Event {
    Event1(Event1),
    // one for each struct tagged #[event]
}

That finds the matching discriminator and then parses the event.

acheroncrypto commented 6 months ago

It's a bit difficult to get all events in the current codegen, but this can easily be implemented with the new declare-program! macro. Would that be sufficient, or do you need the function to be generated with the program codegen?

Lou-Kamades commented 6 months ago

the new macro is probably sufficient imo