1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use solana_program::pubkey::Pubkey;
11
12pub struct Edit {
14 pub list_state: solana_program::pubkey::Pubkey,
15
16 pub owner: solana_program::pubkey::Pubkey,
17
18 pub marketplace_program: solana_program::pubkey::Pubkey,
19}
20
21impl Edit {
22 pub fn instruction(
23 &self,
24 args: EditInstructionArgs,
25 ) -> solana_program::instruction::Instruction {
26 self.instruction_with_remaining_accounts(args, &[])
27 }
28 #[allow(clippy::vec_init_then_push)]
29 pub fn instruction_with_remaining_accounts(
30 &self,
31 args: EditInstructionArgs,
32 remaining_accounts: &[solana_program::instruction::AccountMeta],
33 ) -> solana_program::instruction::Instruction {
34 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
35 accounts.push(solana_program::instruction::AccountMeta::new(
36 self.list_state,
37 false,
38 ));
39 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
40 self.owner, true,
41 ));
42 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
43 self.marketplace_program,
44 false,
45 ));
46 accounts.extend_from_slice(remaining_accounts);
47 let mut data = EditInstructionData::new().try_to_vec().unwrap();
48 let mut args = args.try_to_vec().unwrap();
49 data.append(&mut args);
50
51 solana_program::instruction::Instruction {
52 program_id: crate::TENSOR_MARKETPLACE_ID,
53 accounts,
54 data,
55 }
56 }
57}
58
59#[derive(BorshDeserialize, BorshSerialize)]
60pub struct EditInstructionData {
61 discriminator: [u8; 8],
62}
63
64impl EditInstructionData {
65 pub fn new() -> Self {
66 Self {
67 discriminator: [15, 183, 33, 86, 87, 28, 151, 145],
68 }
69 }
70}
71
72impl Default for EditInstructionData {
73 fn default() -> Self {
74 Self::new()
75 }
76}
77
78#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
79#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
80pub struct EditInstructionArgs {
81 pub amount: u64,
82 pub expire_in_sec: Option<u64>,
83 pub currency: Option<Pubkey>,
84 pub private_taker: Option<Pubkey>,
85 pub maker_broker: Option<Pubkey>,
86}
87
88#[derive(Clone, Debug, Default)]
96pub struct EditBuilder {
97 list_state: Option<solana_program::pubkey::Pubkey>,
98 owner: Option<solana_program::pubkey::Pubkey>,
99 marketplace_program: Option<solana_program::pubkey::Pubkey>,
100 amount: Option<u64>,
101 expire_in_sec: Option<u64>,
102 currency: Option<Pubkey>,
103 private_taker: Option<Pubkey>,
104 maker_broker: Option<Pubkey>,
105 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
106}
107
108impl EditBuilder {
109 pub fn new() -> Self {
110 Self::default()
111 }
112 #[inline(always)]
113 pub fn list_state(&mut self, list_state: solana_program::pubkey::Pubkey) -> &mut Self {
114 self.list_state = Some(list_state);
115 self
116 }
117 #[inline(always)]
118 pub fn owner(&mut self, owner: solana_program::pubkey::Pubkey) -> &mut Self {
119 self.owner = Some(owner);
120 self
121 }
122 #[inline(always)]
124 pub fn marketplace_program(
125 &mut self,
126 marketplace_program: solana_program::pubkey::Pubkey,
127 ) -> &mut Self {
128 self.marketplace_program = Some(marketplace_program);
129 self
130 }
131 #[inline(always)]
132 pub fn amount(&mut self, amount: u64) -> &mut Self {
133 self.amount = Some(amount);
134 self
135 }
136 #[inline(always)]
138 pub fn expire_in_sec(&mut self, expire_in_sec: u64) -> &mut Self {
139 self.expire_in_sec = Some(expire_in_sec);
140 self
141 }
142 #[inline(always)]
144 pub fn currency(&mut self, currency: Pubkey) -> &mut Self {
145 self.currency = Some(currency);
146 self
147 }
148 #[inline(always)]
150 pub fn private_taker(&mut self, private_taker: Pubkey) -> &mut Self {
151 self.private_taker = Some(private_taker);
152 self
153 }
154 #[inline(always)]
156 pub fn maker_broker(&mut self, maker_broker: Pubkey) -> &mut Self {
157 self.maker_broker = Some(maker_broker);
158 self
159 }
160 #[inline(always)]
162 pub fn add_remaining_account(
163 &mut self,
164 account: solana_program::instruction::AccountMeta,
165 ) -> &mut Self {
166 self.__remaining_accounts.push(account);
167 self
168 }
169 #[inline(always)]
171 pub fn add_remaining_accounts(
172 &mut self,
173 accounts: &[solana_program::instruction::AccountMeta],
174 ) -> &mut Self {
175 self.__remaining_accounts.extend_from_slice(accounts);
176 self
177 }
178 #[allow(clippy::clone_on_copy)]
179 pub fn instruction(&self) -> solana_program::instruction::Instruction {
180 let accounts = Edit {
181 list_state: self.list_state.expect("list_state is not set"),
182 owner: self.owner.expect("owner is not set"),
183 marketplace_program: self.marketplace_program.unwrap_or(solana_program::pubkey!(
184 "TCMPhJdwDryooaGtiocG1u3xcYbRpiJzb283XfCZsDp"
185 )),
186 };
187 let args = EditInstructionArgs {
188 amount: self.amount.clone().expect("amount is not set"),
189 expire_in_sec: self.expire_in_sec.clone(),
190 currency: self.currency.clone(),
191 private_taker: self.private_taker.clone(),
192 maker_broker: self.maker_broker.clone(),
193 };
194
195 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
196 }
197}
198
199pub struct EditCpiAccounts<'a, 'b> {
201 pub list_state: &'b solana_program::account_info::AccountInfo<'a>,
202
203 pub owner: &'b solana_program::account_info::AccountInfo<'a>,
204
205 pub marketplace_program: &'b solana_program::account_info::AccountInfo<'a>,
206}
207
208pub struct EditCpi<'a, 'b> {
210 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
212
213 pub list_state: &'b solana_program::account_info::AccountInfo<'a>,
214
215 pub owner: &'b solana_program::account_info::AccountInfo<'a>,
216
217 pub marketplace_program: &'b solana_program::account_info::AccountInfo<'a>,
218 pub __args: EditInstructionArgs,
220}
221
222impl<'a, 'b> EditCpi<'a, 'b> {
223 pub fn new(
224 program: &'b solana_program::account_info::AccountInfo<'a>,
225 accounts: EditCpiAccounts<'a, 'b>,
226 args: EditInstructionArgs,
227 ) -> Self {
228 Self {
229 __program: program,
230 list_state: accounts.list_state,
231 owner: accounts.owner,
232 marketplace_program: accounts.marketplace_program,
233 __args: args,
234 }
235 }
236 #[inline(always)]
237 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
238 self.invoke_signed_with_remaining_accounts(&[], &[])
239 }
240 #[inline(always)]
241 pub fn invoke_with_remaining_accounts(
242 &self,
243 remaining_accounts: &[(
244 &'b solana_program::account_info::AccountInfo<'a>,
245 bool,
246 bool,
247 )],
248 ) -> solana_program::entrypoint::ProgramResult {
249 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
250 }
251 #[inline(always)]
252 pub fn invoke_signed(
253 &self,
254 signers_seeds: &[&[&[u8]]],
255 ) -> solana_program::entrypoint::ProgramResult {
256 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
257 }
258 #[allow(clippy::clone_on_copy)]
259 #[allow(clippy::vec_init_then_push)]
260 pub fn invoke_signed_with_remaining_accounts(
261 &self,
262 signers_seeds: &[&[&[u8]]],
263 remaining_accounts: &[(
264 &'b solana_program::account_info::AccountInfo<'a>,
265 bool,
266 bool,
267 )],
268 ) -> solana_program::entrypoint::ProgramResult {
269 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
270 accounts.push(solana_program::instruction::AccountMeta::new(
271 *self.list_state.key,
272 false,
273 ));
274 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
275 *self.owner.key,
276 true,
277 ));
278 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
279 *self.marketplace_program.key,
280 false,
281 ));
282 remaining_accounts.iter().for_each(|remaining_account| {
283 accounts.push(solana_program::instruction::AccountMeta {
284 pubkey: *remaining_account.0.key,
285 is_signer: remaining_account.1,
286 is_writable: remaining_account.2,
287 })
288 });
289 let mut data = EditInstructionData::new().try_to_vec().unwrap();
290 let mut args = self.__args.try_to_vec().unwrap();
291 data.append(&mut args);
292
293 let instruction = solana_program::instruction::Instruction {
294 program_id: crate::TENSOR_MARKETPLACE_ID,
295 accounts,
296 data,
297 };
298 let mut account_infos = Vec::with_capacity(3 + 1 + remaining_accounts.len());
299 account_infos.push(self.__program.clone());
300 account_infos.push(self.list_state.clone());
301 account_infos.push(self.owner.clone());
302 account_infos.push(self.marketplace_program.clone());
303 remaining_accounts
304 .iter()
305 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
306
307 if signers_seeds.is_empty() {
308 solana_program::program::invoke(&instruction, &account_infos)
309 } else {
310 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
311 }
312 }
313}
314
315#[derive(Clone, Debug)]
323pub struct EditCpiBuilder<'a, 'b> {
324 instruction: Box<EditCpiBuilderInstruction<'a, 'b>>,
325}
326
327impl<'a, 'b> EditCpiBuilder<'a, 'b> {
328 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
329 let instruction = Box::new(EditCpiBuilderInstruction {
330 __program: program,
331 list_state: None,
332 owner: None,
333 marketplace_program: None,
334 amount: None,
335 expire_in_sec: None,
336 currency: None,
337 private_taker: None,
338 maker_broker: None,
339 __remaining_accounts: Vec::new(),
340 });
341 Self { instruction }
342 }
343 #[inline(always)]
344 pub fn list_state(
345 &mut self,
346 list_state: &'b solana_program::account_info::AccountInfo<'a>,
347 ) -> &mut Self {
348 self.instruction.list_state = Some(list_state);
349 self
350 }
351 #[inline(always)]
352 pub fn owner(&mut self, owner: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
353 self.instruction.owner = Some(owner);
354 self
355 }
356 #[inline(always)]
357 pub fn marketplace_program(
358 &mut self,
359 marketplace_program: &'b solana_program::account_info::AccountInfo<'a>,
360 ) -> &mut Self {
361 self.instruction.marketplace_program = Some(marketplace_program);
362 self
363 }
364 #[inline(always)]
365 pub fn amount(&mut self, amount: u64) -> &mut Self {
366 self.instruction.amount = Some(amount);
367 self
368 }
369 #[inline(always)]
371 pub fn expire_in_sec(&mut self, expire_in_sec: u64) -> &mut Self {
372 self.instruction.expire_in_sec = Some(expire_in_sec);
373 self
374 }
375 #[inline(always)]
377 pub fn currency(&mut self, currency: Pubkey) -> &mut Self {
378 self.instruction.currency = Some(currency);
379 self
380 }
381 #[inline(always)]
383 pub fn private_taker(&mut self, private_taker: Pubkey) -> &mut Self {
384 self.instruction.private_taker = Some(private_taker);
385 self
386 }
387 #[inline(always)]
389 pub fn maker_broker(&mut self, maker_broker: Pubkey) -> &mut Self {
390 self.instruction.maker_broker = Some(maker_broker);
391 self
392 }
393 #[inline(always)]
395 pub fn add_remaining_account(
396 &mut self,
397 account: &'b solana_program::account_info::AccountInfo<'a>,
398 is_writable: bool,
399 is_signer: bool,
400 ) -> &mut Self {
401 self.instruction
402 .__remaining_accounts
403 .push((account, is_writable, is_signer));
404 self
405 }
406 #[inline(always)]
411 pub fn add_remaining_accounts(
412 &mut self,
413 accounts: &[(
414 &'b solana_program::account_info::AccountInfo<'a>,
415 bool,
416 bool,
417 )],
418 ) -> &mut Self {
419 self.instruction
420 .__remaining_accounts
421 .extend_from_slice(accounts);
422 self
423 }
424 #[inline(always)]
425 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
426 self.invoke_signed(&[])
427 }
428 #[allow(clippy::clone_on_copy)]
429 #[allow(clippy::vec_init_then_push)]
430 pub fn invoke_signed(
431 &self,
432 signers_seeds: &[&[&[u8]]],
433 ) -> solana_program::entrypoint::ProgramResult {
434 let args = EditInstructionArgs {
435 amount: self.instruction.amount.clone().expect("amount is not set"),
436 expire_in_sec: self.instruction.expire_in_sec.clone(),
437 currency: self.instruction.currency.clone(),
438 private_taker: self.instruction.private_taker.clone(),
439 maker_broker: self.instruction.maker_broker.clone(),
440 };
441 let instruction = EditCpi {
442 __program: self.instruction.__program,
443
444 list_state: self.instruction.list_state.expect("list_state is not set"),
445
446 owner: self.instruction.owner.expect("owner is not set"),
447
448 marketplace_program: self
449 .instruction
450 .marketplace_program
451 .expect("marketplace_program is not set"),
452 __args: args,
453 };
454 instruction.invoke_signed_with_remaining_accounts(
455 signers_seeds,
456 &self.instruction.__remaining_accounts,
457 )
458 }
459}
460
461#[derive(Clone, Debug)]
462struct EditCpiBuilderInstruction<'a, 'b> {
463 __program: &'b solana_program::account_info::AccountInfo<'a>,
464 list_state: Option<&'b solana_program::account_info::AccountInfo<'a>>,
465 owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
466 marketplace_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
467 amount: Option<u64>,
468 expire_in_sec: Option<u64>,
469 currency: Option<Pubkey>,
470 private_taker: Option<Pubkey>,
471 maker_broker: Option<Pubkey>,
472 __remaining_accounts: Vec<(
474 &'b solana_program::account_info::AccountInfo<'a>,
475 bool,
476 bool,
477 )>,
478}