use neptune_consensus::type_scripts::native_currency_amount::NativeCurrencyAmount;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum UpgradeIncentive {
Gobble(NativeCurrencyAmount),
BalanceAffecting(NativeCurrencyAmount),
Critical,
}
impl UpgradeIncentive {
pub fn upgrade_is_worth_it(&self, min_gobbling_fee: NativeCurrencyAmount) -> bool {
match self {
UpgradeIncentive::Gobble(gobble_amt) => *gobble_amt >= min_gobbling_fee,
_ => true,
}
}
pub fn after_upgrade(self) -> Self {
match self {
UpgradeIncentive::Critical => UpgradeIncentive::Critical,
UpgradeIncentive::Gobble(native_currency_amount) => {
UpgradeIncentive::BalanceAffecting(native_currency_amount)
}
UpgradeIncentive::BalanceAffecting(native_currency_amount) => {
UpgradeIncentive::BalanceAffecting(native_currency_amount)
}
}
}
}
impl PartialOrd for UpgradeIncentive {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for UpgradeIncentive {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
use std::cmp::Ordering::Equal;
use std::cmp::Ordering::Greater;
use std::cmp::Ordering::Less;
use UpgradeIncentive::BalanceAffecting;
use UpgradeIncentive::Critical;
use UpgradeIncentive::Gobble;
match (self, other) {
(Gobble(self_amt), Gobble(other_amt)) => self_amt.cmp(other_amt),
(Gobble(_), _) => Less,
(BalanceAffecting(_), Gobble(_)) => Greater,
(BalanceAffecting(self_amt), BalanceAffecting(other_amt)) => self_amt.cmp(other_amt),
(BalanceAffecting(_), Critical) => Less,
(Critical, Critical) => Equal,
(Critical, _) => Greater,
}
}
}