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:

  1. Informal voting
  2. 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:

  1. Reputation Token to handle reputation staking.
  2. Variable Repo for reading voting configuration.

For example implementation see AdminContract.

Implementations§

source§

impl VotingEngine

source

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
source

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
source

pub fn cancel_finished_voting(&mut self, voting_id: VotingId)

Cancels finished voting if CancelFinishedVotingTimeout has passed.

source

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
source

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
source

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
source

pub fn all_voters( &self, voting_id: VotingId, voting_type: VotingType ) -> Vec<Address>

Gets a vector of all voters’ addresses.

source

pub fn get_ballot( &self, voting_id: VotingId, voting_type: VotingType, address: Address ) -> Option<Ballot>

Returns the Voter’s Ballot.

source

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.

source

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.

source

pub fn get_voting(&self, voting_id: VotingId) -> Option<VotingStateMachine>

Returns the Voting for a given id.

source

pub fn get_voting_or_revert(&self, voting_id: VotingId) -> VotingStateMachine

Gets voting with a given id or stops contract execution.

§Errors
source

pub fn get_configuration_or_revert(&self, voting_id: VotingId) -> Configuration

Gets configuration with a given voting_id or stops contract execution.

§Error
source

pub fn set_voting(&mut self, voting: VotingStateMachine)

Updates voting storage.

source

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.

source

pub fn voters( &self, voting_id: VotingId, voting_type: VotingType ) -> List<Address>

Get the governance voting’s voters list.

source

pub fn voters_count(&self, voting_id: VotingId, voting_type: VotingType) -> u32

Gets the total number of users participated in voting.

source

pub fn voting_exists( &self, voting_id: VotingId, voting_type: VotingType ) -> bool

Checks if voting with the given id and type exists.

source

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

source§

fn clone(&self) -> VotingEngine

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl DynamicInstance for VotingEngine

source§

fn instance(namespace: &[u8]) -> Self

source§

impl HasEvents for VotingEngine

source§

fn events() -> Vec<Event>

source§

impl Node for VotingEngine

source§

const IS_LEAF: bool = false

source§

const COUNT: u32 = 9u32

source§

fn __keys() -> Vec<String>

source§

impl OdraItem for VotingEngine

source§

impl StaticInstance for VotingEngine

source§

fn instance<'a>(keys: &'a [&'a str]) -> (Self, &'a [&'a str])

Consumes keys required to create an instance, returns the instance with the remaining keys.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.