cbe_program/
native_token.rs

1//! Definitions for the native CBC token and its fractional scoobies.
2
3#![allow(clippy::integer_arithmetic)]
4
5/// There are 10^9 scoobies in one CBC
6pub const SCOOBIES_PER_CBC: u64 = 1_000_000_000;
7
8/// Approximately convert fractional native tokens (scoobies) into native tokens (CBC)
9pub fn scoobies_to_cbc(scoobies: u64) -> f64 {
10    scoobies as f64 / SCOOBIES_PER_CBC as f64
11}
12
13/// Approximately convert native tokens (CBC) into fractional native tokens (scoobies)
14pub fn cbc_to_scoobies(cbc: f64) -> u64 {
15    (cbc * SCOOBIES_PER_CBC as f64) as u64
16}
17
18use std::fmt::{Debug, Display, Formatter, Result};
19pub struct CBC(pub u64);
20
21impl CBC {
22    fn write_in_sol(&self, f: &mut Formatter) -> Result {
23        write!(
24            f,
25            "◎{}.{:09}",
26            self.0 / SCOOBIES_PER_CBC,
27            self.0 % SCOOBIES_PER_CBC
28        )
29    }
30}
31
32impl Display for CBC {
33    fn fmt(&self, f: &mut Formatter) -> Result {
34        self.write_in_sol(f)
35    }
36}
37
38impl Debug for CBC {
39    fn fmt(&self, f: &mut Formatter) -> Result {
40        self.write_in_sol(f)
41    }
42}