holofuel_types 0.1.1

Fuel types used for holofuel a mutual credit currency
Documentation
//! Implements fee calculation.  The fee structure of HoloFuel may change over time, but not between
//! roll-outs of new HoloFuel DNAs.  Therefore, its values and limits can be hard-coded here.

use crate::error::FuelError;
use crate::fraction::Fraction;
use crate::fuel::Fuel;

// ==> 1.0% fee
pub const FEE_PERCENTAGE: Fraction = Fraction {
    numerator: 1,
    denominator: 100,
};

/// tabulate_fee -- compute simple Transaction Fee from amount-based tables
pub fn tabulate_fee(amount: &Fuel) -> Result<Fuel, FuelError> {
    let fee = (amount * FEE_PERCENTAGE)?;
    Ok(fee)
}

#[cfg(test)]
pub mod tests {
    use crate::fee::*;

    /// smoke test Fuel fees
    #[test]
    fn fee_smoke_test() {
        let fee_tab = tabulate_fee(&Fuel { units: 1_230_000 }).unwrap();
        assert_eq!(fee_tab, Fuel { units: 12_300 });
    }
}