nifty_asset_interface/generated/instructions/
handover.rs1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct Handover {
13 pub asset: solana_program::pubkey::Pubkey,
15 pub authority: solana_program::pubkey::Pubkey,
17 pub new_authority: solana_program::pubkey::Pubkey,
19}
20
21impl Handover {
22 pub fn instruction(&self) -> solana_program::instruction::Instruction {
23 self.instruction_with_remaining_accounts(&[])
24 }
25 #[allow(clippy::vec_init_then_push)]
26 pub fn instruction_with_remaining_accounts(
27 &self,
28 remaining_accounts: &[solana_program::instruction::AccountMeta],
29 ) -> solana_program::instruction::Instruction {
30 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
31 accounts.push(solana_program::instruction::AccountMeta::new(
32 self.asset, true,
33 ));
34 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
35 self.authority,
36 true,
37 ));
38 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
39 self.new_authority,
40 true,
41 ));
42 accounts.extend_from_slice(remaining_accounts);
43 let data = HandoverInstructionData::new().try_to_vec().unwrap();
44
45 solana_program::instruction::Instruction {
46 program_id: crate::INTERFACE_ID,
47 accounts,
48 data,
49 }
50 }
51}
52
53#[derive(BorshDeserialize, BorshSerialize)]
54struct HandoverInstructionData {
55 discriminator: u8,
56}
57
58impl HandoverInstructionData {
59 fn new() -> Self {
60 Self { discriminator: 15 }
61 }
62}
63
64#[derive(Default)]
72pub struct HandoverBuilder {
73 asset: Option<solana_program::pubkey::Pubkey>,
74 authority: Option<solana_program::pubkey::Pubkey>,
75 new_authority: Option<solana_program::pubkey::Pubkey>,
76 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
77}
78
79impl HandoverBuilder {
80 pub fn new() -> Self {
81 Self::default()
82 }
83 #[inline(always)]
85 pub fn asset(&mut self, asset: solana_program::pubkey::Pubkey) -> &mut Self {
86 self.asset = Some(asset);
87 self
88 }
89 #[inline(always)]
91 pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
92 self.authority = Some(authority);
93 self
94 }
95 #[inline(always)]
97 pub fn new_authority(&mut self, new_authority: solana_program::pubkey::Pubkey) -> &mut Self {
98 self.new_authority = Some(new_authority);
99 self
100 }
101 #[inline(always)]
103 pub fn add_remaining_account(
104 &mut self,
105 account: solana_program::instruction::AccountMeta,
106 ) -> &mut Self {
107 self.__remaining_accounts.push(account);
108 self
109 }
110 #[inline(always)]
112 pub fn add_remaining_accounts(
113 &mut self,
114 accounts: &[solana_program::instruction::AccountMeta],
115 ) -> &mut Self {
116 self.__remaining_accounts.extend_from_slice(accounts);
117 self
118 }
119 #[allow(clippy::clone_on_copy)]
120 pub fn instruction(&self) -> solana_program::instruction::Instruction {
121 let accounts = Handover {
122 asset: self.asset.expect("asset is not set"),
123 authority: self.authority.expect("authority is not set"),
124 new_authority: self.new_authority.expect("new_authority is not set"),
125 };
126
127 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
128 }
129}
130
131pub struct HandoverCpiAccounts<'a, 'b> {
133 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
135 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
137 pub new_authority: &'b solana_program::account_info::AccountInfo<'a>,
139}
140
141pub struct HandoverCpi<'a, 'b> {
143 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
145 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
147 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
149 pub new_authority: &'b solana_program::account_info::AccountInfo<'a>,
151}
152
153impl<'a, 'b> HandoverCpi<'a, 'b> {
154 pub fn new(
155 program: &'b solana_program::account_info::AccountInfo<'a>,
156 accounts: HandoverCpiAccounts<'a, 'b>,
157 ) -> Self {
158 Self {
159 __program: program,
160 asset: accounts.asset,
161 authority: accounts.authority,
162 new_authority: accounts.new_authority,
163 }
164 }
165 #[inline(always)]
166 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
167 self.invoke_signed_with_remaining_accounts(&[], &[])
168 }
169 #[inline(always)]
170 pub fn invoke_with_remaining_accounts(
171 &self,
172 remaining_accounts: &[(
173 &'b solana_program::account_info::AccountInfo<'a>,
174 bool,
175 bool,
176 )],
177 ) -> solana_program::entrypoint::ProgramResult {
178 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
179 }
180 #[inline(always)]
181 pub fn invoke_signed(
182 &self,
183 signers_seeds: &[&[&[u8]]],
184 ) -> solana_program::entrypoint::ProgramResult {
185 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
186 }
187 #[allow(clippy::clone_on_copy)]
188 #[allow(clippy::vec_init_then_push)]
189 pub fn invoke_signed_with_remaining_accounts(
190 &self,
191 signers_seeds: &[&[&[u8]]],
192 remaining_accounts: &[(
193 &'b solana_program::account_info::AccountInfo<'a>,
194 bool,
195 bool,
196 )],
197 ) -> solana_program::entrypoint::ProgramResult {
198 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
199 accounts.push(solana_program::instruction::AccountMeta::new(
200 *self.asset.key,
201 true,
202 ));
203 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
204 *self.authority.key,
205 true,
206 ));
207 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
208 *self.new_authority.key,
209 true,
210 ));
211 remaining_accounts.iter().for_each(|remaining_account| {
212 accounts.push(solana_program::instruction::AccountMeta {
213 pubkey: *remaining_account.0.key,
214 is_signer: remaining_account.1,
215 is_writable: remaining_account.2,
216 })
217 });
218 let data = HandoverInstructionData::new().try_to_vec().unwrap();
219
220 let instruction = solana_program::instruction::Instruction {
221 program_id: crate::INTERFACE_ID,
222 accounts,
223 data,
224 };
225 let mut account_infos = Vec::with_capacity(3 + 1 + remaining_accounts.len());
226 account_infos.push(self.__program.clone());
227 account_infos.push(self.asset.clone());
228 account_infos.push(self.authority.clone());
229 account_infos.push(self.new_authority.clone());
230 remaining_accounts
231 .iter()
232 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
233
234 if signers_seeds.is_empty() {
235 solana_program::program::invoke(&instruction, &account_infos)
236 } else {
237 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
238 }
239 }
240}
241
242pub struct HandoverCpiBuilder<'a, 'b> {
250 instruction: Box<HandoverCpiBuilderInstruction<'a, 'b>>,
251}
252
253impl<'a, 'b> HandoverCpiBuilder<'a, 'b> {
254 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
255 let instruction = Box::new(HandoverCpiBuilderInstruction {
256 __program: program,
257 asset: None,
258 authority: None,
259 new_authority: None,
260 __remaining_accounts: Vec::new(),
261 });
262 Self { instruction }
263 }
264 #[inline(always)]
266 pub fn asset(&mut self, asset: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
267 self.instruction.asset = Some(asset);
268 self
269 }
270 #[inline(always)]
272 pub fn authority(
273 &mut self,
274 authority: &'b solana_program::account_info::AccountInfo<'a>,
275 ) -> &mut Self {
276 self.instruction.authority = Some(authority);
277 self
278 }
279 #[inline(always)]
281 pub fn new_authority(
282 &mut self,
283 new_authority: &'b solana_program::account_info::AccountInfo<'a>,
284 ) -> &mut Self {
285 self.instruction.new_authority = Some(new_authority);
286 self
287 }
288 #[inline(always)]
290 pub fn add_remaining_account(
291 &mut self,
292 account: &'b solana_program::account_info::AccountInfo<'a>,
293 is_writable: bool,
294 is_signer: bool,
295 ) -> &mut Self {
296 self.instruction
297 .__remaining_accounts
298 .push((account, is_writable, is_signer));
299 self
300 }
301 #[inline(always)]
306 pub fn add_remaining_accounts(
307 &mut self,
308 accounts: &[(
309 &'b solana_program::account_info::AccountInfo<'a>,
310 bool,
311 bool,
312 )],
313 ) -> &mut Self {
314 self.instruction
315 .__remaining_accounts
316 .extend_from_slice(accounts);
317 self
318 }
319 #[inline(always)]
320 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
321 self.invoke_signed(&[])
322 }
323 #[allow(clippy::clone_on_copy)]
324 #[allow(clippy::vec_init_then_push)]
325 pub fn invoke_signed(
326 &self,
327 signers_seeds: &[&[&[u8]]],
328 ) -> solana_program::entrypoint::ProgramResult {
329 let instruction = HandoverCpi {
330 __program: self.instruction.__program,
331
332 asset: self.instruction.asset.expect("asset is not set"),
333
334 authority: self.instruction.authority.expect("authority is not set"),
335
336 new_authority: self
337 .instruction
338 .new_authority
339 .expect("new_authority is not set"),
340 };
341 instruction.invoke_signed_with_remaining_accounts(
342 signers_seeds,
343 &self.instruction.__remaining_accounts,
344 )
345 }
346}
347
348struct HandoverCpiBuilderInstruction<'a, 'b> {
349 __program: &'b solana_program::account_info::AccountInfo<'a>,
350 asset: Option<&'b solana_program::account_info::AccountInfo<'a>>,
351 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
352 new_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
353 __remaining_accounts: Vec<(
355 &'b solana_program::account_info::AccountInfo<'a>,
356 bool,
357 bool,
358 )>,
359}