Skip to main content

carbon_system_program_decoder/instructions/
transfer_sol.rs

1//! This code was AUTOGENERATED using the Codama library.
2use 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 TransferSol {
6    pub amount: u64,
7}
8
9#[derive(Debug, Clone, PartialEq)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct TransferSolInstructionAccounts {
12    pub source: solana_pubkey::Pubkey,
13    pub destination: solana_pubkey::Pubkey,
14    pub remaining: Vec<solana_instruction::AccountMeta>,
15}
16
17impl TransferSol {
18    pub fn decode(data: &[u8]) -> Option<Self> {
19        if data.len() < 4 {
20            return None;
21        }
22        let discriminator = &data[0..4];
23        if discriminator != [2, 0, 0, 0] {
24            return None;
25        }
26
27        let mut data_slice = data;
28
29        data_slice = &data_slice[4..];
30
31        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
32    }
33}
34
35impl ArrangeAccounts for TransferSol {
36    type ArrangedAccounts = TransferSolInstructionAccounts;
37
38    fn arrange_accounts(
39        accounts: &[solana_instruction::AccountMeta],
40    ) -> Option<Self::ArrangedAccounts> {
41        let mut iter = accounts.iter();
42
43        let source = next_account(&mut iter)?;
44        let destination = next_account(&mut iter)?;
45
46        let remaining = iter.as_slice();
47
48        Some(TransferSolInstructionAccounts {
49            source,
50            destination,
51            remaining: remaining.to_vec(),
52        })
53    }
54}