nifty_asset_interface/generated/instructions/
lock.rs1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct Lock {
13 pub asset: solana_program::pubkey::Pubkey,
15 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#[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 #[inline(always)]
77 pub fn asset(&mut self, asset: solana_program::pubkey::Pubkey) -> &mut Self {
78 self.asset = Some(asset);
79 self
80 }
81 #[inline(always)]
83 pub fn signer(&mut self, signer: solana_program::pubkey::Pubkey) -> &mut Self {
84 self.signer = Some(signer);
85 self
86 }
87 #[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 #[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
116pub struct LockCpiAccounts<'a, 'b> {
118 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
120 pub signer: &'b solana_program::account_info::AccountInfo<'a>,
122}
123
124pub struct LockCpi<'a, 'b> {
126 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
128 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
130 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
217pub 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 #[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 #[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 #[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 #[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 __remaining_accounts: Vec<(
313 &'b solana_program::account_info::AccountInfo<'a>,
314 bool,
315 bool,
316 )>,
317}