-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Rpc for pending rewards #11831
Rpc for pending rewards #11831
Changes from 45 commits
5e4ab1e
f548a89
26004a3
08bcda5
9b5cf9e
180f7ef
0d50df7
c95d155
611d410
6419f43
a9582a0
830ae63
e9b183b
b3b3e18
cf98349
3978023
c8273c2
3a866ff
3266173
34857e5
ff745f1
29fa77c
3beb5ba
83a1b3f
3eeb3e6
24c1230
685a116
756f1b0
36dfaf3
2c26af8
23d2b67
6b8968a
6d976b3
5650a9a
1bb1bd6
5357b48
2fef04c
0d9477f
3964f8c
8d26315
f38fded
7f0b4b3
6a25e61
38f5cf0
b53a766
ebd072c
f65f9df
c198ade
75d72f4
8528ba2
c17560b
18cb8f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| [package] | ||
| name = "pallet-nomination-pools-rpc" | ||
| version = "1.0.0-dev" | ||
| authors = ["Parity Technologies <[email protected]>"] | ||
| edition = "2021" | ||
| license = "Apache-2.0" | ||
| homepage = "https://substrate.io" | ||
| repository = "https://github.com/paritytech/substrate/" | ||
| description = "RPC interface for the nomination-pools pallet." | ||
| readme = "README.md" | ||
|
|
||
| [package.metadata.docs.rs] | ||
| targets = ["x86_64-unknown-linux-gnu"] | ||
|
|
||
| [dependencies] | ||
| codec = { package = "parity-scale-codec", version = "3.0.0" } | ||
| jsonrpsee = { version = "0.14.0", features = ["server", "macros"] } | ||
|
|
||
| sp-api = { version = "4.0.0-dev", path = "../../../primitives/api" } | ||
| sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" } | ||
| sp-core = { version = "6.0.0", path = "../../../primitives/core" } | ||
| sp-rpc = { version = "6.0.0", path = "../../../primitives/rpc" } | ||
| sp-runtime = { version = "6.0.0", path = "../../../primitives/runtime" } | ||
| pallet-nomination-pools-rpc-runtime-api = { path = "./runtime-api" } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| [package] | ||
Szegoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| name = "pallet-nomination-pools-rpc-runtime-api" | ||
| version = "1.0.0-dev" | ||
| authors = ["Parity Technologies <[email protected]>"] | ||
| edition = "2021" | ||
| license = "Apache-2.0" | ||
| homepage = "https://substrate.io" | ||
| repository = "https://github.com/paritytech/substrate/" | ||
| description = "RPC runtime API for nomination-pools FRAME pallet" | ||
| readme = "README.md" | ||
|
|
||
| [package.metadata.docs.rs] | ||
| targets = ["x86_64-unknown-linux-gnu"] | ||
|
|
||
| [dependencies] | ||
| codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } | ||
| sp-api = { version = "4.0.0-dev", default-features = false, path = "../../../../primitives/api" } | ||
| sp-std = { version = "4.0.0-dev", default-features = false, path = "../../../../primitives/std" } | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "codec/std", | ||
| "sp-api/std", | ||
| "sp-std/std", | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Runtime API definition for nomination-pools pallet. | ||
|
|
||
| License: Apache-2.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) 2022 Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| //! Runtime API definition for nomination-pools pallet. | ||
| //! Currently supports only one rpc endpoint. | ||
| #![cfg_attr(not(feature = "std"), no_std)] | ||
|
|
||
| use codec::Codec; | ||
|
|
||
| sp_api::decl_runtime_apis! { | ||
| pub trait NominationPoolsApi<AccountId, Balance> | ||
Szegoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| where AccountId: Codec, Balance: Codec | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason, the cc: @kianenigma
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where are you running into this issue?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When building westend and kusama runtimes locally and on the companion CI check(https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1692761)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm yeah I think the companion system is not able to pickup new crates unfortunately.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, for now, let's not add the PRC endpoint anywhere and only add the new runtime api. This can already be called by the |
||
| { | ||
| /// Returns the pending rewards for the member that the AccountId was given for. | ||
| fn pending_rewards(member: AccountId) -> Balance; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| RPC interface for the nomination-pools pallet. | ||
|
|
||
| License: Apache-2.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // This file is part of Substrate. | ||
Szegoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Copyright (C) 2022 Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| //! RPC interface for the nomination-pools pallet. | ||
| //! Currently supports only one rpc endpoint. | ||
| use codec::Codec; | ||
| use jsonrpsee::{ | ||
| core::{async_trait, RpcResult}, | ||
| proc_macros::rpc, | ||
| }; | ||
| pub use pallet_nomination_pools_rpc_runtime_api::NominationPoolsApi as NominationPoolsRuntimeApi; | ||
| use sp_api::ProvideRuntimeApi; | ||
| use sp_blockchain::HeaderBackend; | ||
| use sp_runtime::{generic::BlockId, traits::Block as BlockT}; | ||
| use std::sync::Arc; | ||
|
|
||
| #[rpc(client, server)] | ||
| pub trait NominationPoolsRpc<BlockHash, AccountId, ResponseType> { | ||
| #[method(name = "nominationPools_pending_rewards")] | ||
| fn pending_rewards(&self, member: AccountId, at: Option<BlockHash>) -> RpcResult<ResponseType>; | ||
| } | ||
|
|
||
| pub struct NominationPoolsRpcType<C, P> { | ||
| client: Arc<C>, | ||
| _marker: std::marker::PhantomData<P>, | ||
| } | ||
|
|
||
| impl<C, P> NominationPoolsRpcType<C, P> { | ||
| pub fn new(client: Arc<C>) -> Self { | ||
| Self { client, _marker: Default::default() } | ||
| } | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl<C, Block, AccountId, Balance> | ||
| NominationPoolsRpcServer<<Block as BlockT>::Hash, AccountId, Balance> | ||
| for NominationPoolsRpcType<C, Block> | ||
Szegoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| where | ||
| Block: BlockT, | ||
| C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>, | ||
| C::Api: NominationPoolsRuntimeApi<Block, AccountId, Balance>, | ||
| AccountId: Codec, | ||
| Balance: Codec + Default, | ||
| { | ||
| fn pending_rewards(&self, member: AccountId, at: Option<Block::Hash>) -> RpcResult<Balance> { | ||
| let api = self.client.runtime_api(); | ||
| let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash)); | ||
|
|
||
| Ok(api.pending_rewards(&at, member).unwrap_or_default()) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.