use crate::fraction::Fraction;
use crate::fuel::{Delta, Fuel, Limit};
use hdi::prelude::*;
use std::fmt;
#[derive(thiserror::Error, Debug, Clone)]
pub enum FuelError {
Range(String), FractionOverflow((Fuel, Fraction)), LimitExceeded((Limit, String, Delta)), AgentDenied(Limit), Generic(String), }
impl fmt::Display for FuelError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
FuelError::Range(s) => write!(f, "HoloFuel Range Error: {}", s),
FuelError::FractionOverflow((fuel, fraction)) => {
write!(f, "HoloFuel overflow in ♓{} * {}", fuel, fraction)
}
FuelError::LimitExceeded((limit, total, change)) => write!(
f,
"HoloFuel Limit {} exceeded with duration total ♓{}, by tx. ♓{}, on {:?}",
limit, total, change.1, change.0
),
FuelError::AgentDenied(limit) => write!(
f,
"HoloFuel Limit {} denies any counterparty transaction",
limit
),
FuelError::Generic(s) => write!(f, "HoloFuel Error: {}", s),
}
}
}
pub type FuelResult<T> = Result<T, FuelError>;
impl From<FuelError> for WasmError {
fn from(c: FuelError) -> Self {
wasm_error!(WasmErrorInner::Guest(format!("{:?}", c)))
}
}