This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Rpc for pending rewards #11831
Merged
Merged
Rpc for pending rewards #11831
Changes from 10 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
5e4ab1e
rpc pending rewards
Szegoo f548a89
commit
Szegoo 26004a3
remove unused imports
Szegoo 08bcda5
fix
Szegoo 9b5cf9e
fix
Szegoo 180f7ef
fmt
Szegoo 0d50df7
fix
Szegoo c95d155
fmt
Szegoo 611d410
fix
Szegoo 6419f43
docs
Szegoo a9582a0
docs & formatting
Szegoo 830ae63
better formatting
Szegoo e9b183b
temporary fix
Szegoo b3b3e18
error handling
Szegoo cf98349
fix?
Szegoo 3978023
fmt
Szegoo c8273c2
use to_string
Szegoo 3a866ff
fmt
Szegoo 3266173
fixed error handling
Szegoo 34857e5
fix
Szegoo ff745f1
rpc added to client
Szegoo 29fa77c
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo 3beb5ba
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo 83a1b3f
Update Cargo.toml
Szegoo 3eeb3e6
Update Cargo.toml
Szegoo 24c1230
fix wrong reward counter
Szegoo 685a116
expose function
Szegoo 756f1b0
move implementation
Szegoo 36dfaf3
docs
Szegoo 2c26af8
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo 23d2b67
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo 6b8968a
docs
Szegoo 6d976b3
docs
Szegoo 5650a9a
Update lib.rs
Szegoo 1bb1bd6
Update lib.rs
Szegoo 5357b48
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo 2fef04c
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo 0d9477f
unexpose functions
Szegoo 3964f8c
unused dependency
Szegoo 8d26315
update Cargo.lock
Szegoo f38fded
Update frame/nomination-pools/src/lib.rs
kianenigma 7f0b4b3
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo 6a25e61
Update lib.rs
Szegoo 38f5cf0
Update lib.rs
Szegoo b53a766
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo ebd072c
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo f65f9df
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo c198ade
Update frame/nomination-pools/rpc/runtime-api/src/lib.rs
Szegoo 75d72f4
remove rpc
Szegoo 8528ba2
Merge branch 'paritytech:master' into rpc-pending-rewards
Szegoo c17560b
remove rpc directory
Szegoo 18cb8f5
final fix
Szegoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| [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" } | ||
| jsonrpc-core = "18.0.0" | ||
| jsonrpc-core-client = "18.0.0" | ||
| jsonrpc-derive = "18.0.0" | ||
|
|
||
| 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" } | ||
Szegoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| [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" } | ||
| pallet-nomination-pools = { default-features = false, path = "../../" } | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "codec/std", | ||
| "sp-api/std", | ||
| "sp-std/std", | ||
| "pallet-nomination-pools/std", | ||
| ] | ||
Szegoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) 2019-2022 Parity Technologies (UK) Ltd. | ||
Szegoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // 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. | ||
| #![cfg_attr(not(feature = "std"), no_std)] | ||
|
|
||
| use codec::Codec; | ||
| pub use pallet_nomination_pools::PoolId; | ||
|
|
||
| sp_api::decl_runtime_apis! { | ||
| pub trait NominationPoolsApi<AccountId, Balance> where AccountId: Codec, Balance: Codec | ||
Szegoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| /// Returns the pending rewards for the given member. | ||
| fn pending_rewards(member: AccountId) -> Balance; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // This file is part of Substrate. | ||
Szegoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Copyright (C) 2019-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. | ||
|
|
||
| pub use self::gen_client::Client as NominationPoolsClient; | ||
| use codec::Codec; | ||
| use jsonrpc_core::Error; | ||
| use jsonrpc_derive::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] | ||
| pub trait NominationPoolsRpc<BlockHash, AccountId, ResponseType> { | ||
| #[rpc(name = "nompools_pending_rewards")] | ||
Szegoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fn pending_rewards( | ||
| &self, | ||
| member: AccountId, | ||
| at: Option<BlockHash>, | ||
| ) -> Result<ResponseType, Error>; | ||
| } | ||
|
|
||
| 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() } | ||
| } | ||
| } | ||
|
|
||
| impl<C, Block, AccountId, Balance> NominationPoolsRpc<<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, | ||
| { | ||
| fn pending_rewards( | ||
| &self, | ||
| member: AccountId, | ||
| at: Option<Block::Hash>, | ||
| ) -> Result<Balance, Error> { | ||
| 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, | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.