use crate::account;
use crate::certificate::PoolId;
use crate::value::Value;
use std::collections::BTreeMap;
use std::default::Default;
#[derive(Default, Debug, Clone, Copy)]
pub struct RewardsInfoParameters {
report_stake_pools: bool,
report_accounts: bool,
}
impl RewardsInfoParameters {
pub fn report_all() -> Self {
RewardsInfoParameters {
report_stake_pools: true,
report_accounts: true,
}
}
}
#[derive(Debug, Clone)]
pub struct EpochRewardsInfo {
pub params: RewardsInfoParameters,
pub drawn: Value,
pub fees: Value,
pub treasury: Value,
pub stake_pools: BTreeMap<PoolId, (Value, Value)>,
pub accounts: BTreeMap<account::Identifier, Value>,
}
impl EpochRewardsInfo {
pub fn new(params: RewardsInfoParameters) -> EpochRewardsInfo {
EpochRewardsInfo {
params,
drawn: Value::zero(),
fees: Value::zero(),
treasury: Value::zero(),
stake_pools: BTreeMap::new(),
accounts: BTreeMap::new(),
}
}
pub fn set_treasury(&mut self, value: Value) {
assert_eq!(self.treasury, Value::zero());
self.treasury = value;
}
pub fn set_stake_pool(&mut self, pool: &PoolId, owned: Value, distributed: Value) {
if self.params.report_stake_pools {
self.stake_pools.insert(pool.clone(), (owned, distributed));
}
}
pub fn add_to_account(&mut self, account: &account::Identifier, value: Value) {
if self.params.report_accounts {
let ent = self.accounts.entry(account.clone()).or_default();
*ent = (*ent + value).unwrap()
}
}
pub fn total(&self) -> Value {
(self.drawn + self.fees).unwrap()
}
}