mpl-agent-tools 0.3.0

A new Solana program using the Metaplex Project Template
Documentation
//! This code was AUTOGENERATED using the kinobi library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun kinobi to update it.
//!
//! [https://github.com/metaplex-foundation/kinobi]
//!

use num_derive::FromPrimitive;
use solana_program_error::{ProgramError, ToStr};
use thiserror::Error;

#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
pub enum MplAgentToolsError {
    /// 0 (0x0) - Invalid System Program
    #[error("Invalid System Program")]
    InvalidSystemProgram,
    /// 1 (0x1) - Invalid instruction data
    #[error("Invalid instruction data")]
    InvalidInstructionData,
    /// 2 (0x2) - Invalid account data
    #[error("Invalid account data")]
    InvalidAccountData,
    /// 3 (0x3) - Invalid MPL Core Program
    #[error("Invalid MPL Core Program")]
    InvalidMplCoreProgram,
    /// 4 (0x4) - Invalid Core Asset
    #[error("Invalid Core Asset")]
    InvalidCoreAsset,
    /// 5 (0x5) - Executive Profile must be uninitialized
    #[error("Executive Profile must be uninitialized")]
    ExecutiveProfileMustBeUninitialized,
    /// 6 (0x6) - Invalid Execution Delegate Record Derivation
    #[error("Invalid Execution Delegate Record Derivation")]
    InvalidExecutionDelegateRecordDerivation,
    /// 7 (0x7) - Execution Delegate Record must be uninitialized
    #[error("Execution Delegate Record must be uninitialized")]
    ExecutionDelegateRecordMustBeUninitialized,
    /// 8 (0x8) - Invalid Agent Identity
    #[error("Invalid Agent Identity")]
    InvalidAgentIdentity,
    /// 9 (0x9) - Agent Identity not registered
    #[error("Agent Identity not registered")]
    AgentIdentityNotRegistered,
    /// 10 (0xA) - Asset owner must be the one to delegate execution
    #[error("Asset owner must be the one to delegate execution")]
    AssetOwnerMustBeTheOneToDelegateExecution,
    /// 11 (0xB) - Invalid Executive Profile Derivation
    #[error("Invalid Executive Profile Derivation")]
    InvalidExecutiveProfileDerivation,
    /// 12 (0xC) - Execution Delegate Record must be initialized
    #[error("Execution Delegate Record must be initialized")]
    ExecutionDelegateRecordMustBeInitialized,
    /// 13 (0xD) - Authority must be asset owner or executive to revoke
    #[error("Authority must be asset owner or executive to revoke")]
    UnauthorizedRevoke,
    /// 14 (0xE) - Executive Profile must be initialized
    #[error("Executive Profile must be initialized")]
    ExecutiveProfileMustBeInitialized,
}

impl From<MplAgentToolsError> for ProgramError {
    fn from(e: MplAgentToolsError) -> Self {
        ProgramError::Custom(e as u32)
    }
}

impl TryFrom<u32> for MplAgentToolsError {
    type Error = ProgramError;
    fn try_from(error: u32) -> Result<Self, Self::Error> {
        match error {
            0 => Ok(MplAgentToolsError::InvalidSystemProgram),
            1 => Ok(MplAgentToolsError::InvalidInstructionData),
            2 => Ok(MplAgentToolsError::InvalidAccountData),
            3 => Ok(MplAgentToolsError::InvalidMplCoreProgram),
            4 => Ok(MplAgentToolsError::InvalidCoreAsset),
            5 => Ok(MplAgentToolsError::ExecutiveProfileMustBeUninitialized),
            6 => Ok(MplAgentToolsError::InvalidExecutionDelegateRecordDerivation),
            7 => Ok(MplAgentToolsError::ExecutionDelegateRecordMustBeUninitialized),
            8 => Ok(MplAgentToolsError::InvalidAgentIdentity),
            9 => Ok(MplAgentToolsError::AgentIdentityNotRegistered),
            10 => Ok(MplAgentToolsError::AssetOwnerMustBeTheOneToDelegateExecution),
            11 => Ok(MplAgentToolsError::InvalidExecutiveProfileDerivation),
            12 => Ok(MplAgentToolsError::ExecutionDelegateRecordMustBeInitialized),
            13 => Ok(MplAgentToolsError::UnauthorizedRevoke),
            14 => Ok(MplAgentToolsError::ExecutiveProfileMustBeInitialized),
            _ => Err(ProgramError::InvalidArgument),
        }
    }
}

impl ToStr for MplAgentToolsError {
    fn to_str(&self) -> &'static str {
        match self {
            MplAgentToolsError::InvalidSystemProgram => "Invalid System Program",
            MplAgentToolsError::InvalidInstructionData => "Invalid instruction data",
            MplAgentToolsError::InvalidAccountData => "Invalid account data",
            MplAgentToolsError::InvalidMplCoreProgram => "Invalid MPL Core Program",
            MplAgentToolsError::InvalidCoreAsset => "Invalid Core Asset",
            MplAgentToolsError::ExecutiveProfileMustBeUninitialized => {
                "Executive Profile must be uninitialized"
            }
            MplAgentToolsError::InvalidExecutionDelegateRecordDerivation => {
                "Invalid Execution Delegate Record Derivation"
            }
            MplAgentToolsError::ExecutionDelegateRecordMustBeUninitialized => {
                "Execution Delegate Record must be uninitialized"
            }
            MplAgentToolsError::InvalidAgentIdentity => "Invalid Agent Identity",
            MplAgentToolsError::AgentIdentityNotRegistered => "Agent Identity not registered",
            MplAgentToolsError::AssetOwnerMustBeTheOneToDelegateExecution => {
                "Asset owner must be the one to delegate execution"
            }
            MplAgentToolsError::InvalidExecutiveProfileDerivation => {
                "Invalid Executive Profile Derivation"
            }
            MplAgentToolsError::ExecutionDelegateRecordMustBeInitialized => {
                "Execution Delegate Record must be initialized"
            }
            MplAgentToolsError::UnauthorizedRevoke => {
                "Authority must be asset owner or executive to revoke"
            }
            MplAgentToolsError::ExecutiveProfileMustBeInitialized => {
                "Executive Profile must be initialized"
            }
        }
    }
}