use crate::constants::{C, H, M_MAX};
pub fn expected_validatesupplylimit_from_orange_paper(height: u64) -> bool {
let total_supply = expected_totalsupply_from_orange_paper(height);
total_supply <= M_MAX
}
pub fn expected_totalsupply_from_orange_paper(height: u64) -> i64 {
let mut total = 0i64;
for h in 0..=height {
let halving_period = h / H;
let initial_subsidy = 50 * C;
if halving_period < 64 {
total += (initial_subsidy >> halving_period) as i64;
}
}
total
}
pub fn expected_getblocksubsidy_from_orange_paper(height: u64) -> i64 {
let halving_period = height / H;
let initial_subsidy = 50 * C;
if halving_period >= 64 {
0
} else {
(initial_subsidy >> halving_period) as i64
}
}
pub fn expected_blockreward_from_orange_paper(height: u64, fees: i64) -> i64 {
expected_getblocksubsidy_from_orange_paper(height) + fees
}
pub fn expected_inflationrate_from_orange_paper(height: u64) -> f64 {
const BLOCKS_PER_YEAR: f64 = 52_560.0;
let subsidy = expected_getblocksubsidy_from_orange_paper(height) as f64;
let total_supply = expected_totalsupply_from_orange_paper(height) as f64;
if total_supply > 0.0 {
(subsidy * BLOCKS_PER_YEAR) / total_supply
} else {
0.0
}
}
pub fn expected_halvingepoch_from_orange_paper(height: u64) -> u64 {
height / H
}
pub fn expected_remainingsupply_from_orange_paper(height: u64) -> i64 {
M_MAX - expected_totalsupply_from_orange_paper(height)
}
pub fn expected_difficultyfromtarget_from_orange_paper(target: u64) -> f64 {
const TARGET_MAX: f64 = 2.69599466e67;
if target > 0 {
TARGET_MAX / (target as f64)
} else {
f64::INFINITY
}
}
pub fn expected_workfromtarget_from_orange_paper(target: u64) -> u128 {
if target > 0 {
let target_plus_one = (target as u128) + 1;
u128::MAX / target_plus_one.max(1)
} else {
u128::MAX
}
}
pub fn expected_utxosetvalue_from_orange_paper(utxo_values: &[i64]) -> i64 {
utxo_values.iter().sum()
}