carbon_system_program_decoder/instructions/
allocate.rs1use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
5pub struct Allocate {
6 pub space: u64,
7}
8
9#[derive(Debug, Clone, PartialEq)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct AllocateInstructionAccounts {
12 pub new_account: solana_pubkey::Pubkey,
13 pub remaining: Vec<solana_instruction::AccountMeta>,
14}
15
16impl Allocate {
17 pub fn decode(data: &[u8]) -> Option<Self> {
18 if data.len() < 4 {
19 return None;
20 }
21 let discriminator = &data[0..4];
22 if discriminator != [8, 0, 0, 0] {
23 return None;
24 }
25
26 let mut data_slice = data;
27
28 data_slice = &data_slice[4..];
29
30 borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
31 }
32}
33
34impl ArrangeAccounts for Allocate {
35 type ArrangedAccounts = AllocateInstructionAccounts;
36
37 fn arrange_accounts(
38 accounts: &[solana_instruction::AccountMeta],
39 ) -> Option<Self::ArrangedAccounts> {
40 let mut iter = accounts.iter();
41
42 let new_account = next_account(&mut iter)?;
43
44 let remaining = iter.as_slice();
45
46 Some(AllocateInstructionAccounts {
47 new_account,
48 remaining: remaining.to_vec(),
49 })
50 }
51}