1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
extern crate proc_macro;
use quote::quote;
use syn::parse_macro_input;

#[proc_macro_attribute]
pub fn event(
    _args: proc_macro::TokenStream,
    input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
    let event_strct = parse_macro_input!(input as syn::ItemEnum);
    let event_name = &event_strct.ident;
    let (impl_gen, type_gen, where_clause) = event_strct.generics.split_for_impl();

    proc_macro::TokenStream::from({
        quote! {
            #[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)]
            #event_strct

            #[automatically_derived]
            impl #impl_gen #event_name #type_gen #where_clause {

                pub fn wrap<'info>(&self, hpl_events_program: AccountInfo<'info>, program: Pubkey) -> ProgramResult {
                    invoke(
                        &spl_noop::instruction(
                            vec![crate::id().try_to_vec().unwrap(), self.try_to_vec().unwrap()].concat(),
                        ),
                        &[hpl_events_program],
                    )
                }

            }
        }
    })
}