use crate::generated::types::Key;
#[cfg(feature = "anchor")]
use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
#[cfg(not(feature = "anchor"))]
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::pubkey::Pubkey;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ExecutionDelegateRecordV1 {
pub key: Key,
pub bump: u8,
pub padding: [u8; 6],
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub executive_profile: Pubkey,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub authority: Pubkey,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub agent_asset: Pubkey,
}
impl ExecutionDelegateRecordV1 {
pub const LEN: usize = 104;
pub const PREFIX: &'static [u8] = "execution_delegate_record".as_bytes();
pub fn create_pda(
executive_profile: Pubkey,
agent_asset: Pubkey,
bump: u8,
) -> Result<solana_program::pubkey::Pubkey, solana_program::pubkey::PubkeyError> {
solana_program::pubkey::Pubkey::create_program_address(
&[
"execution_delegate_record".as_bytes(),
executive_profile.as_ref(),
agent_asset.as_ref(),
&[bump],
],
&crate::MPL_AGENT_TOOLS_ID,
)
}
pub fn find_pda(
executive_profile: &Pubkey,
agent_asset: &Pubkey,
) -> (solana_program::pubkey::Pubkey, u8) {
solana_program::pubkey::Pubkey::find_program_address(
&[
"execution_delegate_record".as_bytes(),
executive_profile.as_ref(),
agent_asset.as_ref(),
],
&crate::MPL_AGENT_TOOLS_ID,
)
}
#[inline(always)]
pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
let mut data = data;
Self::deserialize(&mut data)
}
}
impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for ExecutionDelegateRecordV1 {
type Error = std::io::Error;
fn try_from(
account_info: &solana_program::account_info::AccountInfo<'a>,
) -> Result<Self, Self::Error> {
let mut data: &[u8] = &(*account_info.data).borrow();
Self::deserialize(&mut data)
}
}