referrerpolicy=no-referrer-when-downgrade
pallet_conviction_voting

Trait VotingHooks

Source
pub trait VotingHooks<AccountId, Index, Balance> {
    // Required methods
    fn on_before_vote(
        who: &AccountId,
        ref_index: Index,
        vote: AccountVote<Balance>,
    ) -> DispatchResult;
    fn on_remove_vote(who: &AccountId, ref_index: Index, status: Status);
    fn lock_balance_on_unsuccessful_vote(
        who: &AccountId,
        ref_index: Index,
    ) -> Option<Balance>;
    fn on_vote_worst_case(who: &AccountId);
    fn on_remove_vote_worst_case(who: &AccountId);
}
Expand description

Trait for voting hooks that are called during various stages of the voting process.

§Important Note

These hooks are called BEFORE the actual vote is recorded in storage. This means:

  • If on_vote returns an error, the entire voting operation will be reverted
  • If on_vote succeeds but the voting operation fails later, any storage modifications made by on_vote will still persist

§Hook Methods

  • on_vote: Called before a vote is recorded. Returns Err to prevent the vote from being recorded. Storage modifications made by this hook will persist even if the vote fails later.

  • on_remove_vote: Called before a vote is removed. Cannot fail.

  • lock_balance_on_unsuccessful_vote: Called when a vote fails to be recorded (e.g. due to insufficient balance). Returns optionally locked balance amount.

§Benchmarking Hooks

The following methods are only used during runtime benchmarking:

  • on_vote_worst_case: Sets up worst-case state for on_vote benchmarking
  • on_remove_vote_worst_case: Sets up worst-case state for on_remove_vote benchmarking

§Generic Parameters

  • AccountId: The type used to identify accounts in the system
  • Index: The type used for referendum indices
  • Balance: The type used for balance values

Required Methods§

Source

fn on_before_vote( who: &AccountId, ref_index: Index, vote: AccountVote<Balance>, ) -> DispatchResult

Source

fn on_remove_vote(who: &AccountId, ref_index: Index, status: Status)

Source

fn lock_balance_on_unsuccessful_vote( who: &AccountId, ref_index: Index, ) -> Option<Balance>

Source

fn on_vote_worst_case(who: &AccountId)

Will be called by benchmarking before calling on_vote in a benchmark.

Should setup the state in such a way that when on_vote is called it will take the worst case path performance wise.

Source

fn on_remove_vote_worst_case(who: &AccountId)

Will be called by benchmarking before calling on_remove_vote in a benchmark.

Should setup the state in such a way that when on_remove_vote is called it will
take the worst case path performance wise.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<A, I, B> VotingHooks<A, I, B> for ()

Source§

fn on_before_vote( _who: &A, _ref_index: I, _vote: AccountVote<B>, ) -> DispatchResult

Source§

fn on_remove_vote(_who: &A, _ref_index: I, _status: Status)

Source§

fn lock_balance_on_unsuccessful_vote(_who: &A, _ref_index: I) -> Option<B>

Source§

fn on_vote_worst_case(_who: &A)

Source§

fn on_remove_vote_worst_case(_who: &A)

Implementors§