carbon_token_2022_decoder/instructions/
initialize_default_account_state.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 crate::types::AccountState;
8use carbon_core::account_utils::next_account;
9use carbon_core::borsh;
10use carbon_core::deserialize::ArrangeAccounts;
11use carbon_core::deserialize::CarbonDeserialize;
12use carbon_core::CarbonDeserialize;
13
14/// Initialize a new mint with the default state for new Accounts.
15///
16/// Fails if the mint has already been initialized, so must be called before
17/// `InitializeMint`.
18///
19/// The mint must have exactly enough space allocated for the base mint (82
20/// bytes), plus 83 bytes of padding, 1 byte reserved for the account type,
21/// then space required for this extension, plus any others.
22#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
23#[derive(Debug, Clone, borsh::BorshSerialize, CarbonDeserialize, PartialEq)]
24pub struct InitializeDefaultAccountState {
25    pub default_account_state_discriminator: u8,
26    /// The state each new token account should start with.
27    pub state: AccountState,
28}
29
30#[derive(Debug, Clone, PartialEq)]
31#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
32pub struct InitializeDefaultAccountStateInstructionAccounts {
33    pub mint: solana_pubkey::Pubkey,
34    pub remaining: Vec<solana_instruction::AccountMeta>,
35}
36
37impl InitializeDefaultAccountState {
38    pub fn decode(data: &[u8]) -> Option<Self> {
39        if data.len() < 2 {
40            return None;
41        }
42        let discriminator = &data[0..1];
43        if discriminator != [28] {
44            return None;
45        }
46        let default_account_state_discriminator = data[1];
47        if default_account_state_discriminator != 0 {
48            return None;
49        }
50
51        let data_slice = data;
52
53        let data_slice = &data_slice[1..];
54
55        Self::deserialize(data_slice)
56    }
57}
58
59impl ArrangeAccounts for InitializeDefaultAccountState {
60    type ArrangedAccounts = InitializeDefaultAccountStateInstructionAccounts;
61
62    fn arrange_accounts(
63        accounts: &[solana_instruction::AccountMeta],
64    ) -> Option<Self::ArrangedAccounts> {
65        let mut iter = accounts.iter();
66
67        let mint = next_account(&mut iter)?;
68
69        let remaining = iter.as_slice();
70
71        Some(InitializeDefaultAccountStateInstructionAccounts {
72            mint,
73            remaining: remaining.to_vec(),
74        })
75    }
76}