Skip to main content

satrush_client/generated/instructions/
migrate_miner.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//!
7
8use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11pub const MIGRATE_MINER_DISCRIMINATOR: [u8; 8] = [12, 226, 213, 146, 253, 206, 95, 81];
12
13/// Accounts.
14#[derive(Debug)]
15pub struct MigrateMiner {
16            /// The config admin; also funds the miner's rent top-up.
17
18    
19              
20          pub authority: solana_address::Address,
21          
22              
23          pub satrush_config: solana_address::Address,
24                /// The v1 miner to extend. Unchecked because v1 data cannot deserialize
25/// into the v2 `Miner` struct.
26
27    
28              
29          pub miner: solana_address::Address,
30          
31              
32          pub system_program: solana_address::Address,
33      }
34
35impl MigrateMiner {
36  pub fn instruction(&self) -> solana_instruction::Instruction {
37    self.instruction_with_remaining_accounts(&[])
38  }
39  #[allow(clippy::arithmetic_side_effects)]
40  #[allow(clippy::vec_init_then_push)]
41  pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
42    let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
43                            accounts.push(solana_instruction::AccountMeta::new(
44            self.authority,
45            true
46          ));
47                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
48            self.satrush_config,
49            false
50          ));
51                                          accounts.push(solana_instruction::AccountMeta::new(
52            self.miner,
53            false
54          ));
55                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
56            self.system_program,
57            false
58          ));
59                      accounts.extend_from_slice(remaining_accounts);
60    let data = MigrateMinerInstructionData::new().try_to_vec().unwrap();
61    
62    solana_instruction::Instruction {
63      program_id: crate::SATRUSH_ID,
64      accounts,
65      data,
66    }
67  }
68}
69
70#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
71 pub struct MigrateMinerInstructionData {
72            discriminator: [u8; 8],
73      }
74
75impl MigrateMinerInstructionData {
76  pub fn new() -> Self {
77    Self {
78                        discriminator: [12, 226, 213, 146, 253, 206, 95, 81],
79                  }
80  }
81
82    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
83    borsh::to_vec(self)
84  }
85  }
86
87impl Default for MigrateMinerInstructionData {
88  fn default() -> Self {
89    Self::new()
90  }
91}
92
93
94
95/// Instruction builder for `MigrateMiner`.
96///
97/// ### Accounts:
98///
99                      ///   0. `[writable, signer]` authority
100          ///   1. `[]` satrush_config
101                ///   2. `[writable]` miner
102                ///   3. `[optional]` system_program (default to `11111111111111111111111111111111`)
103#[derive(Clone, Debug, Default)]
104pub struct MigrateMinerBuilder {
105            authority: Option<solana_address::Address>,
106                satrush_config: Option<solana_address::Address>,
107                miner: Option<solana_address::Address>,
108                system_program: Option<solana_address::Address>,
109                __remaining_accounts: Vec<solana_instruction::AccountMeta>,
110}
111
112impl MigrateMinerBuilder {
113  pub fn new() -> Self {
114    Self::default()
115  }
116            /// The config admin; also funds the miner's rent top-up.
117#[inline(always)]
118    pub fn authority(&mut self, authority: solana_address::Address) -> &mut Self {
119                        self.authority = Some(authority);
120                    self
121    }
122            #[inline(always)]
123    pub fn satrush_config(&mut self, satrush_config: solana_address::Address) -> &mut Self {
124                        self.satrush_config = Some(satrush_config);
125                    self
126    }
127            /// The v1 miner to extend. Unchecked because v1 data cannot deserialize
128/// into the v2 `Miner` struct.
129#[inline(always)]
130    pub fn miner(&mut self, miner: solana_address::Address) -> &mut Self {
131                        self.miner = Some(miner);
132                    self
133    }
134            /// `[optional account, default to '11111111111111111111111111111111']`
135#[inline(always)]
136    pub fn system_program(&mut self, system_program: solana_address::Address) -> &mut Self {
137                        self.system_program = Some(system_program);
138                    self
139    }
140            /// Add an additional account to the instruction.
141  #[inline(always)]
142  pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
143    self.__remaining_accounts.push(account);
144    self
145  }
146  /// Add additional accounts to the instruction.
147  #[inline(always)]
148  pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
149    self.__remaining_accounts.extend_from_slice(accounts);
150    self
151  }
152  #[allow(clippy::clone_on_copy)]
153  pub fn instruction(&self) -> solana_instruction::Instruction {
154    let accounts = MigrateMiner {
155                              authority: self.authority.expect("authority is not set"),
156                                        satrush_config: self.satrush_config.expect("satrush_config is not set"),
157                                        miner: self.miner.expect("miner is not set"),
158                                        system_program: self.system_program.unwrap_or(solana_address::address!("11111111111111111111111111111111")),
159                      };
160    
161    accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
162  }
163}
164
165  /// `migrate_miner` CPI accounts.
166  pub struct MigrateMinerCpiAccounts<'a, 'b> {
167                  /// The config admin; also funds the miner's rent top-up.
168
169      
170                    
171              pub authority: &'b solana_account_info::AccountInfo<'a>,
172                
173                    
174              pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
175                        /// The v1 miner to extend. Unchecked because v1 data cannot deserialize
176/// into the v2 `Miner` struct.
177
178      
179                    
180              pub miner: &'b solana_account_info::AccountInfo<'a>,
181                
182                    
183              pub system_program: &'b solana_account_info::AccountInfo<'a>,
184            }
185
186/// `migrate_miner` CPI instruction.
187pub struct MigrateMinerCpi<'a, 'b> {
188  /// The program to invoke.
189  pub __program: &'b solana_account_info::AccountInfo<'a>,
190            /// The config admin; also funds the miner's rent top-up.
191
192    
193              
194          pub authority: &'b solana_account_info::AccountInfo<'a>,
195          
196              
197          pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
198                /// The v1 miner to extend. Unchecked because v1 data cannot deserialize
199/// into the v2 `Miner` struct.
200
201    
202              
203          pub miner: &'b solana_account_info::AccountInfo<'a>,
204          
205              
206          pub system_program: &'b solana_account_info::AccountInfo<'a>,
207        }
208
209impl<'a, 'b> MigrateMinerCpi<'a, 'b> {
210  pub fn new(
211    program: &'b solana_account_info::AccountInfo<'a>,
212          accounts: MigrateMinerCpiAccounts<'a, 'b>,
213          ) -> Self {
214    Self {
215      __program: program,
216              authority: accounts.authority,
217              satrush_config: accounts.satrush_config,
218              miner: accounts.miner,
219              system_program: accounts.system_program,
220                }
221  }
222  #[inline(always)]
223  pub fn invoke(&self) -> solana_program_error::ProgramResult {
224    self.invoke_signed_with_remaining_accounts(&[], &[])
225  }
226  #[inline(always)]
227  pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
228    self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
229  }
230  #[inline(always)]
231  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
232    self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
233  }
234  #[allow(clippy::arithmetic_side_effects)]
235  #[allow(clippy::clone_on_copy)]
236  #[allow(clippy::vec_init_then_push)]
237  pub fn invoke_signed_with_remaining_accounts(
238    &self,
239    signers_seeds: &[&[&[u8]]],
240    remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
241  ) -> solana_program_error::ProgramResult {
242    let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
243                            accounts.push(solana_instruction::AccountMeta::new(
244            *self.authority.key,
245            true
246          ));
247                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
248            *self.satrush_config.key,
249            false
250          ));
251                                          accounts.push(solana_instruction::AccountMeta::new(
252            *self.miner.key,
253            false
254          ));
255                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
256            *self.system_program.key,
257            false
258          ));
259                      remaining_accounts.iter().for_each(|remaining_account| {
260      accounts.push(solana_instruction::AccountMeta {
261          pubkey: *remaining_account.0.key,
262          is_signer: remaining_account.1,
263          is_writable: remaining_account.2,
264      })
265    });
266    let data = MigrateMinerInstructionData::new().try_to_vec().unwrap();
267    
268    let instruction = solana_instruction::Instruction {
269      program_id: crate::SATRUSH_ID,
270      accounts,
271      data,
272    };
273    let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
274    account_infos.push(self.__program.clone());
275                  account_infos.push(self.authority.clone());
276                        account_infos.push(self.satrush_config.clone());
277                        account_infos.push(self.miner.clone());
278                        account_infos.push(self.system_program.clone());
279              remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
280
281    if signers_seeds.is_empty() {
282      solana_cpi::invoke(&instruction, &account_infos)
283    } else {
284      solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
285    }
286  }
287}
288
289/// Instruction builder for `MigrateMiner` via CPI.
290///
291/// ### Accounts:
292///
293                      ///   0. `[writable, signer]` authority
294          ///   1. `[]` satrush_config
295                ///   2. `[writable]` miner
296          ///   3. `[]` system_program
297#[derive(Clone, Debug)]
298pub struct MigrateMinerCpiBuilder<'a, 'b> {
299  instruction: Box<MigrateMinerCpiBuilderInstruction<'a, 'b>>,
300}
301
302impl<'a, 'b> MigrateMinerCpiBuilder<'a, 'b> {
303  pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
304    let instruction = Box::new(MigrateMinerCpiBuilderInstruction {
305      __program: program,
306              authority: None,
307              satrush_config: None,
308              miner: None,
309              system_program: None,
310                                __remaining_accounts: Vec::new(),
311    });
312    Self { instruction }
313  }
314      /// The config admin; also funds the miner's rent top-up.
315#[inline(always)]
316    pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
317                        self.instruction.authority = Some(authority);
318                    self
319    }
320      #[inline(always)]
321    pub fn satrush_config(&mut self, satrush_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
322                        self.instruction.satrush_config = Some(satrush_config);
323                    self
324    }
325      /// The v1 miner to extend. Unchecked because v1 data cannot deserialize
326/// into the v2 `Miner` struct.
327#[inline(always)]
328    pub fn miner(&mut self, miner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
329                        self.instruction.miner = Some(miner);
330                    self
331    }
332      #[inline(always)]
333    pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
334                        self.instruction.system_program = Some(system_program);
335                    self
336    }
337            /// Add an additional account to the instruction.
338  #[inline(always)]
339  pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
340    self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
341    self
342  }
343  /// Add additional accounts to the instruction.
344  ///
345  /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
346  /// and a `bool` indicating whether the account is a signer or not.
347  #[inline(always)]
348  pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
349    self.instruction.__remaining_accounts.extend_from_slice(accounts);
350    self
351  }
352  #[inline(always)]
353  pub fn invoke(&self) -> solana_program_error::ProgramResult {
354    self.invoke_signed(&[])
355  }
356  #[allow(clippy::clone_on_copy)]
357  #[allow(clippy::vec_init_then_push)]
358  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
359        let instruction = MigrateMinerCpi {
360        __program: self.instruction.__program,
361                  
362          authority: self.instruction.authority.expect("authority is not set"),
363                  
364          satrush_config: self.instruction.satrush_config.expect("satrush_config is not set"),
365                  
366          miner: self.instruction.miner.expect("miner is not set"),
367                  
368          system_program: self.instruction.system_program.expect("system_program is not set"),
369                    };
370    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
371  }
372}
373
374#[derive(Clone, Debug)]
375struct MigrateMinerCpiBuilderInstruction<'a, 'b> {
376  __program: &'b solana_account_info::AccountInfo<'a>,
377            authority: Option<&'b solana_account_info::AccountInfo<'a>>,
378                satrush_config: Option<&'b solana_account_info::AccountInfo<'a>>,
379                miner: Option<&'b solana_account_info::AccountInfo<'a>>,
380                system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
381                /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
382  __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
383}
384