use r402::proto::PaymentVerificationError;
use solana_pubkey::Pubkey;
#[derive(Debug, thiserror::Error)]
pub enum SolanaExactError {
#[error("Can not decode transaction: {0}")]
TransactionDecoding(String),
#[error("Compute unit limit exceeds facilitator maximum")]
MaxComputeUnitLimitExceeded,
#[error("Compute unit price exceeds facilitator maximum")]
MaxComputeUnitPriceExceeded,
#[error("Too few instructions in transaction")]
TooFewInstructions,
#[error("Additional instructions not allowed")]
AdditionalInstructionsNotAllowed,
#[error("Instruction count exceeds maximum: {0}")]
InstructionCountExceedsMax(usize),
#[error("Blocked program in transaction: {0}")]
BlockedProgram(Pubkey),
#[error("Program not in allowed list: {0}")]
ProgramNotAllowed(Pubkey),
#[error("CreateATA instruction not supported - destination ATA must exist")]
CreateATANotSupported,
#[error("Fee payer included in instruction accounts")]
FeePayerIncludedInInstructionAccounts,
#[error("Fee payer found transferring funds")]
FeePayerTransferringFunds,
#[error("Instruction at index {0} not found")]
NoInstructionAtIndex(usize),
#[error("No account at index {0}")]
NoAccountAtIndex(u8),
#[error("Empty instruction at index {0}")]
EmptyInstructionAtIndex(usize),
#[error("Invalid compute limit instruction")]
InvalidComputeLimitInstruction,
#[error("Invalid compute price instruction")]
InvalidComputePriceInstruction,
#[error("Invalid token instruction")]
InvalidTokenInstruction,
#[error("Missing sender account in transaction")]
MissingSenderAccount,
}
impl From<SolanaExactError> for PaymentVerificationError {
fn from(e: SolanaExactError) -> Self {
match e {
SolanaExactError::TransactionDecoding(_) => Self::InvalidFormat(e.to_string()),
SolanaExactError::MaxComputeUnitLimitExceeded
| SolanaExactError::MaxComputeUnitPriceExceeded
| SolanaExactError::TooFewInstructions
| SolanaExactError::AdditionalInstructionsNotAllowed
| SolanaExactError::InstructionCountExceedsMax(_)
| SolanaExactError::BlockedProgram(_)
| SolanaExactError::ProgramNotAllowed(_)
| SolanaExactError::CreateATANotSupported
| SolanaExactError::FeePayerIncludedInInstructionAccounts
| SolanaExactError::NoInstructionAtIndex(_)
| SolanaExactError::InvalidComputeLimitInstruction
| SolanaExactError::NoAccountAtIndex(_)
| SolanaExactError::InvalidTokenInstruction
| SolanaExactError::EmptyInstructionAtIndex(_)
| SolanaExactError::FeePayerTransferringFunds
| SolanaExactError::MissingSenderAccount
| SolanaExactError::InvalidComputePriceInstruction => {
Self::TransactionSimulation(e.to_string())
}
}
}
}
#[derive(Debug, thiserror::Error)]
#[error("Can not encode transaction to base64: {0}")]
pub struct TransactionToB64Error(pub String);
#[derive(Debug, thiserror::Error)]
#[error("Can not sign transaction: {0}")]
pub struct TransactionSignError(pub String);