use console::network::Network;
use snarkvm_ledger_block::Transactions;
use anyhow::{Result, anyhow};
pub fn update_total_supply<N: Network>(
starting_total_supply_in_microcredits: u64,
block_reward: u64,
puzzle_reward: u64,
transactions: &Transactions<N>,
) -> Result<u64> {
let mut next_total_supply = starting_total_supply_in_microcredits;
next_total_supply = next_total_supply.saturating_add(block_reward);
next_total_supply = next_total_supply.saturating_add(puzzle_reward);
for confirmed in transactions.iter() {
next_total_supply = next_total_supply
.checked_sub(*confirmed.fee_amount()?)
.ok_or_else(|| anyhow!("The proposed fee underflows the total supply of microcredits"))?;
for transition in confirmed.transaction().transitions() {
if transition.is_split() {
next_total_supply = next_total_supply
.checked_sub(10_000u64)
.ok_or_else(|| anyhow!("The proposed split underflows the total supply of microcredits"))?;
}
}
}
Ok(next_total_supply)
}