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