Rpc for pending rewards (#11831)

* rpc pending rewards

* commit

* remove unused imports

* fix

* fix

* fmt

* fix

* fmt

* fix

* docs

* docs & formatting

* better formatting

* temporary fix

* error handling

* fix?

* fmt

* use to_string

* fmt

* fixed error handling

* fix

* rpc added to client

* Update Cargo.toml

* Update Cargo.toml

* fix wrong reward counter

* expose function

* move implementation

* docs

* docs

* docs

* Update lib.rs

* Update lib.rs

* unexpose functions

* unused dependency

* update Cargo.lock

* Update frame/nomination-pools/src/lib.rs

* Update lib.rs

* Update lib.rs

* Update frame/nomination-pools/rpc/runtime-api/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* remove rpc

* remove rpc directory

* final fix

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Sergej Sakac
2022-07-26 11:06:48 +02:00
committed by GitHub
parent a37226d09e
commit cdfd2da02e
8 changed files with 96 additions and 1 deletions
+15 -1
View File
@@ -939,7 +939,7 @@ pub struct RewardPool<T: Config> {
impl<T: Config> RewardPool<T> {
/// Getter for [`RewardPool::last_recorded_reward_counter`].
fn last_recorded_reward_counter(&self) -> T::RewardCounter {
pub(crate) fn last_recorded_reward_counter(&self) -> T::RewardCounter {
self.last_recorded_reward_counter
}
@@ -2147,6 +2147,20 @@ pub mod pallet {
}
impl<T: Config> Pallet<T> {
/// Returns the pending rewards for the specified `member_account`.
///
/// In the case of error the function returns balance of zero.
pub fn pending_rewards(member_account: T::AccountId) -> BalanceOf<T> {
if let Some(pool_member) = PoolMembers::<T>::get(member_account) {
if let Some(reward_pool) = RewardPools::<T>::get(pool_member.pool_id) {
return pool_member
.pending_rewards(reward_pool.last_recorded_reward_counter())
.unwrap_or_default()
}
}
BalanceOf::<T>::default()
}
/// The amount of bond that MUST REMAIN IN BONDED in ALL POOLS.
///
/// It is the responsibility of the depositor to put these funds into the pool initially. Upon