pub use sc_network::ReputationChange;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(missing_docs)]
pub enum UnifiedReputationChange {
CostMajor(&'static str),
CostMinor(&'static str),
CostMajorRepeated(&'static str),
CostMinorRepeated(&'static str),
Malicious(&'static str),
BenefitMinorFirst(&'static str),
BenefitMinor(&'static str),
BenefitMajorFirst(&'static str),
BenefitMajor(&'static str),
}
impl UnifiedReputationChange {
const fn cost_or_benefit(&self) -> i32 {
match self {
Self::CostMinor(_) => -100_000,
Self::CostMajor(_) => -300_000,
Self::CostMinorRepeated(_) => -200_000,
Self::CostMajorRepeated(_) => -600_000,
Self::Malicious(_) => i32::MIN,
Self::BenefitMajorFirst(_) => 300_000,
Self::BenefitMajor(_) => 200_000,
Self::BenefitMinorFirst(_) => 15_000,
Self::BenefitMinor(_) => 10_000,
}
}
pub const fn description(&self) -> &'static str {
match self {
Self::CostMinor(description) => description,
Self::CostMajor(description) => description,
Self::CostMinorRepeated(description) => description,
Self::CostMajorRepeated(description) => description,
Self::Malicious(description) => description,
Self::BenefitMajorFirst(description) => description,
Self::BenefitMajor(description) => description,
Self::BenefitMinorFirst(description) => description,
Self::BenefitMinor(description) => description,
}
}
pub const fn is_benefit(&self) -> bool {
match self {
Self::BenefitMajorFirst(_) |
Self::BenefitMajor(_) |
Self::BenefitMinorFirst(_) |
Self::BenefitMinor(_) => true,
_ => false,
}
}
pub const fn into_base_rep(self) -> ReputationChange {
ReputationChange::new(self.cost_or_benefit(), self.description())
}
}