Skip to content

Commit

Permalink
[Documentation] Add description for VoteTally's methods (#3140)
Browse files Browse the repository at this point in the history
# Description

While methods' names on [`VoteTally`][1] trait might be self-explanatory
at first sight, the distinction between `support` and `approval` can be
a bit ambiguous for some readers. This PR aims to clarify the
distinction and inform about the expected values for every not yet
documented method on this trait.

# Checklist

- [x] My PR includes a detailed description as outlined in the
"Description" section above
- [ ] My PR follows the [labeling requirements](CONTRIBUTING.md#Process)
of this project (at minimum one label for `T`
  required)
- [x] I have made corresponding changes to the documentation (if
applicable)
- [x] I have added tests that prove my fix is effective or that my
feature works (if applicable)

[1]:
https://docs.rs/frame-support/latest/frame_support/traits/trait.VoteTally.html

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
  • Loading branch information
pandres95 and bkchr committed Jan 31, 2024
1 parent 07e5500 commit 8a8f6f9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions substrate/frame/support/src/traits/voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,24 @@ use sp_runtime::{traits::Member, DispatchError};
use sp_std::prelude::*;

pub trait VoteTally<Votes, Class> {
/// Initializes a new tally.
fn new(_: Class) -> Self;
/// Returns the number of positive votes for the tally.
fn ayes(&self, class: Class) -> Votes;
/// Returns the approval ratio (positive to total votes) for the tally, without multipliers
/// (e.g. conviction, ranks, etc.).
fn support(&self, class: Class) -> Perbill;
/// Returns the approval ratio (positive to total votes) for the tally.
fn approval(&self, class: Class) -> Perbill;
/// Returns an instance of the tally representing a unanimous approval, for benchmarking
/// purposes.
#[cfg(feature = "runtime-benchmarks")]
fn unanimity(class: Class) -> Self;
/// Returns an instance of the tally representing a rejecting state, for benchmarking purposes.
#[cfg(feature = "runtime-benchmarks")]
fn rejection(class: Class) -> Self;
/// Returns an instance of the tally given some `approval` and `support`, for benchmarking
/// purposes.
#[cfg(feature = "runtime-benchmarks")]
fn from_requirements(support: Perbill, approval: Perbill, class: Class) -> Self;
#[cfg(feature = "runtime-benchmarks")]
Expand Down

0 comments on commit 8a8f6f9

Please sign in to comment.