Skip to main content

carbon_token_program_decoder/instructions/
get_account_data_size.rs

1//! This code was AUTOGENERATED using the Codama library.
2use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3/// Gets the required size of an account for the given mint as a
4/// little-endian `u64`.
5/// Return data can be fetched using `sol_get_return_data` and deserializing
6/// the return data as a little-endian `u64`.
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
9pub struct GetAccountDataSize {}
10
11#[derive(Debug, Clone, PartialEq)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13pub struct GetAccountDataSizeInstructionAccounts {
14    pub mint: solana_pubkey::Pubkey,
15    pub remaining: Vec<solana_instruction::AccountMeta>,
16}
17
18impl GetAccountDataSize {
19    pub fn decode(data: &[u8]) -> Option<Self> {
20        if data.is_empty() {
21            return None;
22        }
23        let discriminator = &data[0..1];
24        if discriminator != [21] {
25            return None;
26        }
27
28        let mut data_slice = data;
29
30        data_slice = &data_slice[1..];
31
32        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
33    }
34}
35
36impl ArrangeAccounts for GetAccountDataSize {
37    type ArrangedAccounts = GetAccountDataSizeInstructionAccounts;
38
39    fn arrange_accounts(
40        accounts: &[solana_instruction::AccountMeta],
41    ) -> Option<Self::ArrangedAccounts> {
42        let mut iter = accounts.iter();
43
44        let mint = next_account(&mut iter)?;
45
46        let remaining = iter.as_slice();
47
48        Some(GetAccountDataSizeInstructionAccounts {
49            mint,
50            remaining: remaining.to_vec(),
51        })
52    }
53}