holofuel_types 0.5.9

Fuel types used for holofuel a mutual credit currency
Documentation
//! Custom error types for HoloFuel transactions
use crate::fraction::Fraction;
use crate::fuel::Fuel;
use hdi::prelude::*;
use std::fmt;

#[derive(thiserror::Error, Debug, Clone)]
pub enum FuelError {
    Range(String),                      // Fuel range exceeded
    FractionOverflow((Fuel, Fraction)), // Overflow in Fuel * Fraction
    // LimitExceeded((Limit, String, Delta)), // An account Limit was exceeded by Fuel value, by the given transaction Delta
    // AgentDenied(Limit), // All transactions w/ counterparty are denied
    Generic(String), // we want to avoid this one if at all possible and add a new error variant instead
}

// All FuelError display logic is in one place which is here
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)))
    }
}