carbon_token_2022_decoder/instructions/
initialize_group_pointer.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 carbon_core::account_utils::next_account;
8use carbon_core::borsh;
9use carbon_core::deserialize::ArrangeAccounts;
10use carbon_core::deserialize::CarbonDeserialize;
11use carbon_core::CarbonDeserialize;
12use solana_pubkey::Pubkey;
13
14/// Initialize a new mint with a group pointer
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, PartialEq)]
24pub struct InitializeGroupPointer {
25    pub group_pointer_discriminator: u8,
26    /// The public key for the account that can update the group address.
27    pub authority: Option<Pubkey>,
28    /// The account address that holds the group.
29    pub group_address: Option<Pubkey>,
30}
31
32#[derive(Debug, Clone, borsh::BorshSerialize, CarbonDeserialize, PartialEq)]
33pub struct InitializeGroupPointerDeser {
34    pub group_pointer_discriminator: u8,
35    pub authority: spl_pod::optional_keys::OptionalNonZeroPubkey,
36    pub group_address: spl_pod::optional_keys::OptionalNonZeroPubkey,
37}
38
39#[derive(Debug, Clone, PartialEq)]
40#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
41pub struct InitializeGroupPointerInstructionAccounts {
42    pub mint: solana_pubkey::Pubkey,
43    pub remaining: Vec<solana_instruction::AccountMeta>,
44}
45
46impl InitializeGroupPointer {
47    pub fn decode(data: &[u8]) -> Option<Self> {
48        if data.len() < 2 {
49            return None;
50        }
51        let discriminator = &data[0..1];
52        if discriminator != [40] {
53            return None;
54        }
55        let group_pointer_discriminator = data[1];
56        if group_pointer_discriminator != 0 {
57            return None;
58        }
59
60        let data_slice = data;
61
62        let data_slice = &data_slice[1..];
63
64        let group_pointer = InitializeGroupPointerDeser::deserialize(data_slice)?;
65
66        Some(InitializeGroupPointer {
67            group_pointer_discriminator: group_pointer.group_pointer_discriminator,
68            authority: group_pointer.authority.into(),
69            group_address: group_pointer.group_address.into(),
70        })
71    }
72}
73
74impl ArrangeAccounts for InitializeGroupPointer {
75    type ArrangedAccounts = InitializeGroupPointerInstructionAccounts;
76
77    fn arrange_accounts(
78        accounts: &[solana_instruction::AccountMeta],
79    ) -> Option<Self::ArrangedAccounts> {
80        let mut iter = accounts.iter();
81
82        let mint = next_account(&mut iter)?;
83
84        let remaining = iter.as_slice();
85
86        Some(InitializeGroupPointerInstructionAccounts {
87            mint,
88            remaining: remaining.to_vec(),
89        })
90    }
91}