commerce_program_client/generated/instructions/
emit_event.rs1use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11pub const EMIT_EVENT_DISCRIMINATOR: u8 = 228;
12
13#[derive(Debug)]
15pub struct EmitEvent {
16
17
18 pub event_authority: solana_pubkey::Pubkey,
19 }
20
21impl EmitEvent {
22 pub fn instruction(&self) -> solana_instruction::Instruction {
23 self.instruction_with_remaining_accounts(&[])
24 }
25 #[allow(clippy::arithmetic_side_effects)]
26 #[allow(clippy::vec_init_then_push)]
27 pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
28 let mut accounts = Vec::with_capacity(1+ remaining_accounts.len());
29 accounts.push(solana_instruction::AccountMeta::new_readonly(
30 self.event_authority,
31 true
32 ));
33 accounts.extend_from_slice(remaining_accounts);
34 let data = borsh::to_vec(&EmitEventInstructionData::new()).unwrap();
35
36 solana_instruction::Instruction {
37 program_id: crate::COMMERCE_PROGRAM_ID,
38 accounts,
39 data,
40 }
41 }
42}
43
44#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
45#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
46 pub struct EmitEventInstructionData {
47 discriminator: u8,
48 }
49
50impl EmitEventInstructionData {
51 pub fn new() -> Self {
52 Self {
53 discriminator: 228,
54 }
55 }
56}
57
58impl Default for EmitEventInstructionData {
59 fn default() -> Self {
60 Self::new()
61 }
62}
63
64
65
66#[derive(Clone, Debug, Default)]
72pub struct EmitEventBuilder {
73 event_authority: Option<solana_pubkey::Pubkey>,
74 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
75}
76
77impl EmitEventBuilder {
78 pub fn new() -> Self {
79 Self::default()
80 }
81 #[inline(always)]
83 pub fn event_authority(&mut self, event_authority: solana_pubkey::Pubkey) -> &mut Self {
84 self.event_authority = Some(event_authority);
85 self
86 }
87 #[inline(always)]
89 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
90 self.__remaining_accounts.push(account);
91 self
92 }
93 #[inline(always)]
95 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
96 self.__remaining_accounts.extend_from_slice(accounts);
97 self
98 }
99 #[allow(clippy::clone_on_copy)]
100 pub fn instruction(&self) -> solana_instruction::Instruction {
101 let accounts = EmitEvent {
102 event_authority: self.event_authority.unwrap_or(solana_pubkey::pubkey!("3VSJP7faqLk6MbCaNtMYc2Y8S8hMXRsZ5cBcwh1fjMH1")),
103 };
104
105 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
106 }
107}
108
109 pub struct EmitEventCpiAccounts<'a, 'b> {
111
112
113 pub event_authority: &'b solana_account_info::AccountInfo<'a>,
114 }
115
116pub struct EmitEventCpi<'a, 'b> {
118 pub __program: &'b solana_account_info::AccountInfo<'a>,
120
121
122 pub event_authority: &'b solana_account_info::AccountInfo<'a>,
123 }
124
125impl<'a, 'b> EmitEventCpi<'a, 'b> {
126 pub fn new(
127 program: &'b solana_account_info::AccountInfo<'a>,
128 accounts: EmitEventCpiAccounts<'a, 'b>,
129 ) -> Self {
130 Self {
131 __program: program,
132 event_authority: accounts.event_authority,
133 }
134 }
135 #[inline(always)]
136 pub fn invoke(&self) -> solana_program_error::ProgramResult {
137 self.invoke_signed_with_remaining_accounts(&[], &[])
138 }
139 #[inline(always)]
140 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
141 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
142 }
143 #[inline(always)]
144 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
145 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
146 }
147 #[allow(clippy::arithmetic_side_effects)]
148 #[allow(clippy::clone_on_copy)]
149 #[allow(clippy::vec_init_then_push)]
150 pub fn invoke_signed_with_remaining_accounts(
151 &self,
152 signers_seeds: &[&[&[u8]]],
153 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
154 ) -> solana_program_error::ProgramResult {
155 let mut accounts = Vec::with_capacity(1+ remaining_accounts.len());
156 accounts.push(solana_instruction::AccountMeta::new_readonly(
157 *self.event_authority.key,
158 true
159 ));
160 remaining_accounts.iter().for_each(|remaining_account| {
161 accounts.push(solana_instruction::AccountMeta {
162 pubkey: *remaining_account.0.key,
163 is_signer: remaining_account.1,
164 is_writable: remaining_account.2,
165 })
166 });
167 let data = borsh::to_vec(&EmitEventInstructionData::new()).unwrap();
168
169 let instruction = solana_instruction::Instruction {
170 program_id: crate::COMMERCE_PROGRAM_ID,
171 accounts,
172 data,
173 };
174 let mut account_infos = Vec::with_capacity(2 + remaining_accounts.len());
175 account_infos.push(self.__program.clone());
176 account_infos.push(self.event_authority.clone());
177 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
178
179 if signers_seeds.is_empty() {
180 solana_cpi::invoke(&instruction, &account_infos)
181 } else {
182 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
183 }
184 }
185}
186
187#[derive(Clone, Debug)]
193pub struct EmitEventCpiBuilder<'a, 'b> {
194 instruction: Box<EmitEventCpiBuilderInstruction<'a, 'b>>,
195}
196
197impl<'a, 'b> EmitEventCpiBuilder<'a, 'b> {
198 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
199 let instruction = Box::new(EmitEventCpiBuilderInstruction {
200 __program: program,
201 event_authority: None,
202 __remaining_accounts: Vec::new(),
203 });
204 Self { instruction }
205 }
206 #[inline(always)]
207 pub fn event_authority(&mut self, event_authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
208 self.instruction.event_authority = Some(event_authority);
209 self
210 }
211 #[inline(always)]
213 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
214 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
215 self
216 }
217 #[inline(always)]
222 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
223 self.instruction.__remaining_accounts.extend_from_slice(accounts);
224 self
225 }
226 #[inline(always)]
227 pub fn invoke(&self) -> solana_program_error::ProgramResult {
228 self.invoke_signed(&[])
229 }
230 #[allow(clippy::clone_on_copy)]
231 #[allow(clippy::vec_init_then_push)]
232 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
233 let instruction = EmitEventCpi {
234 __program: self.instruction.__program,
235
236 event_authority: self.instruction.event_authority.expect("event_authority is not set"),
237 };
238 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
239 }
240}
241
242#[derive(Clone, Debug)]
243struct EmitEventCpiBuilderInstruction<'a, 'b> {
244 __program: &'b solana_account_info::AccountInfo<'a>,
245 event_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
246 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
248}
249