Skip to main content

nifty_asset_interface/generated/instructions/
lock.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 Lock {
13    /// Asset account
14    pub asset: solana_program::pubkey::Pubkey,
15    /// Delegate or owner account
16    pub signer: solana_program::pubkey::Pubkey,
17}
18
19impl Lock {
20    pub fn instruction(&self) -> solana_program::instruction::Instruction {
21        self.instruction_with_remaining_accounts(&[])
22    }
23    #[allow(clippy::vec_init_then_push)]
24    pub fn instruction_with_remaining_accounts(
25        &self,
26        remaining_accounts: &[solana_program::instruction::AccountMeta],
27    ) -> solana_program::instruction::Instruction {
28        let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
29        accounts.push(solana_program::instruction::AccountMeta::new(
30            self.asset, true,
31        ));
32        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
33            self.signer,
34            true,
35        ));
36        accounts.extend_from_slice(remaining_accounts);
37        let data = LockInstructionData::new().try_to_vec().unwrap();
38
39        solana_program::instruction::Instruction {
40            program_id: crate::INTERFACE_ID,
41            accounts,
42            data,
43        }
44    }
45}
46
47#[derive(BorshDeserialize, BorshSerialize)]
48struct LockInstructionData {
49    discriminator: u8,
50}
51
52impl LockInstructionData {
53    fn new() -> Self {
54        Self { discriminator: 5 }
55    }
56}
57
58/// Instruction builder for `Lock`.
59///
60/// ### Accounts:
61///
62///   0. `[writable, signer]` asset
63///   1. `[signer]` signer
64#[derive(Default)]
65pub struct LockBuilder {
66    asset: Option<solana_program::pubkey::Pubkey>,
67    signer: Option<solana_program::pubkey::Pubkey>,
68    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
69}
70
71impl LockBuilder {
72    pub fn new() -> Self {
73        Self::default()
74    }
75    /// Asset account
76    #[inline(always)]
77    pub fn asset(&mut self, asset: solana_program::pubkey::Pubkey) -> &mut Self {
78        self.asset = Some(asset);
79        self
80    }
81    /// Delegate or owner account
82    #[inline(always)]
83    pub fn signer(&mut self, signer: solana_program::pubkey::Pubkey) -> &mut Self {
84        self.signer = Some(signer);
85        self
86    }
87    /// Add an aditional account to the instruction.
88    #[inline(always)]
89    pub fn add_remaining_account(
90        &mut self,
91        account: solana_program::instruction::AccountMeta,
92    ) -> &mut Self {
93        self.__remaining_accounts.push(account);
94        self
95    }
96    /// Add additional accounts to the instruction.
97    #[inline(always)]
98    pub fn add_remaining_accounts(
99        &mut self,
100        accounts: &[solana_program::instruction::AccountMeta],
101    ) -> &mut Self {
102        self.__remaining_accounts.extend_from_slice(accounts);
103        self
104    }
105    #[allow(clippy::clone_on_copy)]
106    pub fn instruction(&self) -> solana_program::instruction::Instruction {
107        let accounts = Lock {
108            asset: self.asset.expect("asset is not set"),
109            signer: self.signer.expect("signer is not set"),
110        };
111
112        accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
113    }
114}
115
116/// `lock` CPI accounts.
117pub struct LockCpiAccounts<'a, 'b> {
118    /// Asset account
119    pub asset: &'b solana_program::account_info::AccountInfo<'a>,
120    /// Delegate or owner account
121    pub signer: &'b solana_program::account_info::AccountInfo<'a>,
122}
123
124/// `lock` CPI instruction.
125pub struct LockCpi<'a, 'b> {
126    /// The program to invoke.
127    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
128    /// Asset account
129    pub asset: &'b solana_program::account_info::AccountInfo<'a>,
130    /// Delegate or owner account
131    pub signer: &'b solana_program::account_info::AccountInfo<'a>,
132}
133
134impl<'a, 'b> LockCpi<'a, 'b> {
135    pub fn new(
136        program: &'b solana_program::account_info::AccountInfo<'a>,
137        accounts: LockCpiAccounts<'a, 'b>,
138    ) -> Self {
139        Self {
140            __program: program,
141            asset: accounts.asset,
142            signer: accounts.signer,
143        }
144    }
145    #[inline(always)]
146    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
147        self.invoke_signed_with_remaining_accounts(&[], &[])
148    }
149    #[inline(always)]
150    pub fn invoke_with_remaining_accounts(
151        &self,
152        remaining_accounts: &[(
153            &'b solana_program::account_info::AccountInfo<'a>,
154            bool,
155            bool,
156        )],
157    ) -> solana_program::entrypoint::ProgramResult {
158        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
159    }
160    #[inline(always)]
161    pub fn invoke_signed(
162        &self,
163        signers_seeds: &[&[&[u8]]],
164    ) -> solana_program::entrypoint::ProgramResult {
165        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
166    }
167    #[allow(clippy::clone_on_copy)]
168    #[allow(clippy::vec_init_then_push)]
169    pub fn invoke_signed_with_remaining_accounts(
170        &self,
171        signers_seeds: &[&[&[u8]]],
172        remaining_accounts: &[(
173            &'b solana_program::account_info::AccountInfo<'a>,
174            bool,
175            bool,
176        )],
177    ) -> solana_program::entrypoint::ProgramResult {
178        let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
179        accounts.push(solana_program::instruction::AccountMeta::new(
180            *self.asset.key,
181            true,
182        ));
183        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
184            *self.signer.key,
185            true,
186        ));
187        remaining_accounts.iter().for_each(|remaining_account| {
188            accounts.push(solana_program::instruction::AccountMeta {
189                pubkey: *remaining_account.0.key,
190                is_signer: remaining_account.1,
191                is_writable: remaining_account.2,
192            })
193        });
194        let data = LockInstructionData::new().try_to_vec().unwrap();
195
196        let instruction = solana_program::instruction::Instruction {
197            program_id: crate::INTERFACE_ID,
198            accounts,
199            data,
200        };
201        let mut account_infos = Vec::with_capacity(2 + 1 + remaining_accounts.len());
202        account_infos.push(self.__program.clone());
203        account_infos.push(self.asset.clone());
204        account_infos.push(self.signer.clone());
205        remaining_accounts
206            .iter()
207            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
208
209        if signers_seeds.is_empty() {
210            solana_program::program::invoke(&instruction, &account_infos)
211        } else {
212            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
213        }
214    }
215}
216
217/// Instruction builder for `Lock` via CPI.
218///
219/// ### Accounts:
220///
221///   0. `[writable, signer]` asset
222///   1. `[signer]` signer
223pub struct LockCpiBuilder<'a, 'b> {
224    instruction: Box<LockCpiBuilderInstruction<'a, 'b>>,
225}
226
227impl<'a, 'b> LockCpiBuilder<'a, 'b> {
228    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
229        let instruction = Box::new(LockCpiBuilderInstruction {
230            __program: program,
231            asset: None,
232            signer: None,
233            __remaining_accounts: Vec::new(),
234        });
235        Self { instruction }
236    }
237    /// Asset account
238    #[inline(always)]
239    pub fn asset(&mut self, asset: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
240        self.instruction.asset = Some(asset);
241        self
242    }
243    /// Delegate or owner account
244    #[inline(always)]
245    pub fn signer(
246        &mut self,
247        signer: &'b solana_program::account_info::AccountInfo<'a>,
248    ) -> &mut Self {
249        self.instruction.signer = Some(signer);
250        self
251    }
252    /// Add an additional account to the instruction.
253    #[inline(always)]
254    pub fn add_remaining_account(
255        &mut self,
256        account: &'b solana_program::account_info::AccountInfo<'a>,
257        is_writable: bool,
258        is_signer: bool,
259    ) -> &mut Self {
260        self.instruction
261            .__remaining_accounts
262            .push((account, is_writable, is_signer));
263        self
264    }
265    /// Add additional accounts to the instruction.
266    ///
267    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
268    /// and a `bool` indicating whether the account is a signer or not.
269    #[inline(always)]
270    pub fn add_remaining_accounts(
271        &mut self,
272        accounts: &[(
273            &'b solana_program::account_info::AccountInfo<'a>,
274            bool,
275            bool,
276        )],
277    ) -> &mut Self {
278        self.instruction
279            .__remaining_accounts
280            .extend_from_slice(accounts);
281        self
282    }
283    #[inline(always)]
284    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
285        self.invoke_signed(&[])
286    }
287    #[allow(clippy::clone_on_copy)]
288    #[allow(clippy::vec_init_then_push)]
289    pub fn invoke_signed(
290        &self,
291        signers_seeds: &[&[&[u8]]],
292    ) -> solana_program::entrypoint::ProgramResult {
293        let instruction = LockCpi {
294            __program: self.instruction.__program,
295
296            asset: self.instruction.asset.expect("asset is not set"),
297
298            signer: self.instruction.signer.expect("signer is not set"),
299        };
300        instruction.invoke_signed_with_remaining_accounts(
301            signers_seeds,
302            &self.instruction.__remaining_accounts,
303        )
304    }
305}
306
307struct LockCpiBuilderInstruction<'a, 'b> {
308    __program: &'b solana_program::account_info::AccountInfo<'a>,
309    asset: Option<&'b solana_program::account_info::AccountInfo<'a>>,
310    signer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
311    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
312    __remaining_accounts: Vec<(
313        &'b solana_program::account_info::AccountInfo<'a>,
314        bool,
315        bool,
316    )>,
317}