Skip to main content

carbon_token_program_decoder/instructions/
initialize_account.rs

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