Struct dao::voting::voting_engine::voting_state_machine::VotingStateMachine
source · pub struct VotingStateMachine { /* private fields */ }
Expand description
Serializable voting state with a state machine capabilities.
Stores voting metadata, the configuration and the voting progress (stakes).
Implementations§
source§impl VotingStateMachine
impl VotingStateMachine
sourcepub fn new(voting_id: VotingId, created_at: u64, creator: Address) -> Self
pub fn new(voting_id: VotingId, created_at: u64, creator: Address) -> Self
Creates new Voting with immutable Configuration
.
sourcepub fn complete_informal_voting(
&mut self,
configuration: &Configuration
) -> bool
pub fn complete_informal_voting( &mut self, configuration: &Configuration ) -> bool
Ends the informal phase, verifies if the result is close, updates voting type to Formal.
sourcepub fn voting_type(&self) -> VotingType
pub fn voting_type(&self) -> VotingType
Returns the type of Voting.
sourcepub fn is_informal_without_stake(&self, configuration: &Configuration) -> bool
pub fn is_informal_without_stake(&self, configuration: &Configuration) -> bool
Checks if Voting is of type Informal and stakes the reputation.
sourcepub fn is_in_time(&self, block_time: u64, configuration: &Configuration) -> bool
pub fn is_in_time(&self, block_time: u64, configuration: &Configuration) -> bool
Checks if Voting is still in the voting phase.
sourcepub fn informal_voting_end_time(
&self,
configuration: &Configuration
) -> BlockTime
pub fn informal_voting_end_time( &self, configuration: &Configuration ) -> BlockTime
Gets the informal phase end time.
sourcepub fn time_between_votings_end_time(
&self,
configuration: &Configuration
) -> BlockTime
pub fn time_between_votings_end_time( &self, configuration: &Configuration ) -> BlockTime
Gets the informal-formal break end time.
sourcepub fn formal_voting_end_time(&self, configuration: &Configuration) -> BlockTime
pub fn formal_voting_end_time(&self, configuration: &Configuration) -> BlockTime
Gets the informal phase end time.
sourcepub fn is_in_favor(&self) -> bool
pub fn is_in_favor(&self) -> bool
Checks is the in_favor
stake surpasses the against
stake.
sourcepub fn get_winning_stake(&self) -> Balance
pub fn get_winning_stake(&self) -> Balance
Depending on the result of the voting, returns the amount of reputation staked on the winning side.
sourcepub fn get_result(
&self,
voters_number: u32,
configuration: &Configuration
) -> VotingResult
pub fn get_result( &self, voters_number: u32, configuration: &Configuration ) -> VotingResult
Gets the current voting result.
sourcepub fn add_stake(&mut self, stake: Balance, choice: Choice)
pub fn add_stake(&mut self, stake: Balance, choice: Choice)
Adds the stake
to the total bound stake.
sourcepub fn add_unbound_stake(&mut self, stake: Balance, choice: Choice)
pub fn add_unbound_stake(&mut self, stake: Balance, choice: Choice)
Adds the stake
to the total unbound stake.
sourcepub fn remove_stake(&mut self, stake: Balance, choice: Choice)
pub fn remove_stake(&mut self, stake: Balance, choice: Choice)
Removes the stake
from the total bound stake.
sourcepub fn remove_unbound_stake(&mut self, stake: Balance, choice: Choice)
pub fn remove_unbound_stake(&mut self, stake: Balance, choice: Choice)
Removes the stake
from the total unbound stake.
sourcepub fn bind_stake(&mut self, stake: Balance, choice: Choice)
pub fn bind_stake(&mut self, stake: Balance, choice: Choice)
Removes the unbound stake and adds it to the bound stake.
sourcepub fn total_stake(&self) -> Balance
pub fn total_stake(&self) -> Balance
Gets the sum of bound and unbound stake.
sourcepub fn total_bound_stake(&self) -> Balance
pub fn total_bound_stake(&self) -> Balance
Gets the total bound stake.
sourcepub fn total_unbound_stake(&self) -> Balance
pub fn total_unbound_stake(&self) -> Balance
Gets the total unbound stake.
sourcepub fn stake_in_favor(&self) -> Balance
pub fn stake_in_favor(&self) -> Balance
Get the voting’s stake in favor.
sourcepub fn stake_against(&self) -> Balance
pub fn stake_against(&self) -> Balance
Get the voting’s stake against.
sourcepub fn state(&self) -> &VotingState
pub fn state(&self) -> &VotingState
Gets the current voting state.
sourcepub fn state_in_time(
&self,
block_time: BlockTime,
configuration: &Configuration
) -> VotingState
pub fn state_in_time( &self, block_time: BlockTime, configuration: &Configuration ) -> VotingState
Returns the voting state depending on a given block_time
.
sourcepub fn informal_stats(&self) -> &Stats
pub fn informal_stats(&self) -> &Stats
Gets the Informal Voting
statistics.
sourcepub fn formal_stats(&self) -> &Stats
pub fn formal_stats(&self) -> &Stats
Gets the Formal Voting
statistics.
pub fn created_at(&self) -> u64
sourcepub fn guard_vote(&self, block_time: BlockTime, configuration: &Configuration)
pub fn guard_vote(&self, block_time: BlockTime, configuration: &Configuration)
Verifies if a ballot can be casted.
Stops contract execution if validation fails. See VoteInTime
.
sourcepub fn guard_finish_formal_voting(
&self,
block_time: BlockTime,
configuration: &Configuration
)
pub fn guard_finish_formal_voting( &self, block_time: BlockTime, configuration: &Configuration )
Verifies if the formal voting can be finished.
Stops contract execution if validation fails. See AfterFormalVoting
and VotingNotCompleted
.
pub fn guard_cancel_finished_voting( &self, block_time: BlockTime, configuration: &Configuration )
Trait Implementations§
source§impl BorshDeserialize for VotingStateMachine
impl BorshDeserialize for VotingStateMachine
source§fn deserialize(buf: &mut &[u8]) -> Result<Self>
fn deserialize(buf: &mut &[u8]) -> Result<Self>
§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
source§impl BorshSerialize for VotingStateMachine
impl BorshSerialize for VotingStateMachine
source§impl Clone for VotingStateMachine
impl Clone for VotingStateMachine
source§fn clone(&self) -> VotingStateMachine
fn clone(&self) -> VotingStateMachine
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more