carbon_token_2022_decoder/instructions/
initialize_account.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;
12
13/// Initializes a new account to hold tokens. If this account is associated
14/// with the native mint then the token balance of the initialized account
15/// will be equal to the amount of SOL in the account. If this account is
16/// associated with another mint, that mint must be initialized before this
17/// command can succeed.
18///
19/// The `InitializeAccount` instruction requires no signers and MUST be
20/// included within the same Transaction as the system program's
21/// `CreateAccount` instruction that creates the account being initialized.
22/// Otherwise another party can acquire ownership of the uninitialized account.
23#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
24#[derive(Debug, Clone, borsh::BorshSerialize, CarbonDeserialize, PartialEq)]
25pub struct InitializeAccount {}
26
27#[derive(Debug, Clone, PartialEq)]
28#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
29pub struct InitializeAccountInstructionAccounts {
30    pub account: solana_pubkey::Pubkey,
31    pub mint: solana_pubkey::Pubkey,
32    pub owner: solana_pubkey::Pubkey,
33    pub rent: solana_pubkey::Pubkey,
34    pub remaining: Vec<solana_instruction::AccountMeta>,
35}
36
37impl InitializeAccount {
38    pub fn decode(data: &[u8]) -> Option<Self> {
39        if data.is_empty() {
40            return None;
41        }
42        let discriminator = &data[0..1];
43        if discriminator != [1] {
44            return None;
45        }
46
47        let data_slice = data;
48
49        let data_slice = &data_slice[1..];
50
51        Self::deserialize(data_slice)
52    }
53}
54
55impl ArrangeAccounts for InitializeAccount {
56    type ArrangedAccounts = InitializeAccountInstructionAccounts;
57
58    fn arrange_accounts(
59        accounts: &[solana_instruction::AccountMeta],
60    ) -> Option<Self::ArrangedAccounts> {
61        let mut iter = accounts.iter();
62
63        let account = next_account(&mut iter)?;
64        let mint = next_account(&mut iter)?;
65        let owner = next_account(&mut iter)?;
66        let rent = next_account(&mut iter)?;
67
68        let remaining = iter.as_slice();
69
70        Some(InitializeAccountInstructionAccounts {
71            account,
72            mint,
73            owner,
74            rent,
75            remaining: remaining.to_vec(),
76        })
77    }
78}