Skip to main content

nifty_asset_interface/generated/instructions/
handover.rs

1//! This code was AUTOGENERATED using the kinobi library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun kinobi to update it.
4//!
5//! [https://github.com/metaplex-foundation/kinobi]
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11/// Accounts.
12pub struct Handover {
13    /// Asset account
14    pub asset: solana_program::pubkey::Pubkey,
15    /// The authority of the asset
16    pub authority: solana_program::pubkey::Pubkey,
17    /// The new authority of the asset
18    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/// Instruction builder for `Handover`.
65///
66/// ### Accounts:
67///
68///   0. `[writable, signer]` asset
69///   1. `[signer]` authority
70///   2. `[signer]` new_authority
71#[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    /// Asset account
84    #[inline(always)]
85    pub fn asset(&mut self, asset: solana_program::pubkey::Pubkey) -> &mut Self {
86        self.asset = Some(asset);
87        self
88    }
89    /// The authority of the asset
90    #[inline(always)]
91    pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
92        self.authority = Some(authority);
93        self
94    }
95    /// The new authority of the asset
96    #[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    /// Add an aditional account to the instruction.
102    #[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    /// Add additional accounts to the instruction.
111    #[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
131/// `handover` CPI accounts.
132pub struct HandoverCpiAccounts<'a, 'b> {
133    /// Asset account
134    pub asset: &'b solana_program::account_info::AccountInfo<'a>,
135    /// The authority of the asset
136    pub authority: &'b solana_program::account_info::AccountInfo<'a>,
137    /// The new authority of the asset
138    pub new_authority: &'b solana_program::account_info::AccountInfo<'a>,
139}
140
141/// `handover` CPI instruction.
142pub struct HandoverCpi<'a, 'b> {
143    /// The program to invoke.
144    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
145    /// Asset account
146    pub asset: &'b solana_program::account_info::AccountInfo<'a>,
147    /// The authority of the asset
148    pub authority: &'b solana_program::account_info::AccountInfo<'a>,
149    /// The new authority of the asset
150    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
242/// Instruction builder for `Handover` via CPI.
243///
244/// ### Accounts:
245///
246///   0. `[writable, signer]` asset
247///   1. `[signer]` authority
248///   2. `[signer]` new_authority
249pub 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    /// Asset account
265    #[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    /// The authority of the asset
271    #[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    /// The new authority of the asset
280    #[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    /// Add an additional account to the instruction.
289    #[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    /// Add additional accounts to the instruction.
302    ///
303    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
304    /// and a `bool` indicating whether the account is a signer or not.
305    #[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    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
354    __remaining_accounts: Vec<(
355        &'b solana_program::account_info::AccountInfo<'a>,
356        bool,
357        bool,
358    )>,
359}