use {
crate::types::StakeAuthorize,
carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct AuthorizeChecked {
pub stake_authorize: StakeAuthorize,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AuthorizeCheckedInstructionAccounts {
pub stake: solana_pubkey::Pubkey,
pub clock_sysvar: solana_pubkey::Pubkey,
pub authority: solana_pubkey::Pubkey,
pub new_authority: solana_pubkey::Pubkey,
pub lockup_authority: Option<solana_pubkey::Pubkey>,
pub remaining: Vec<solana_instruction::AccountMeta>,
}
impl AuthorizeChecked {
pub fn decode(data: &[u8]) -> Option<Self> {
if data.is_empty() {
return None;
}
let discriminator = &data[0..1];
if discriminator != [10] {
return None;
}
let mut data_slice = data;
data_slice = &data_slice[1..];
borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
}
}
impl ArrangeAccounts for AuthorizeChecked {
type ArrangedAccounts = AuthorizeCheckedInstructionAccounts;
fn arrange_accounts(
accounts: &[solana_instruction::AccountMeta],
) -> Option<Self::ArrangedAccounts> {
let mut iter = accounts.iter();
let stake = next_account(&mut iter)?;
let clock_sysvar = next_account(&mut iter)?;
let authority = next_account(&mut iter)?;
let new_authority = next_account(&mut iter)?;
let lockup_authority = next_account(&mut iter);
let remaining = iter.as_slice();
Some(AuthorizeCheckedInstructionAccounts {
stake,
clock_sysvar,
authority,
new_authority,
lockup_authority,
remaining: remaining.to_vec(),
})
}
}