Skip to main content

carbon_stake_program_decoder/instructions/
authorize.rs

1//! This code was AUTOGENERATED using the Codama library.
2use {
3    crate::types::StakeAuthorize,
4    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
5    solana_pubkey::Pubkey,
6};
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
9pub struct Authorize {
10    pub arg0: Pubkey,
11    pub arg1: StakeAuthorize,
12}
13
14#[derive(Debug, Clone, PartialEq)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16pub struct AuthorizeInstructionAccounts {
17    pub stake: solana_pubkey::Pubkey,
18    pub clock_sysvar: solana_pubkey::Pubkey,
19    pub authority: solana_pubkey::Pubkey,
20    pub lockup_authority: Option<solana_pubkey::Pubkey>,
21    pub remaining: Vec<solana_instruction::AccountMeta>,
22}
23
24impl Authorize {
25    pub fn decode(data: &[u8]) -> Option<Self> {
26        if data.is_empty() {
27            return None;
28        }
29        let discriminator = &data[0..1];
30        if discriminator != [1] {
31            return None;
32        }
33
34        let mut data_slice = data;
35
36        data_slice = &data_slice[1..];
37
38        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
39    }
40}
41
42impl ArrangeAccounts for Authorize {
43    type ArrangedAccounts = AuthorizeInstructionAccounts;
44
45    fn arrange_accounts(
46        accounts: &[solana_instruction::AccountMeta],
47    ) -> Option<Self::ArrangedAccounts> {
48        let mut iter = accounts.iter();
49
50        let stake = next_account(&mut iter)?;
51        let clock_sysvar = next_account(&mut iter)?;
52        let authority = next_account(&mut iter)?;
53        let lockup_authority = next_account(&mut iter);
54
55        let remaining = iter.as_slice();
56
57        Some(AuthorizeInstructionAccounts {
58            stake,
59            clock_sysvar,
60            authority,
61            lockup_authority,
62            remaining: remaining.to_vec(),
63        })
64    }
65}