use crate::configuration::Configuration;
use crate::voting::ballot::{Ballot, Choice};
use crate::voting::types::VotingId;
use crate::voting::voting_engine::voting_state_machine::{
Stats, VotingResult, VotingStateMachine, VotingType,
};
use odra::prelude::collections::BTreeMap;
use odra::types::{Address, Balance, BlockTime};
use odra::{Event, OdraType};
#[derive(OdraType, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Debug)]
pub enum Reason {
InformalFinished = 1,
FormalFinished = 2,
FormalWon = 3,
FormalLost = 4,
}
#[derive(Debug, PartialEq, Eq, Event)]
pub struct BallotCast {
pub voter: Address,
pub voting_id: VotingId,
pub voting_type: VotingType,
pub choice: Choice,
pub stake: Balance,
}
impl BallotCast {
pub fn new(ballot: &Ballot) -> Self {
BallotCast {
voter: ballot.voter,
voting_id: ballot.voting_id,
voting_type: ballot.voting_type,
choice: ballot.choice,
stake: ballot.stake,
}
}
}
#[derive(Debug, PartialEq, Eq, Event)]
pub struct VotingCreatedInfo {
pub creator: Address,
pub stake: Option<Balance>,
pub voting_id: VotingId,
pub config_informal_quorum: u32,
pub config_informal_voting_time: u64,
pub config_formal_quorum: u32,
pub config_formal_voting_time: u64,
pub config_total_onboarded: Balance,
pub config_double_time_between_votings: bool,
pub config_voting_clearness_delta: Balance,
pub config_time_between_informal_and_formal_voting: BlockTime,
}
impl VotingCreatedInfo {
pub fn new(
creator: Address,
voting_id: VotingId,
stake: Option<Balance>,
config: &Configuration,
) -> Self {
Self {
creator,
stake,
voting_id,
config_informal_quorum: config.informal_voting_quorum(),
config_informal_voting_time: config.informal_voting_time(),
config_formal_quorum: config.formal_voting_quorum(),
config_formal_voting_time: config.formal_voting_time(),
config_total_onboarded: config.total_onboarded(),
config_voting_clearness_delta: config.voting_clearness_delta(),
config_double_time_between_votings: config.should_double_time_between_votings(),
config_time_between_informal_and_formal_voting: config
.time_between_informal_and_formal_voting(),
}
}
}
#[derive(Debug, PartialEq, Eq, Event)]
pub struct VotingEnded {
pub voting_id: VotingId,
pub voting_type: VotingType,
pub voting_result: VotingResult,
pub stake_in_favor: Balance,
pub stake_against: Balance,
pub unbound_stake_in_favor: Balance,
pub unbound_stake_against: Balance,
pub votes_in_favor: u32,
pub votes_against: u32,
pub unstakes: BTreeMap<(Address, Reason), Balance>,
pub stakes: BTreeMap<(Address, Reason), Balance>,
pub burns: BTreeMap<(Address, Reason), Balance>,
pub mints: BTreeMap<(Address, Reason), Balance>,
}
impl VotingEnded {
pub fn new(
voting: &VotingStateMachine,
voting_result: VotingResult,
stats: &Stats,
unstakes: BTreeMap<(Address, Reason), Balance>,
stakes: BTreeMap<(Address, Reason), Balance>,
burns: BTreeMap<(Address, Reason), Balance>,
mints: BTreeMap<(Address, Reason), Balance>,
) -> Self {
Self {
voting_id: voting.voting_id(),
voting_type: voting.voting_type(),
voting_result,
stake_in_favor: stats.stake_in_favor,
stake_against: stats.stake_against,
unbound_stake_in_favor: stats.unbound_stake_in_favor,
unbound_stake_against: stats.unbound_stake_against,
votes_in_favor: stats.votes_in_favor,
votes_against: stats.votes_against,
unstakes,
stakes,
burns,
mints,
}
}
}
#[derive(Debug, PartialEq, Eq, Event)]
pub struct BallotCanceled {
pub voter: Address,
pub voting_id: VotingId,
pub voting_type: VotingType,
pub choice: Choice,
pub stake: Balance,
}
impl BallotCanceled {
pub fn new(ballot: &Ballot) -> Self {
Self {
voter: ballot.voter,
voting_id: ballot.voting_id,
voting_type: ballot.voting_type,
choice: ballot.choice,
stake: ballot.stake,
}
}
}
#[derive(Debug, PartialEq, Eq, Event)]
pub struct VotingCanceled {
pub voting_id: VotingId,
pub voting_type: VotingType,
pub unstakes: BTreeMap<Address, Balance>,
}
impl VotingCanceled {
pub fn new(
voting_id: VotingId,
voting_type: VotingType,
unstakes: BTreeMap<Address, Balance>,
) -> Self {
Self {
voting_id,
voting_type,
unstakes,
}
}
}