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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use ;
use Idl;
// fn gen_event(idl: &Idl) -> proc_macro2::TokenStream {
// let variants = idl
// .events
// .iter()
// .map(|ev| format_ident!("{}", ev.name))
// .map(|name| quote! { #name(#name) });
// let if_statements = idl.events.iter().map(|ev| {
// let name = format_ident!("{}", ev.name);
// quote! {
// if value.starts_with(#name::DISCRIMINATOR) {
// return #name::try_from_slice(&value[#name::DISCRIMINATOR.len()..])
// .map(Self::#name)
// .map_err(Into::into)
// }
// }
// });
// quote! {
// /// 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 {
// #(#variants,)*
// }
// 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> {
// Self::try_from(bytes)
// }
// }
// impl TryFrom<&[u8]> for Event {
// type Error = arch_satellite_lang::error::Error;
// fn try_from(value: &[u8]) -> Result<Self> {
// #(#if_statements)*
// Err(ProgramError::InvalidArgument.into())
// }
// }
// }
// }