Skip to main content

carbon_token_program_decoder/instructions/
approve.rs

1//! This code was AUTOGENERATED using the Codama library.
2use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3/// Approves a delegate. A delegate is given the authority over tokens on
4/// behalf of the source account's owner.
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
7pub struct Approve {
8    /// The amount of tokens the delegate is approved for.
9    pub amount: u64,
10}
11
12#[derive(Debug, Clone, PartialEq)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14pub struct ApproveInstructionAccounts {
15    pub source: solana_pubkey::Pubkey,
16    pub delegate: solana_pubkey::Pubkey,
17    pub owner: solana_pubkey::Pubkey,
18    pub remaining: Vec<solana_instruction::AccountMeta>,
19}
20
21impl Approve {
22    pub fn decode(data: &[u8]) -> Option<Self> {
23        if data.is_empty() {
24            return None;
25        }
26        let discriminator = &data[0..1];
27        if discriminator != [4] {
28            return None;
29        }
30
31        let mut data_slice = data;
32
33        data_slice = &data_slice[1..];
34
35        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
36    }
37}
38
39impl ArrangeAccounts for Approve {
40    type ArrangedAccounts = ApproveInstructionAccounts;
41
42    fn arrange_accounts(
43        accounts: &[solana_instruction::AccountMeta],
44    ) -> Option<Self::ArrangedAccounts> {
45        let mut iter = accounts.iter();
46
47        let source = next_account(&mut iter)?;
48        let delegate = next_account(&mut iter)?;
49        let owner = next_account(&mut iter)?;
50
51        let remaining = iter.as_slice();
52
53        Some(ApproveInstructionAccounts {
54            source,
55            delegate,
56            owner,
57            remaining: remaining.to_vec(),
58        })
59    }
60}