pub trait AuthorPoints<Author, Points>{
// Required methods
fn points_of(author: &Author) -> Result<Points, DispatchError>;
fn iter_points() -> impl Iterator<Item = (Author, Points)>;
fn set_points(author: &Author, points: Points) -> DispatchResult;
fn clear_points();
// Provided method
fn add_point(author: &Author) -> DispatchResult { ... }
}Expand description
Trait representing temporary, abstract points assigned to authors.
These points are not finalized rewards or assets, but rather a lightweight mechanism to track “good behavior” or participation within a specific, temporary context, such as:
- A single author round.
- A session of block production.
- A single task or contribution that is ephemeral in nature.
§Design notes
- Points are incremented one at a time using
Self::add_point, rather than in bulk. This enforces a clear, single-event granularity per point. It also simplifies logic for ephemeral metrics and prevents accidental double-counting. - Different implementations of this trait can represent distinct points systems or contexts. For example, one implementation could track “block production points”, while another tracks “validation participation points”.
§Ephemeral behavior
- Points do not correspond to finalized payments or balances.
- They are temporary: cleared via
Self::clear_pointsat the end of the round or session. - They provide a way to accumulate good behavior metrics for temporary evaluation.
§Type Parameters
Author: The entity receiving points (e.g.,AccountIdor validator identifier).Points: The numeric type representing points; typicallyu32,u64. This type can be used to compute metrics, rankings, or temporary rewards.
Required Methods§
Sourcefn points_of(author: &Author) -> Result<Points, DispatchError>
fn points_of(author: &Author) -> Result<Points, DispatchError>
Returns the current points of a given author, if any.
Points are temporary and reflect only the current round or session.
Returns a DispatchError if there is an issue reading storage or runtime state.
§Parameters
author: The author whose points are queried.
§Returns
Ok(points)if the author has points.Err(DispatchError)if reading fails.
Sourcefn iter_points() -> impl Iterator<Item = (Author, Points)>
fn iter_points() -> impl Iterator<Item = (Author, Points)>
Returns an iterator over all authors and their current points.
This provides a view of the entire ephemeral points state for the current round or session, typically used by runtime operations such as reward computation, ranking, or evaluation.
Since points are ephemeral, any such operation is expected to
eventually clear them via Self::clear_points, which is left to
the caller’s discretion.
§Returns
- An iterator yielding
(Author, Points)pairs.
Sourcefn set_points(author: &Author, points: Points) -> DispatchResult
fn set_points(author: &Author, points: Points) -> DispatchResult
Sets the points for a given author.
This is the primitive write operation for point state. All mutations to points (including increments) should be expressed in terms of this method to ensure consistency.
§Returns
Ok(())if the update succeeds.Err(DispatchError)if the operation fails.
Sourcefn clear_points()
fn clear_points()
Clears all points for all authors.
- Typically called at the end of a round or session to reset the ephemeral scoring.
- Ensures the points system remains context-specific and avoids carry-over between rounds.
Provided Methods§
Sourcefn add_point(author: &Author) -> DispatchResult
fn add_point(author: &Author) -> DispatchResult
Adds a single point to a given author.
Each invocation represents one unit of contribution or good behavior. For bulk or weighted increments, implementers could wrap this in higher-level logic externally, keeping the trait focused on single-point increments.
This default implementation:
- Reads the current points (or assumes zero if none exist)
- Performs a saturating addition of one point
- Writes the updated value via
Self::set_points
Returns a DispatchError if updating fails (e.g., storage error or overflow).
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.