Struct dao::voting::voting_engine::VotingEngine
source · pub struct VotingEngine { /* private fields */ }
Expand description
Governance voting is a struct that voting_contracts can use to implement voting.
It consists of two phases:
- Informal voting
- Formal voting
Whether formal voting starts depends on informal voting results.
When formal voting passes, an action can be performed - a contract can be called with voted arguments.
Governance voting uses:
- Reputation Token to handle reputation staking.
- Variable Repo for reading voting configuration.
For example implementation see AdminContract.
Implementations§
source§impl VotingEngine
impl VotingEngine
sourcepub fn create_voting(
&mut self,
creator: Address,
stake: Balance,
configuration: Configuration
) -> (VotingCreatedInfo, VotingStateMachine)
pub fn create_voting( &mut self, creator: Address, stake: Balance, configuration: Configuration ) -> (VotingCreatedInfo, VotingStateMachine)
Creates new informal Voting.
contract_to_call
, entry_point
and runtime_args
parameters define an action that will be performed when formal voting passes.
It collects configuration from Variable Repo and persists it, so they won’t change during the voting process.
Interacts with Dao Ids Contract to generate voting id.
Depending on the configuration may cast
the first vote.
§Errors
Error::NotEnoughReputation
when the creator does not have enough reputation to create a voting.Error::NotOnboarded
if the configuration requires the creator to be a VA but is not.
sourcepub fn finish_voting(
&mut self,
voting_id: VotingId,
voting_type: VotingType
) -> VotingSummary
pub fn finish_voting( &mut self, voting_id: VotingId, voting_type: VotingType ) -> VotingSummary
Finishes voting.
Depending on type of voting, different actions are performed.
For informal voting a new formal voting can be created. Reputation staked for this voting is returned to the voters, except for the creator. When voting passes, it is used as a stake for a new voting, otherwise it is burned.
For formal voting an action will be performed if the result is in favor
. Reputation is redistributed to the winning voters.
When no quorum is reached, the reputation is returned, except for the creator - its reputation is then burned.
§Events
§Errors
FinishingCompletedVotingNotAllowed
if trying to complete already finished voting.FormalVotingTimeNotReached
if formal voting time did not pass.InformalVotingTimeNotReached
if informal voting time did not pass.ArithmeticOverflow
in an unlikely event of a overflow when calculating reputation to redistribute.
sourcepub fn cancel_finished_voting(&mut self, voting_id: VotingId)
pub fn cancel_finished_voting(&mut self, voting_id: VotingId)
Cancels finished voting if CancelFinishedVotingTimeout has passed.
sourcepub fn finish_voting_without_token_redistribution(
&mut self,
voting_id: VotingId,
configuration: &mut Configuration
) -> VotingSummary
pub fn finish_voting_without_token_redistribution( &mut self, voting_id: VotingId, configuration: &mut Configuration ) -> VotingSummary
Marks voting finished but do nothing with the staked reputation.
§Errors
Error::VotingDoesNotExist
- voting with the given id does not exists.Error::FinishingCompletedVotingNotAllowed
- voting is finished already.
sourcepub fn vote(
&mut self,
voter: Address,
voting_id: VotingId,
voting_type: VotingType,
choice: Choice,
stake: Balance
)
pub fn vote( &mut self, voter: Address, voting_id: VotingId, voting_type: VotingType, choice: Choice, stake: Balance )
Writes a vote in the storage.
§Events
§Errors
VoteOnCompletedVotingNotAllowed
if voting is completed.CannotVoteTwice
if the voter already voted.
sourcepub fn cast_ballot(
&mut self,
voter: Address,
choice: Choice,
stake: Balance,
unbound: bool,
voting: &mut VotingStateMachine,
configuration: &Configuration
)
pub fn cast_ballot( &mut self, voter: Address, choice: Choice, stake: Balance, unbound: bool, voting: &mut VotingStateMachine, configuration: &Configuration )
Records voter’s vote.
Writes into the storage the vote details and stakes reputation (for a bound ballot).
Calls Reputation Token Contract to stake reputation.
§Events
BallotCast
event.
sourcepub fn all_voters(
&self,
voting_id: VotingId,
voting_type: VotingType
) -> Vec<Address>
pub fn all_voters( &self, voting_id: VotingId, voting_type: VotingType ) -> Vec<Address>
Gets a vector of all voters’ addresses.
sourcepub fn get_ballot(
&self,
voting_id: VotingId,
voting_type: VotingType,
address: Address
) -> Option<Ballot>
pub fn get_ballot( &self, voting_id: VotingId, voting_type: VotingType, address: Address ) -> Option<Ballot>
Returns the Voter’s Ballot
.
sourcepub fn get_ballot_at(
&self,
voting_id: VotingId,
voting_type: VotingType,
i: u32
) -> Ballot
pub fn get_ballot_at( &self, voting_id: VotingId, voting_type: VotingType, i: u32 ) -> Ballot
Returns the nth Ballot of voting with a given id.
sourcepub fn get_voter(
&self,
voting_id: VotingId,
voting_type: VotingType,
at: u32
) -> Option<Address>
pub fn get_voter( &self, voting_id: VotingId, voting_type: VotingType, at: u32 ) -> Option<Address>
Returns the address of the nth voter who voted on Voting with a given id.
sourcepub fn get_voting(&self, voting_id: VotingId) -> Option<VotingStateMachine>
pub fn get_voting(&self, voting_id: VotingId) -> Option<VotingStateMachine>
Returns the Voting for a given id.
sourcepub fn get_voting_or_revert(&self, voting_id: VotingId) -> VotingStateMachine
pub fn get_voting_or_revert(&self, voting_id: VotingId) -> VotingStateMachine
Gets voting with a given id or stops contract execution.
§Errors
- Error::VotingDoesNotExist if the given id does not exist.
sourcepub fn get_configuration_or_revert(&self, voting_id: VotingId) -> Configuration
pub fn get_configuration_or_revert(&self, voting_id: VotingId) -> Configuration
Gets configuration with a given voting_id or stops contract execution.
§Error
- Error::ConfigurationNotFound if the given id does not exist.
sourcepub fn set_voting(&mut self, voting: VotingStateMachine)
pub fn set_voting(&mut self, voting: VotingStateMachine)
Updates voting storage.
sourcepub fn unstake_all_reputation(
&mut self,
voting_id: VotingId,
voting_type: VotingType
) -> BTreeMap<Address, Balance>
pub fn unstake_all_reputation( &mut self, voting_id: VotingId, voting_type: VotingType ) -> BTreeMap<Address, Balance>
Iterates over all the ballots and unstakes reputation. Returns a map of address to it’s stake.
Calls Reputation Token Contract to perform unstake operation.
sourcepub fn voters(
&self,
voting_id: VotingId,
voting_type: VotingType
) -> List<Address>
pub fn voters( &self, voting_id: VotingId, voting_type: VotingType ) -> List<Address>
Get the governance voting’s voters list.
sourcepub fn voters_count(&self, voting_id: VotingId, voting_type: VotingType) -> u32
pub fn voters_count(&self, voting_id: VotingId, voting_type: VotingType) -> u32
Gets the total number of users participated in voting.
sourcepub fn voting_exists(
&self,
voting_id: VotingId,
voting_type: VotingType
) -> bool
pub fn voting_exists( &self, voting_id: VotingId, voting_type: VotingType ) -> bool
Checks if voting with the given id and type exists.
sourcepub fn slash_voter(&mut self, voter: Address) -> SlashedVotings
pub fn slash_voter(&mut self, voter: Address) -> SlashedVotings
Erases a voter from all active votings.
If the voter is also the creator, voting is canceled. Otherwise, only his vote is invalidated.
Returns a tuple of vectors listing canceled and affected votings.j
Trait Implementations§
source§impl Clone for VotingEngine
impl Clone for VotingEngine
source§fn clone(&self) -> VotingEngine
fn clone(&self) -> VotingEngine
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more