Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
5e4ab1e
rpc pending rewards
Szegoo Jul 13, 2022
f548a89
commit
Szegoo Jul 13, 2022
26004a3
remove unused imports
Szegoo Jul 13, 2022
08bcda5
fix
Szegoo Jul 13, 2022
9b5cf9e
fix
Szegoo Jul 13, 2022
180f7ef
fmt
Szegoo Jul 13, 2022
0d50df7
fix
Szegoo Jul 14, 2022
c95d155
fmt
Szegoo Jul 14, 2022
611d410
fix
Szegoo Jul 14, 2022
6419f43
docs
Szegoo Jul 14, 2022
a9582a0
docs & formatting
Szegoo Jul 14, 2022
830ae63
better formatting
Szegoo Jul 14, 2022
e9b183b
temporary fix
Szegoo Jul 14, 2022
b3b3e18
error handling
Szegoo Jul 14, 2022
cf98349
fix?
Szegoo Jul 14, 2022
3978023
fmt
Szegoo Jul 14, 2022
c8273c2
use to_string
Szegoo Jul 14, 2022
3a866ff
fmt
Szegoo Jul 14, 2022
3266173
fixed error handling
Szegoo Jul 15, 2022
34857e5
fix
Szegoo Jul 15, 2022
ff745f1
rpc added to client
Szegoo Jul 15, 2022
29fa77c
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo Jul 16, 2022
3beb5ba
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo Jul 17, 2022
83a1b3f
Update Cargo.toml
Szegoo Jul 17, 2022
3eeb3e6
Update Cargo.toml
Szegoo Jul 17, 2022
24c1230
fix wrong reward counter
Szegoo Jul 17, 2022
685a116
expose function
Szegoo Jul 17, 2022
756f1b0
move implementation
Szegoo Jul 17, 2022
36dfaf3
docs
Szegoo Jul 17, 2022
2c26af8
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo Jul 17, 2022
23d2b67
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo Jul 18, 2022
6b8968a
docs
Szegoo Jul 18, 2022
6d976b3
docs
Szegoo Jul 18, 2022
5650a9a
Update lib.rs
Szegoo Jul 18, 2022
1bb1bd6
Update lib.rs
Szegoo Jul 18, 2022
5357b48
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo Jul 18, 2022
2fef04c
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo Jul 18, 2022
0d9477f
unexpose functions
Szegoo Jul 18, 2022
3964f8c
unused dependency
Szegoo Jul 19, 2022
8d26315
update Cargo.lock
Szegoo Jul 19, 2022
f38fded
Update frame/nomination-pools/src/lib.rs
kianenigma Jul 22, 2022
7f0b4b3
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo Jul 23, 2022
6a25e61
Update lib.rs
Szegoo Jul 23, 2022
38f5cf0
Update lib.rs
Szegoo Jul 23, 2022
b53a766
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo Jul 23, 2022
ebd072c
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo Jul 24, 2022
f65f9df
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo Jul 25, 2022
c198ade
Update frame/nomination-pools/rpc/runtime-api/src/lib.rs
Szegoo Jul 25, 2022
75d72f4
remove rpc
Szegoo Jul 25, 2022
8528ba2
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo Jul 26, 2022
c17560b
remove rpc directory
Szegoo Jul 26, 2022
18cb8f5
final fix
Szegoo Jul 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
error handling
  • Loading branch information
Szegoo committed Jul 14, 2022
commit b3b3e18bb816bc6bc9c7b6cb034ee90301856c3e
10 changes: 6 additions & 4 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ use pallet_grandpa::{
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_nomination_pools_rpc_runtime_api::NpApiError;
use pallet_session::historical::{self as pallet_session_historical};
pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment};
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
Expand Down Expand Up @@ -1836,10 +1837,11 @@ impl_runtime_apis! {
}

impl pallet_nomination_pools_rpc_runtime_api::NominationPoolsApi<Block, AccountId, Balance> for Runtime {
fn pending_rewards(member_account: AccountId) -> Balance {
let member = pallet_nomination_pools::PoolMembers::<Runtime>::get(member_account).unwrap();

member.pending_rewards(member.last_recorded_reward_counter).unwrap()
fn pending_rewards(member_account: AccountId) -> Result<Balance, NpApiError> {
if let Some(member) = pallet_nomination_pools::PoolMembers::<Runtime>::get(member_account) {
return member.pending_rewards(member.last_recorded_reward_counter).map_err(|_| NpApiError::OverflowInPendingRewards);
}
Err(NpApiError::MemberNotFound)
}
}

Expand Down
13 changes: 11 additions & 2 deletions frame/nomination-pools/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@

#![cfg_attr(not(feature = "std"), no_std)]

use codec::Codec;
use codec::{Codec, Decode, Encode};
pub use pallet_nomination_pools::PoolId;

/// The possible errors that may occur when getting the pending rewards.
#[derive(Decode, Encode, Eq, PartialEq)]
pub enum NpApiError {
/// The member was not found.
MemberNotFound,
/// An overflow occured when calculating the pending rewards.
OverflowInPendingRewards,
}

sp_api::decl_runtime_apis! {
pub trait NominationPoolsApi<AccountId, Balance>
where AccountId: Codec, Balance: Codec
{
/// Returns the pending rewards for the given member.
fn pending_rewards(member: AccountId) -> Balance;
fn pending_rewards(member: AccountId) -> Result<Balance, NpApiError>;
}
}
18 changes: 14 additions & 4 deletions frame/nomination-pools/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use codec::Codec;
use jsonrpc_core::Error;
use jsonrpc_derive::rpc;
pub use pallet_nomination_pools_rpc_runtime_api::NominationPoolsApi as NominationPoolsRuntimeApi;
use pallet_nomination_pools_rpc_runtime_api::NpApiError;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
Expand Down Expand Up @@ -65,10 +66,19 @@ where
let api = self.client.runtime_api();
let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash));

api.pending_rewards(&at, member).map_err(|e| Error {
code: jsonrpc_core::ErrorCode::ServerError(1),
message: format!("{:?}", e),
data: None,
api.pending_rewards(&at, member).map_err(|e| -> Error {
match e {
NpApiError::MemberNotFound => Error {
code: jsonrpc_core::ErrorCode::ServerError(1),
message: format!("Member with the given account was not found."),
data: None,
},
NpApiError::OverflowInPendingRewards => Error {
code: jsonrpc_core::ErrorCode::ServerError(2),
message: format!("An overflow occured when calculating the pending rewards."),
data: None,
},
}
})
}
}