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 byon_vote
will still persist
§Hook Methods
-
on_vote
: Called before a vote is recorded. ReturnsErr
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 foron_vote
benchmarkingon_remove_vote_worst_case
: Sets up worst-case state foron_remove_vote
benchmarking
§Generic Parameters
AccountId
: The type used to identify accounts in the systemIndex
: The type used for referendum indicesBalance
: The type used for balance values
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>
Sourcefn on_vote_worst_case(who: &AccountId)
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.
Sourcefn on_remove_vote_worst_case(who: &AccountId)
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.