atlas_config_program_client/generated/instructions/
store.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6
7use {
8    crate::hooked::ConfigKeys,
9    borsh::{BorshDeserialize, BorshSerialize},
10    kaigan::types::RemainderVec,
11};
12
13/// Accounts.
14#[derive(Debug)]
15pub struct Store {
16    /// The config account to be modified.
17    /// Must sign during the first call to `store` to initialize the account,
18    /// or if no signers are configured in the config data.
19    pub config_account: (crate::atlas_program::pubkey::Pubkey, bool),
20}
21
22impl Store {
23    pub fn instruction(
24        &self,
25        args: StoreInstructionArgs,
26    ) -> crate::atlas_program::instruction::Instruction {
27        self.instruction_with_remaining_accounts(args, &[])
28    }
29    #[allow(clippy::vec_init_then_push)]
30    pub fn instruction_with_remaining_accounts(
31        &self,
32        args: StoreInstructionArgs,
33        remaining_accounts: &[crate::atlas_program::instruction::AccountMeta],
34    ) -> crate::atlas_program::instruction::Instruction {
35        let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
36        accounts.push(crate::atlas_program::instruction::AccountMeta::new(
37            self.config_account.0,
38            self.config_account.1,
39        ));
40        accounts.extend_from_slice(remaining_accounts);
41        let mut data = borsh::to_vec(&StoreInstructionData::new()).unwrap();
42        let mut args = borsh::to_vec(&args).unwrap();
43        data.append(&mut args);
44
45        crate::atlas_program::instruction::Instruction {
46            program_id: crate::ATLAS_CONFIG_ID,
47            accounts,
48            data,
49        }
50    }
51}
52
53#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
54#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
55pub struct StoreInstructionData {}
56
57impl StoreInstructionData {
58    pub fn new() -> Self {
59        Self {}
60    }
61}
62
63impl Default for StoreInstructionData {
64    fn default() -> Self {
65        Self::new()
66    }
67}
68
69#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
70#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
71pub struct StoreInstructionArgs {
72    pub keys: ConfigKeys,
73    pub data: RemainderVec<u8>,
74}
75
76/// Instruction builder for `Store`.
77///
78/// ### Accounts:
79///
80///   0. `[writable, signer]` config_account
81#[derive(Clone, Debug, Default)]
82pub struct StoreBuilder {
83    config_account: Option<(crate::atlas_program::pubkey::Pubkey, bool)>,
84    keys: Option<ConfigKeys>,
85    data: Option<RemainderVec<u8>>,
86    __remaining_accounts: Vec<crate::atlas_program::instruction::AccountMeta>,
87}
88
89impl StoreBuilder {
90    pub fn new() -> Self {
91        Self::default()
92    }
93    /// The config account to be modified.
94    /// Must sign during the first call to `store` to initialize the account,
95    /// or if no signers are configured in the config data.
96    #[inline(always)]
97    pub fn config_account(
98        &mut self,
99        config_account: crate::atlas_program::pubkey::Pubkey,
100        as_signer: bool,
101    ) -> &mut Self {
102        self.config_account = Some((config_account, as_signer));
103        self
104    }
105    #[inline(always)]
106    pub fn keys(&mut self, keys: ConfigKeys) -> &mut Self {
107        self.keys = Some(keys);
108        self
109    }
110    #[inline(always)]
111    pub fn data(&mut self, data: RemainderVec<u8>) -> &mut Self {
112        self.data = Some(data);
113        self
114    }
115    /// Add an additional account to the instruction.
116    #[inline(always)]
117    pub fn add_remaining_account(
118        &mut self,
119        account: crate::atlas_program::instruction::AccountMeta,
120    ) -> &mut Self {
121        self.__remaining_accounts.push(account);
122        self
123    }
124    /// Add additional accounts to the instruction.
125    #[inline(always)]
126    pub fn add_remaining_accounts(
127        &mut self,
128        accounts: &[crate::atlas_program::instruction::AccountMeta],
129    ) -> &mut Self {
130        self.__remaining_accounts.extend_from_slice(accounts);
131        self
132    }
133    #[allow(clippy::clone_on_copy)]
134    pub fn instruction(&self) -> crate::atlas_program::instruction::Instruction {
135        let accounts = Store {
136            config_account: self.config_account.expect("config_account is not set"),
137        };
138        let args = StoreInstructionArgs {
139            keys: self.keys.clone().expect("keys is not set"),
140            data: self.data.clone().expect("data is not set"),
141        };
142
143        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
144    }
145}
146
147/// `store` CPI accounts.
148pub struct StoreCpiAccounts<'a, 'b> {
149    /// The config account to be modified.
150    /// Must sign during the first call to `store` to initialize the account,
151    /// or if no signers are configured in the config data.
152    pub config_account: (&'b crate::atlas_program::account_info::AccountInfo<'a>, bool),
153}
154
155/// `store` CPI instruction.
156pub struct StoreCpi<'a, 'b> {
157    /// The program to invoke.
158    pub __program: &'b crate::atlas_program::account_info::AccountInfo<'a>,
159    /// The config account to be modified.
160    /// Must sign during the first call to `store` to initialize the account,
161    /// or if no signers are configured in the config data.
162    pub config_account: (&'b crate::atlas_program::account_info::AccountInfo<'a>, bool),
163    /// The arguments for the instruction.
164    pub __args: StoreInstructionArgs,
165}
166
167impl<'a, 'b> StoreCpi<'a, 'b> {
168    pub fn new(
169        program: &'b crate::atlas_program::account_info::AccountInfo<'a>,
170        accounts: StoreCpiAccounts<'a, 'b>,
171        args: StoreInstructionArgs,
172    ) -> Self {
173        Self {
174            __program: program,
175            config_account: accounts.config_account,
176            __args: args,
177        }
178    }
179    #[inline(always)]
180    pub fn invoke(&self) -> crate::atlas_program::entrypoint::ProgramResult {
181        self.invoke_signed_with_remaining_accounts(&[], &[])
182    }
183    #[inline(always)]
184    pub fn invoke_with_remaining_accounts(
185        &self,
186        remaining_accounts: &[(
187            &'b crate::atlas_program::account_info::AccountInfo<'a>,
188            bool,
189            bool,
190        )],
191    ) -> crate::atlas_program::entrypoint::ProgramResult {
192        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
193    }
194    #[inline(always)]
195    pub fn invoke_signed(
196        &self,
197        signers_seeds: &[&[&[u8]]],
198    ) -> crate::atlas_program::entrypoint::ProgramResult {
199        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
200    }
201    #[allow(clippy::clone_on_copy)]
202    #[allow(clippy::vec_init_then_push)]
203    pub fn invoke_signed_with_remaining_accounts(
204        &self,
205        signers_seeds: &[&[&[u8]]],
206        remaining_accounts: &[(
207            &'b crate::atlas_program::account_info::AccountInfo<'a>,
208            bool,
209            bool,
210        )],
211    ) -> crate::atlas_program::entrypoint::ProgramResult {
212        let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
213        accounts.push(crate::atlas_program::instruction::AccountMeta::new(
214            *self.config_account.0.key,
215            self.config_account.1,
216        ));
217        remaining_accounts.iter().for_each(|remaining_account| {
218            accounts.push(crate::atlas_program::instruction::AccountMeta {
219                pubkey: *remaining_account.0.key,
220                is_signer: remaining_account.1,
221                is_writable: remaining_account.2,
222            })
223        });
224        let mut data = borsh::to_vec(&StoreInstructionData::new()).unwrap();
225        let mut args = borsh::to_vec(&self.__args).unwrap();
226        data.append(&mut args);
227
228        let instruction = crate::atlas_program::instruction::Instruction {
229            program_id: crate::ATLAS_CONFIG_ID,
230            accounts,
231            data,
232        };
233        let mut account_infos = Vec::with_capacity(2 + remaining_accounts.len());
234        account_infos.push(self.__program.clone());
235        account_infos.push(self.config_account.0.clone());
236        remaining_accounts
237            .iter()
238            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
239
240        if signers_seeds.is_empty() {
241            crate::atlas_program::program::invoke(&instruction, &account_infos)
242        } else {
243            crate::atlas_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
244        }
245    }
246}
247
248/// Instruction builder for `Store` via CPI.
249///
250/// ### Accounts:
251///
252///   0. `[writable, signer]` config_account
253#[derive(Clone, Debug)]
254pub struct StoreCpiBuilder<'a, 'b> {
255    instruction: Box<StoreCpiBuilderInstruction<'a, 'b>>,
256}
257
258impl<'a, 'b> StoreCpiBuilder<'a, 'b> {
259    pub fn new(program: &'b crate::atlas_program::account_info::AccountInfo<'a>) -> Self {
260        let instruction = Box::new(StoreCpiBuilderInstruction {
261            __program: program,
262            config_account: None,
263            keys: None,
264            data: None,
265            __remaining_accounts: Vec::new(),
266        });
267        Self { instruction }
268    }
269    /// The config account to be modified.
270    /// Must sign during the first call to `store` to initialize the account,
271    /// or if no signers are configured in the config data.
272    #[inline(always)]
273    pub fn config_account(
274        &mut self,
275        config_account: &'b crate::atlas_program::account_info::AccountInfo<'a>,
276        as_signer: bool,
277    ) -> &mut Self {
278        self.instruction.config_account = Some((config_account, as_signer));
279        self
280    }
281    #[inline(always)]
282    pub fn keys(&mut self, keys: ConfigKeys) -> &mut Self {
283        self.instruction.keys = Some(keys);
284        self
285    }
286    #[inline(always)]
287    pub fn data(&mut self, data: RemainderVec<u8>) -> &mut Self {
288        self.instruction.data = Some(data);
289        self
290    }
291    /// Add an additional account to the instruction.
292    #[inline(always)]
293    pub fn add_remaining_account(
294        &mut self,
295        account: &'b crate::atlas_program::account_info::AccountInfo<'a>,
296        is_writable: bool,
297        is_signer: bool,
298    ) -> &mut Self {
299        self.instruction
300            .__remaining_accounts
301            .push((account, is_writable, is_signer));
302        self
303    }
304    /// Add additional accounts to the instruction.
305    ///
306    /// Each account is represented by a tuple of the `AccountInfo`, a `bool`
307    /// indicating whether the account is writable or not, and a `bool`
308    /// indicating whether the account is a signer or not.
309    #[inline(always)]
310    pub fn add_remaining_accounts(
311        &mut self,
312        accounts: &[(
313            &'b crate::atlas_program::account_info::AccountInfo<'a>,
314            bool,
315            bool,
316        )],
317    ) -> &mut Self {
318        self.instruction
319            .__remaining_accounts
320            .extend_from_slice(accounts);
321        self
322    }
323    #[inline(always)]
324    pub fn invoke(&self) -> crate::atlas_program::entrypoint::ProgramResult {
325        self.invoke_signed(&[])
326    }
327    #[allow(clippy::clone_on_copy)]
328    #[allow(clippy::vec_init_then_push)]
329    pub fn invoke_signed(
330        &self,
331        signers_seeds: &[&[&[u8]]],
332    ) -> crate::atlas_program::entrypoint::ProgramResult {
333        let args = StoreInstructionArgs {
334            keys: self.instruction.keys.clone().expect("keys is not set"),
335            data: self.instruction.data.clone().expect("data is not set"),
336        };
337        let instruction = StoreCpi {
338            __program: self.instruction.__program,
339
340            config_account: self
341                .instruction
342                .config_account
343                .expect("config_account is not set"),
344            __args: args,
345        };
346        instruction.invoke_signed_with_remaining_accounts(
347            signers_seeds,
348            &self.instruction.__remaining_accounts,
349        )
350    }
351}
352
353#[derive(Clone, Debug)]
354struct StoreCpiBuilderInstruction<'a, 'b> {
355    __program: &'b crate::atlas_program::account_info::AccountInfo<'a>,
356    config_account: Option<(&'b crate::atlas_program::account_info::AccountInfo<'a>, bool)>,
357    keys: Option<ConfigKeys>,
358    data: Option<RemainderVec<u8>>,
359    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
360    __remaining_accounts: Vec<(
361        &'b crate::atlas_program::account_info::AccountInfo<'a>,
362        bool,
363        bool,
364    )>,
365}