Skip to content

add staking/election related view functions #8337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 2, 2025
12 changes: 12 additions & 0 deletions prdoc/pr_8337.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
title: add staking/election related view functions
doc:
- audience: Runtime Dev
description: |-
Adds two self-explanatory view functions to staking/election related pallets.
To be used by wallets wishing to perform rebag operation, and use by staking miner(s) to know
how much deposit they need in advance.
crates:
- name: pallet-bags-list
bump: patch
- name: pallet-election-provider-multi-block
bump: patch
12 changes: 12 additions & 0 deletions substrate/frame/bags-list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ pub mod pallet {
}
}

#[pallet::view_functions]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Get the current `score` of a given account.
///
/// Returns `(current, real_score)`.
///
/// If the two differ, it probably means this node is eligible for [`Call::rebag`].
pub fn scores(who: T::AccountId) -> (Option<T::Score>, Option<T::Score>) {
(ListNodes::<T, I>::get(&who).map(|node| node.score), T::ScoreProvider::score(&who))
}
}

#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Declare that some `dislocated` account has, through rewards or penalties, sufficiently
Expand Down
11 changes: 11 additions & 0 deletions substrate/frame/election-provider-multi-block/src/signed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,17 @@
}
}

#[pallet::view_functions]
impl<T: Config> Pallet<T> {
/// Get the deposit amount that will be held for a solution of `p` pages.
///
/// This allows an offchain application to know what [`Config::DepositPerPage`] and
/// [`Config::DepositBase`] are doing under the hood.
pub fn deposit_for(p: u32) -> BalanceOf<T> {
Self::deposit_for(p as usize)

Check failure on line 896 in substrate/frame/election-provider-multi-block/src/signed/mod.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

mismatched types
}
}

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
Expand Down
Loading