tensor_marketplace/generated/instructions/
cancel_bid.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/kinobi-so/kinobi>
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11/// Accounts.
12pub struct CancelBid {
13    pub bid_state: solana_program::pubkey::Pubkey,
14
15    pub owner: solana_program::pubkey::Pubkey,
16
17    pub system_program: solana_program::pubkey::Pubkey,
18
19    pub marketplace_program: solana_program::pubkey::Pubkey,
20
21    pub rent_destination: solana_program::pubkey::Pubkey,
22}
23
24impl CancelBid {
25    pub fn instruction(&self) -> solana_program::instruction::Instruction {
26        self.instruction_with_remaining_accounts(&[])
27    }
28    #[allow(clippy::vec_init_then_push)]
29    pub fn instruction_with_remaining_accounts(
30        &self,
31        remaining_accounts: &[solana_program::instruction::AccountMeta],
32    ) -> solana_program::instruction::Instruction {
33        let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
34        accounts.push(solana_program::instruction::AccountMeta::new(
35            self.bid_state,
36            false,
37        ));
38        accounts.push(solana_program::instruction::AccountMeta::new(
39            self.owner, true,
40        ));
41        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
42            self.system_program,
43            false,
44        ));
45        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
46            self.marketplace_program,
47            false,
48        ));
49        accounts.push(solana_program::instruction::AccountMeta::new(
50            self.rent_destination,
51            false,
52        ));
53        accounts.extend_from_slice(remaining_accounts);
54        let data = CancelBidInstructionData::new().try_to_vec().unwrap();
55
56        solana_program::instruction::Instruction {
57            program_id: crate::TENSOR_MARKETPLACE_ID,
58            accounts,
59            data,
60        }
61    }
62}
63
64#[derive(BorshDeserialize, BorshSerialize)]
65pub struct CancelBidInstructionData {
66    discriminator: [u8; 8],
67}
68
69impl CancelBidInstructionData {
70    pub fn new() -> Self {
71        Self {
72            discriminator: [40, 243, 190, 217, 208, 253, 86, 206],
73        }
74    }
75}
76
77impl Default for CancelBidInstructionData {
78    fn default() -> Self {
79        Self::new()
80    }
81}
82
83/// Instruction builder for `CancelBid`.
84///
85/// ### Accounts:
86///
87///   0. `[writable]` bid_state
88///   1. `[writable, signer]` owner
89///   2. `[optional]` system_program (default to `11111111111111111111111111111111`)
90///   3. `[optional]` marketplace_program (default to `TCMPhJdwDryooaGtiocG1u3xcYbRpiJzb283XfCZsDp`)
91///   4. `[writable]` rent_destination
92#[derive(Clone, Debug, Default)]
93pub struct CancelBidBuilder {
94    bid_state: Option<solana_program::pubkey::Pubkey>,
95    owner: Option<solana_program::pubkey::Pubkey>,
96    system_program: Option<solana_program::pubkey::Pubkey>,
97    marketplace_program: Option<solana_program::pubkey::Pubkey>,
98    rent_destination: Option<solana_program::pubkey::Pubkey>,
99    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
100}
101
102impl CancelBidBuilder {
103    pub fn new() -> Self {
104        Self::default()
105    }
106    #[inline(always)]
107    pub fn bid_state(&mut self, bid_state: solana_program::pubkey::Pubkey) -> &mut Self {
108        self.bid_state = Some(bid_state);
109        self
110    }
111    #[inline(always)]
112    pub fn owner(&mut self, owner: solana_program::pubkey::Pubkey) -> &mut Self {
113        self.owner = Some(owner);
114        self
115    }
116    /// `[optional account, default to '11111111111111111111111111111111']`
117    #[inline(always)]
118    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
119        self.system_program = Some(system_program);
120        self
121    }
122    /// `[optional account, default to 'TCMPhJdwDryooaGtiocG1u3xcYbRpiJzb283XfCZsDp']`
123    #[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 rent_destination(
133        &mut self,
134        rent_destination: solana_program::pubkey::Pubkey,
135    ) -> &mut Self {
136        self.rent_destination = Some(rent_destination);
137        self
138    }
139    /// Add an aditional account to the instruction.
140    #[inline(always)]
141    pub fn add_remaining_account(
142        &mut self,
143        account: solana_program::instruction::AccountMeta,
144    ) -> &mut Self {
145        self.__remaining_accounts.push(account);
146        self
147    }
148    /// Add additional accounts to the instruction.
149    #[inline(always)]
150    pub fn add_remaining_accounts(
151        &mut self,
152        accounts: &[solana_program::instruction::AccountMeta],
153    ) -> &mut Self {
154        self.__remaining_accounts.extend_from_slice(accounts);
155        self
156    }
157    #[allow(clippy::clone_on_copy)]
158    pub fn instruction(&self) -> solana_program::instruction::Instruction {
159        let accounts = CancelBid {
160            bid_state: self.bid_state.expect("bid_state is not set"),
161            owner: self.owner.expect("owner is not set"),
162            system_program: self
163                .system_program
164                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
165            marketplace_program: self.marketplace_program.unwrap_or(solana_program::pubkey!(
166                "TCMPhJdwDryooaGtiocG1u3xcYbRpiJzb283XfCZsDp"
167            )),
168            rent_destination: self.rent_destination.expect("rent_destination is not set"),
169        };
170
171        accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
172    }
173}
174
175/// `cancel_bid` CPI accounts.
176pub struct CancelBidCpiAccounts<'a, 'b> {
177    pub bid_state: &'b solana_program::account_info::AccountInfo<'a>,
178
179    pub owner: &'b solana_program::account_info::AccountInfo<'a>,
180
181    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
182
183    pub marketplace_program: &'b solana_program::account_info::AccountInfo<'a>,
184
185    pub rent_destination: &'b solana_program::account_info::AccountInfo<'a>,
186}
187
188/// `cancel_bid` CPI instruction.
189pub struct CancelBidCpi<'a, 'b> {
190    /// The program to invoke.
191    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
192
193    pub bid_state: &'b solana_program::account_info::AccountInfo<'a>,
194
195    pub owner: &'b solana_program::account_info::AccountInfo<'a>,
196
197    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
198
199    pub marketplace_program: &'b solana_program::account_info::AccountInfo<'a>,
200
201    pub rent_destination: &'b solana_program::account_info::AccountInfo<'a>,
202}
203
204impl<'a, 'b> CancelBidCpi<'a, 'b> {
205    pub fn new(
206        program: &'b solana_program::account_info::AccountInfo<'a>,
207        accounts: CancelBidCpiAccounts<'a, 'b>,
208    ) -> Self {
209        Self {
210            __program: program,
211            bid_state: accounts.bid_state,
212            owner: accounts.owner,
213            system_program: accounts.system_program,
214            marketplace_program: accounts.marketplace_program,
215            rent_destination: accounts.rent_destination,
216        }
217    }
218    #[inline(always)]
219    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
220        self.invoke_signed_with_remaining_accounts(&[], &[])
221    }
222    #[inline(always)]
223    pub fn invoke_with_remaining_accounts(
224        &self,
225        remaining_accounts: &[(
226            &'b solana_program::account_info::AccountInfo<'a>,
227            bool,
228            bool,
229        )],
230    ) -> solana_program::entrypoint::ProgramResult {
231        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
232    }
233    #[inline(always)]
234    pub fn invoke_signed(
235        &self,
236        signers_seeds: &[&[&[u8]]],
237    ) -> solana_program::entrypoint::ProgramResult {
238        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
239    }
240    #[allow(clippy::clone_on_copy)]
241    #[allow(clippy::vec_init_then_push)]
242    pub fn invoke_signed_with_remaining_accounts(
243        &self,
244        signers_seeds: &[&[&[u8]]],
245        remaining_accounts: &[(
246            &'b solana_program::account_info::AccountInfo<'a>,
247            bool,
248            bool,
249        )],
250    ) -> solana_program::entrypoint::ProgramResult {
251        let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
252        accounts.push(solana_program::instruction::AccountMeta::new(
253            *self.bid_state.key,
254            false,
255        ));
256        accounts.push(solana_program::instruction::AccountMeta::new(
257            *self.owner.key,
258            true,
259        ));
260        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
261            *self.system_program.key,
262            false,
263        ));
264        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
265            *self.marketplace_program.key,
266            false,
267        ));
268        accounts.push(solana_program::instruction::AccountMeta::new(
269            *self.rent_destination.key,
270            false,
271        ));
272        remaining_accounts.iter().for_each(|remaining_account| {
273            accounts.push(solana_program::instruction::AccountMeta {
274                pubkey: *remaining_account.0.key,
275                is_signer: remaining_account.1,
276                is_writable: remaining_account.2,
277            })
278        });
279        let data = CancelBidInstructionData::new().try_to_vec().unwrap();
280
281        let instruction = solana_program::instruction::Instruction {
282            program_id: crate::TENSOR_MARKETPLACE_ID,
283            accounts,
284            data,
285        };
286        let mut account_infos = Vec::with_capacity(5 + 1 + remaining_accounts.len());
287        account_infos.push(self.__program.clone());
288        account_infos.push(self.bid_state.clone());
289        account_infos.push(self.owner.clone());
290        account_infos.push(self.system_program.clone());
291        account_infos.push(self.marketplace_program.clone());
292        account_infos.push(self.rent_destination.clone());
293        remaining_accounts
294            .iter()
295            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
296
297        if signers_seeds.is_empty() {
298            solana_program::program::invoke(&instruction, &account_infos)
299        } else {
300            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
301        }
302    }
303}
304
305/// Instruction builder for `CancelBid` via CPI.
306///
307/// ### Accounts:
308///
309///   0. `[writable]` bid_state
310///   1. `[writable, signer]` owner
311///   2. `[]` system_program
312///   3. `[]` marketplace_program
313///   4. `[writable]` rent_destination
314#[derive(Clone, Debug)]
315pub struct CancelBidCpiBuilder<'a, 'b> {
316    instruction: Box<CancelBidCpiBuilderInstruction<'a, 'b>>,
317}
318
319impl<'a, 'b> CancelBidCpiBuilder<'a, 'b> {
320    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
321        let instruction = Box::new(CancelBidCpiBuilderInstruction {
322            __program: program,
323            bid_state: None,
324            owner: None,
325            system_program: None,
326            marketplace_program: None,
327            rent_destination: None,
328            __remaining_accounts: Vec::new(),
329        });
330        Self { instruction }
331    }
332    #[inline(always)]
333    pub fn bid_state(
334        &mut self,
335        bid_state: &'b solana_program::account_info::AccountInfo<'a>,
336    ) -> &mut Self {
337        self.instruction.bid_state = Some(bid_state);
338        self
339    }
340    #[inline(always)]
341    pub fn owner(&mut self, owner: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
342        self.instruction.owner = Some(owner);
343        self
344    }
345    #[inline(always)]
346    pub fn system_program(
347        &mut self,
348        system_program: &'b solana_program::account_info::AccountInfo<'a>,
349    ) -> &mut Self {
350        self.instruction.system_program = Some(system_program);
351        self
352    }
353    #[inline(always)]
354    pub fn marketplace_program(
355        &mut self,
356        marketplace_program: &'b solana_program::account_info::AccountInfo<'a>,
357    ) -> &mut Self {
358        self.instruction.marketplace_program = Some(marketplace_program);
359        self
360    }
361    #[inline(always)]
362    pub fn rent_destination(
363        &mut self,
364        rent_destination: &'b solana_program::account_info::AccountInfo<'a>,
365    ) -> &mut Self {
366        self.instruction.rent_destination = Some(rent_destination);
367        self
368    }
369    /// Add an additional account to the instruction.
370    #[inline(always)]
371    pub fn add_remaining_account(
372        &mut self,
373        account: &'b solana_program::account_info::AccountInfo<'a>,
374        is_writable: bool,
375        is_signer: bool,
376    ) -> &mut Self {
377        self.instruction
378            .__remaining_accounts
379            .push((account, is_writable, is_signer));
380        self
381    }
382    /// Add additional accounts to the instruction.
383    ///
384    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
385    /// and a `bool` indicating whether the account is a signer or not.
386    #[inline(always)]
387    pub fn add_remaining_accounts(
388        &mut self,
389        accounts: &[(
390            &'b solana_program::account_info::AccountInfo<'a>,
391            bool,
392            bool,
393        )],
394    ) -> &mut Self {
395        self.instruction
396            .__remaining_accounts
397            .extend_from_slice(accounts);
398        self
399    }
400    #[inline(always)]
401    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
402        self.invoke_signed(&[])
403    }
404    #[allow(clippy::clone_on_copy)]
405    #[allow(clippy::vec_init_then_push)]
406    pub fn invoke_signed(
407        &self,
408        signers_seeds: &[&[&[u8]]],
409    ) -> solana_program::entrypoint::ProgramResult {
410        let instruction = CancelBidCpi {
411            __program: self.instruction.__program,
412
413            bid_state: self.instruction.bid_state.expect("bid_state is not set"),
414
415            owner: self.instruction.owner.expect("owner is not set"),
416
417            system_program: self
418                .instruction
419                .system_program
420                .expect("system_program is not set"),
421
422            marketplace_program: self
423                .instruction
424                .marketplace_program
425                .expect("marketplace_program is not set"),
426
427            rent_destination: self
428                .instruction
429                .rent_destination
430                .expect("rent_destination is not set"),
431        };
432        instruction.invoke_signed_with_remaining_accounts(
433            signers_seeds,
434            &self.instruction.__remaining_accounts,
435        )
436    }
437}
438
439#[derive(Clone, Debug)]
440struct CancelBidCpiBuilderInstruction<'a, 'b> {
441    __program: &'b solana_program::account_info::AccountInfo<'a>,
442    bid_state: Option<&'b solana_program::account_info::AccountInfo<'a>>,
443    owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
444    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
445    marketplace_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
446    rent_destination: Option<&'b solana_program::account_info::AccountInfo<'a>>,
447    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
448    __remaining_accounts: Vec<(
449        &'b solana_program::account_info::AccountInfo<'a>,
450        bool,
451        bool,
452    )>,
453}