use casper_types::{
system::{
mint,
mint::{Error, TOTAL_SUPPLY_KEY},
},
Key, U512,
};
use crate::system::mint::Mint;
pub(crate) fn reduce_total_supply_unsafe<P>(mint: &mut P, amount: U512) -> Result<(), mint::Error>
where
P: Mint + ?Sized,
{
if amount.is_zero() {
return Ok(()); }
let total_supply_uref = match mint.get_key(TOTAL_SUPPLY_KEY) {
Some(Key::URef(uref)) => uref,
Some(_) => return Err(Error::MissingKey),
None => return Err(Error::MissingKey),
};
let total_supply: U512 = mint
.read(total_supply_uref)?
.ok_or(Error::TotalSupplyNotFound)?;
let reduced_total_supply = total_supply
.checked_sub(amount)
.ok_or(Error::ArithmeticOverflow)?;
mint.write_amount(total_supply_uref, reduced_total_supply)?;
Ok(())
}