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

source

pub fn new(voting_id: VotingId, created_at: u64, creator: Address) -> Self

Creates new Voting with immutable Configuration.

source

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.

source

pub fn finish(&mut self)

Ends the voting process gracefully.

source

pub fn cancel(&mut self)

Ends the voting process forcefully and cancels the result.

source

pub fn voting_type(&self) -> VotingType

Returns the type of Voting.

source

pub fn is_informal_without_stake(&self, configuration: &Configuration) -> bool

Checks if Voting is of type Informal and stakes the reputation.

source

pub fn is_in_time(&self, block_time: u64, configuration: &Configuration) -> bool

Checks if Voting is still in the voting phase.

source

pub fn informal_voting_end_time( &self, configuration: &Configuration ) -> BlockTime

Gets the informal phase end time.

source

pub fn time_between_votings_end_time( &self, configuration: &Configuration ) -> BlockTime

Gets the informal-formal break end time.

source

pub fn formal_voting_end_time(&self, configuration: &Configuration) -> BlockTime

Gets the informal phase end time.

source

pub fn is_in_favor(&self) -> bool

Checks is the in_favor stake surpasses the against stake.

source

pub fn get_winning_stake(&self) -> Balance

Depending on the result of the voting, returns the amount of reputation staked on the winning side.

source

pub fn get_result( &self, voters_number: u32, configuration: &Configuration ) -> VotingResult

Gets the current voting result.

source

pub fn add_stake(&mut self, stake: Balance, choice: Choice)

Adds the stake to the total bound stake.

source

pub fn add_unbound_stake(&mut self, stake: Balance, choice: Choice)

Adds the stake to the total unbound stake.

source

pub fn remove_stake(&mut self, stake: Balance, choice: Choice)

Removes the stake from the total bound stake.

source

pub fn remove_unbound_stake(&mut self, stake: Balance, choice: Choice)

Removes the stake from the total unbound stake.

source

pub fn bind_stake(&mut self, stake: Balance, choice: Choice)

Removes the unbound stake and adds it to the bound stake.

source

pub fn total_stake(&self) -> Balance

Gets the sum of bound and unbound stake.

source

pub fn total_bound_stake(&self) -> Balance

Gets the total bound stake.

source

pub fn total_unbound_stake(&self) -> Balance

Gets the total unbound stake.

source

pub fn voting_id(&self) -> VotingId

Get the voting’s voting id.

source

pub fn stake_in_favor(&self) -> Balance

Get the voting’s stake in favor.

source

pub fn stake_against(&self) -> Balance

Get the voting’s stake against.

source

pub fn creator(&self) -> &Address

Gets the voting creator.

source

pub fn state(&self) -> &VotingState

Gets the current voting state.

source

pub fn completed(&self) -> bool

Indicates if Voting is finished or canceled.

source

pub fn state_in_time( &self, block_time: BlockTime, configuration: &Configuration ) -> VotingState

Returns the voting state depending on a given block_time.

source

pub fn informal_stats(&self) -> &Stats

Gets the Informal Voting statistics.

source

pub fn formal_stats(&self) -> &Stats

Gets the Formal Voting statistics.

source

pub fn created_at(&self) -> u64

source

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.

source

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.

source

pub fn guard_cancel_finished_voting( &self, block_time: BlockTime, configuration: &Configuration )

Trait Implementations§

source§

impl BorshDeserialize for VotingStateMachine

source§

fn deserialize(buf: &mut &[u8]) -> Result<Self>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
source§

impl BorshSerialize for VotingStateMachine

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>

§

fn try_to_vec(&self) -> Result<Vec<u8>, Error>

Serialize this instance into a vector of bytes.
source§

impl Clone for VotingStateMachine

source§

fn clone(&self) -> VotingStateMachine

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 Debug for VotingStateMachine

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl OdraItem for VotingStateMachine

source§

fn is_module() -> bool

§

fn events() -> Vec<Event>

source§

impl Typed for VotingStateMachine

source§

fn ty() -> Type

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.

§

impl<T> OdraType for T
where T: MockSerializable + MockDeserializable,

§

fn serialize(&self) -> Option<Vec<u8>>

Serializes the value.
§

fn deserialize(bytes: &[u8]) -> Option<Self>

Deserializes the value.
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.