From f237d4d5f44df0615ae57b183bae00aedd1fe5d7 Mon Sep 17 00:00:00 2001 From: koushiro Date: Thu, 19 May 2022 15:23:15 +0800 Subject: [PATCH 1/5] Unify rpc api and implementation name Signed-off-by: koushiro --- bin/node/rpc/src/lib.rs | 15 ++++-------- client/beefy/rpc/src/lib.rs | 23 ++++++++----------- client/rpc/src/state/mod.rs | 8 +++---- client/sync-state-rpc/src/lib.rs | 8 +++---- .../rpc/state-trie-migration-rpc/src/lib.rs | 8 +++---- 5 files changed, 26 insertions(+), 36 deletions(-) diff --git a/bin/node/rpc/src/lib.rs b/bin/node/rpc/src/lib.rs index 05aa973e102b1..515cfbf84d238 100644 --- a/bin/node/rpc/src/lib.rs +++ b/bin/node/rpc/src/lib.rs @@ -37,12 +37,10 @@ use jsonrpsee::RpcModule; use node_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Index}; use sc_client_api::AuxStore; use sc_consensus_babe::{Config, Epoch}; -use sc_consensus_babe_rpc::BabeRpc; use sc_consensus_epochs::SharedEpochChanges; use sc_finality_grandpa::{ FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState, }; -use sc_finality_grandpa_rpc::GrandpaRpc; use sc_rpc::SubscriptionTaskExecutor; pub use sc_rpc_api::DenyUnsafe; use sc_transaction_pool_api::TransactionPool; @@ -123,12 +121,12 @@ where use pallet_contracts_rpc::{ContractsApiServer, ContractsRpc}; use pallet_mmr_rpc::{MmrApiServer, MmrRpc}; use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPaymentRpc}; - use sc_consensus_babe_rpc::BabeApiServer; - use sc_finality_grandpa_rpc::GrandpaApiServer; + use sc_consensus_babe_rpc::{BabeApiServer, BabeRpc}; + use sc_finality_grandpa_rpc::{GrandpaApiServer, GrandpaRpc}; use sc_rpc::dev::{Dev, DevApiServer}; - use sc_sync_state_rpc::{SyncStateRpc, SyncStateRpcApiServer}; + use sc_sync_state_rpc::{SyncStateApiServer, SyncStateRpc}; use substrate_frame_rpc_system::{SystemApiServer, SystemRpc}; - use substrate_state_trie_migration_rpc::StateMigrationApiServer; + use substrate_state_trie_migration_rpc::{StateMigrationApiServer, StateMigrationRpc}; let mut io = RpcModule::new(()); let FullDeps { client, pool, select_chain, chain_spec, deny_unsafe, babe, grandpa } = deps; @@ -176,10 +174,7 @@ where .into_rpc(), )?; - io.merge( - substrate_state_trie_migration_rpc::MigrationRpc::new(client.clone(), backend, deny_unsafe) - .into_rpc(), - )?; + io.merge(StateMigrationRpc::new(client.clone(), backend, deny_unsafe).into_rpc())?; io.merge(Dev::new(client, deny_unsafe).into_rpc())?; Ok(io) diff --git a/client/beefy/rpc/src/lib.rs b/client/beefy/rpc/src/lib.rs index ea35678a48b8f..6ae06ebdc944c 100644 --- a/client/beefy/rpc/src/lib.rs +++ b/client/beefy/rpc/src/lib.rs @@ -100,13 +100,13 @@ pub trait BeefyApi { } /// Implements the BeefyApi RPC trait for interacting with BEEFY. -pub struct BeefyRpcHandler { +pub struct BeefyRpc { signed_commitment_stream: BeefySignedCommitmentStream, beefy_best_block: Arc>>, executor: SubscriptionTaskExecutor, } -impl BeefyRpcHandler +impl BeefyRpc where Block: BlockT, { @@ -131,8 +131,7 @@ where } #[async_trait] -impl BeefyApiServer - for BeefyRpcHandler +impl BeefyApiServer for BeefyRpc where Block: BlockT, { @@ -174,24 +173,20 @@ mod tests { use sp_runtime::traits::{BlakeTwo256, Hash}; use substrate_test_runtime_client::runtime::Block; - fn setup_io_handler() -> (RpcModule>, BeefySignedCommitmentSender) - { + fn setup_io_handler() -> (RpcModule>, BeefySignedCommitmentSender) { let (_, stream) = BeefyBestBlockStream::::channel(); setup_io_handler_with_best_block_stream(stream) } fn setup_io_handler_with_best_block_stream( best_block_stream: BeefyBestBlockStream, - ) -> (RpcModule>, BeefySignedCommitmentSender) { + ) -> (RpcModule>, BeefySignedCommitmentSender) { let (commitment_sender, commitment_stream) = BeefySignedCommitmentStream::::channel(); - let handler = BeefyRpcHandler::new( - commitment_stream, - best_block_stream, - sc_rpc::testing::test_executor(), - ) - .expect("Setting up the BEEFY RPC handler works"); + let handler = + BeefyRpc::new(commitment_stream, best_block_stream, sc_rpc::testing::test_executor()) + .expect("Setting up the BEEFY RPC handler works"); (handler.into_rpc(), commitment_sender) } @@ -203,7 +198,7 @@ mod tests { let expected_response = r#"{"jsonrpc":"2.0","error":{"code":1,"message":"BEEFY RPC endpoint not ready"},"id":1}"#.to_string(); let (result, _) = rpc.raw_json_request(&request).await.unwrap(); - assert_eq!(expected_response, result,); + assert_eq!(expected_response, result); } #[tokio::test] diff --git a/client/rpc/src/state/mod.rs b/client/rpc/src/state/mod.rs index a45651c5e7990..6bfe290e63dbd 100644 --- a/client/rpc/src/state/mod.rs +++ b/client/rpc/src/state/mod.rs @@ -168,7 +168,7 @@ pub fn new_full( executor: SubscriptionTaskExecutor, deny_unsafe: DenyUnsafe, rpc_max_payload: Option, -) -> (StateApi, ChildState) +) -> (State, ChildState) where Block: BlockT + 'static, Block::Hash: Unpin, @@ -193,18 +193,18 @@ where rpc_max_payload, )); let backend = Box::new(self::state_full::FullState::new(client, executor, rpc_max_payload)); - (StateApi { backend, deny_unsafe }, ChildState { backend: child_backend }) + (State { backend, deny_unsafe }, ChildState { backend: child_backend }) } /// State API with subscriptions support. -pub struct StateApi { +pub struct State { backend: Box>, /// Whether to deny unsafe calls deny_unsafe: DenyUnsafe, } #[async_trait] -impl StateApiServer for StateApi +impl StateApiServer for State where Block: BlockT + 'static, Client: Send + Sync + 'static, diff --git a/client/sync-state-rpc/src/lib.rs b/client/sync-state-rpc/src/lib.rs index 02a22a838b8b2..c99267cc6787d 100644 --- a/client/sync-state-rpc/src/lib.rs +++ b/client/sync-state-rpc/src/lib.rs @@ -42,7 +42,7 @@ #![deny(unused_crate_dependencies)] use jsonrpsee::{ - core::{Error as JsonRpseeError, RpcResult}, + core::{Error as RpcError, RpcResult}, proc_macros::rpc, types::{error::CallError, ErrorObject}, }; @@ -79,7 +79,7 @@ pub enum Error { LightSyncStateExtensionNotFound, } -impl From> for JsonRpseeError { +impl From> for RpcError { fn from(error: Error) -> Self { let message = match error { Error::JsonRpc(s) => s, @@ -125,7 +125,7 @@ pub struct LightSyncState { /// An api for sync state RPC calls. #[rpc(client, server)] -pub trait SyncStateRpcApi { +pub trait SyncStateApi { /// Returns the JSON serialized chainspec running the node, with a sync state. #[method(name = "sync_state_genSyncSpec")] fn system_gen_sync_spec(&self, raw: bool) -> RpcResult; @@ -180,7 +180,7 @@ where } } -impl SyncStateRpcApiServer for SyncStateRpc +impl SyncStateApiServer for SyncStateRpc where Block: BlockT, Backend: HeaderBackend + sc_client_api::AuxStore + 'static, diff --git a/utils/frame/rpc/state-trie-migration-rpc/src/lib.rs b/utils/frame/rpc/state-trie-migration-rpc/src/lib.rs index 531bf463f6523..91a03d18f346f 100644 --- a/utils/frame/rpc/state-trie-migration-rpc/src/lib.rs +++ b/utils/frame/rpc/state-trie-migration-rpc/src/lib.rs @@ -122,21 +122,21 @@ pub trait StateMigrationApi { } /// An implementation of state migration specific RPC methods. -pub struct MigrationRpc { +pub struct StateMigrationRpc { client: Arc, backend: Arc, deny_unsafe: DenyUnsafe, _marker: std::marker::PhantomData<(B, BA)>, } -impl MigrationRpc { +impl StateMigrationRpc { /// Create new state migration rpc for the given reference to the client. pub fn new(client: Arc, backend: Arc, deny_unsafe: DenyUnsafe) -> Self { - MigrationRpc { client, backend, deny_unsafe, _marker: Default::default() } + StateMigrationRpc { client, backend, deny_unsafe, _marker: Default::default() } } } -impl StateMigrationApiServer<::Hash> for MigrationRpc +impl StateMigrationApiServer<::Hash> for StateMigrationRpc where B: BlockT, C: Send + Sync + 'static + sc_client_api::HeaderBackend, From 7c32da893504550c4dec6feea18716a96d0f8987 Mon Sep 17 00:00:00 2001 From: koushiro Date: Thu, 19 May 2022 15:31:52 +0800 Subject: [PATCH 2/5] MauanlSeal ==> ManualSealRpc Signed-off-by: koushiro --- client/consensus/manual-seal/src/rpc.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/consensus/manual-seal/src/rpc.rs b/client/consensus/manual-seal/src/rpc.rs index b9bb06551f818..9043780e4aa59 100644 --- a/client/consensus/manual-seal/src/rpc.rs +++ b/client/consensus/manual-seal/src/rpc.rs @@ -86,7 +86,7 @@ pub trait ManualSealApi { } /// A struct that implements the [`ManualSealApiServer`]. -pub struct ManualSeal { +pub struct ManualSealRpc { import_block_channel: mpsc::Sender>, } @@ -99,7 +99,7 @@ pub struct CreatedBlock { pub aux: ImportedAux, } -impl ManualSeal { +impl ManualSealRpc { /// Create new `ManualSeal` with the given reference to the client. pub fn new(import_block_channel: mpsc::Sender>) -> Self { Self { import_block_channel } @@ -107,7 +107,7 @@ impl ManualSeal { } #[async_trait] -impl ManualSealApiServer for ManualSeal { +impl ManualSealApiServer for ManualSealRpc { async fn create_block( &self, create_empty: bool, From ad1b7cb19e899a7d9484cebbfb1689c8471490a7 Mon Sep 17 00:00:00 2001 From: koushiro Date: Fri, 20 May 2022 16:47:32 +0800 Subject: [PATCH 3/5] Remove extra Rpc naming in the structs Signed-off-by: koushiro --- bin/node-template/node/src/rpc.rs | 8 ++--- bin/node/rpc/src/lib.rs | 32 +++++++++---------- client/beefy/rpc/src/lib.rs | 12 +++---- client/consensus/babe/rpc/src/lib.rs | 10 +++--- client/consensus/manual-seal/src/rpc.rs | 6 ++-- client/finality-grandpa/rpc/src/lib.rs | 12 +++---- client/sync-state-rpc/src/lib.rs | 6 ++-- frame/contracts/rpc/src/lib.rs | 6 ++-- frame/merkle-mountain-range/rpc/src/lib.rs | 7 ++-- frame/transaction-payment/rpc/src/lib.rs | 6 ++-- .../rpc/state-trie-migration-rpc/src/lib.rs | 8 ++--- utils/frame/rpc/system/src/lib.rs | 14 ++++---- 12 files changed, 63 insertions(+), 64 deletions(-) diff --git a/bin/node-template/node/src/rpc.rs b/bin/node-template/node/src/rpc.rs index 7edae4d81474f..981f375d0b462 100644 --- a/bin/node-template/node/src/rpc.rs +++ b/bin/node-template/node/src/rpc.rs @@ -39,14 +39,14 @@ where C::Api: BlockBuilder, P: TransactionPool + 'static, { - use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPaymentRpc}; - use substrate_frame_rpc_system::{SystemApiServer, SystemRpc}; + use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; + use substrate_frame_rpc_system::{System, SystemApiServer}; let mut module = RpcModule::new(()); let FullDeps { client, pool, deny_unsafe } = deps; - module.merge(SystemRpc::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?; - module.merge(TransactionPaymentRpc::new(client).into_rpc())?; + module.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?; + module.merge(TransactionPayment::new(client).into_rpc())?; // Extend this RPC with a custom API by using the following syntax. // `YourRpcStruct` should have a reference to a client, which is needed diff --git a/bin/node/rpc/src/lib.rs b/bin/node/rpc/src/lib.rs index 515cfbf84d238..e5b666195e1bc 100644 --- a/bin/node/rpc/src/lib.rs +++ b/bin/node/rpc/src/lib.rs @@ -118,15 +118,15 @@ where B: sc_client_api::Backend + Send + Sync + 'static, B::State: sc_client_api::backend::StateBackend>, { - use pallet_contracts_rpc::{ContractsApiServer, ContractsRpc}; - use pallet_mmr_rpc::{MmrApiServer, MmrRpc}; - use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPaymentRpc}; - use sc_consensus_babe_rpc::{BabeApiServer, BabeRpc}; - use sc_finality_grandpa_rpc::{GrandpaApiServer, GrandpaRpc}; + use pallet_contracts_rpc::{Contracts, ContractsApiServer}; + use pallet_mmr_rpc::{Mmr, MmrApiServer}; + use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; + use sc_consensus_babe_rpc::{Babe, BabeApiServer}; + use sc_finality_grandpa_rpc::{Grandpa, GrandpaApiServer}; use sc_rpc::dev::{Dev, DevApiServer}; - use sc_sync_state_rpc::{SyncStateApiServer, SyncStateRpc}; - use substrate_frame_rpc_system::{SystemApiServer, SystemRpc}; - use substrate_state_trie_migration_rpc::{StateMigrationApiServer, StateMigrationRpc}; + use sc_sync_state_rpc::{SyncState, SyncStateApiServer}; + use substrate_frame_rpc_system::{System, SystemApiServer}; + use substrate_state_trie_migration_rpc::{StateMigration, StateMigrationApiServer}; let mut io = RpcModule::new(()); let FullDeps { client, pool, select_chain, chain_spec, deny_unsafe, babe, grandpa } = deps; @@ -140,15 +140,15 @@ where finality_provider, } = grandpa; - io.merge(SystemRpc::new(client.clone(), pool, deny_unsafe).into_rpc())?; + io.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?; // Making synchronous calls in light client freezes the browser currently, // more context: https://github.com/paritytech/substrate/pull/3480 // These RPCs should use an asynchronous caller instead. - io.merge(ContractsRpc::new(client.clone()).into_rpc())?; - io.merge(MmrRpc::new(client.clone()).into_rpc())?; - io.merge(TransactionPaymentRpc::new(client.clone()).into_rpc())?; + io.merge(Contracts::new(client.clone()).into_rpc())?; + io.merge(Mmr::new(client.clone()).into_rpc())?; + io.merge(TransactionPayment::new(client.clone()).into_rpc())?; io.merge( - BabeRpc::new( + Babe::new( client.clone(), shared_epoch_changes.clone(), keystore, @@ -159,7 +159,7 @@ where .into_rpc(), )?; io.merge( - GrandpaRpc::new( + Grandpa::new( subscription_executor, shared_authority_set.clone(), shared_voter_state, @@ -170,11 +170,11 @@ where )?; io.merge( - SyncStateRpc::new(chain_spec, client.clone(), shared_authority_set, shared_epoch_changes)? + SyncState::new(chain_spec, client.clone(), shared_authority_set, shared_epoch_changes)? .into_rpc(), )?; - io.merge(StateMigrationRpc::new(client.clone(), backend, deny_unsafe).into_rpc())?; + io.merge(StateMigration::new(client.clone(), backend, deny_unsafe).into_rpc())?; io.merge(Dev::new(client, deny_unsafe).into_rpc())?; Ok(io) diff --git a/client/beefy/rpc/src/lib.rs b/client/beefy/rpc/src/lib.rs index 6ae06ebdc944c..bad5bf96a1cf4 100644 --- a/client/beefy/rpc/src/lib.rs +++ b/client/beefy/rpc/src/lib.rs @@ -100,13 +100,13 @@ pub trait BeefyApi { } /// Implements the BeefyApi RPC trait for interacting with BEEFY. -pub struct BeefyRpc { +pub struct Beefy { signed_commitment_stream: BeefySignedCommitmentStream, beefy_best_block: Arc>>, executor: SubscriptionTaskExecutor, } -impl BeefyRpc +impl Beefy where Block: BlockT, { @@ -131,7 +131,7 @@ where } #[async_trait] -impl BeefyApiServer for BeefyRpc +impl BeefyApiServer for Beefy where Block: BlockT, { @@ -173,19 +173,19 @@ mod tests { use sp_runtime::traits::{BlakeTwo256, Hash}; use substrate_test_runtime_client::runtime::Block; - fn setup_io_handler() -> (RpcModule>, BeefySignedCommitmentSender) { + fn setup_io_handler() -> (RpcModule>, BeefySignedCommitmentSender) { let (_, stream) = BeefyBestBlockStream::::channel(); setup_io_handler_with_best_block_stream(stream) } fn setup_io_handler_with_best_block_stream( best_block_stream: BeefyBestBlockStream, - ) -> (RpcModule>, BeefySignedCommitmentSender) { + ) -> (RpcModule>, BeefySignedCommitmentSender) { let (commitment_sender, commitment_stream) = BeefySignedCommitmentStream::::channel(); let handler = - BeefyRpc::new(commitment_stream, best_block_stream, sc_rpc::testing::test_executor()) + Beefy::new(commitment_stream, best_block_stream, sc_rpc::testing::test_executor()) .expect("Setting up the BEEFY RPC handler works"); (handler.into_rpc(), commitment_sender) diff --git a/client/consensus/babe/rpc/src/lib.rs b/client/consensus/babe/rpc/src/lib.rs index d5f21606c62ed..9a8a87b98df53 100644 --- a/client/consensus/babe/rpc/src/lib.rs +++ b/client/consensus/babe/rpc/src/lib.rs @@ -49,7 +49,7 @@ pub trait BabeApi { } /// Provides RPC methods for interacting with Babe. -pub struct BabeRpc { +pub struct Babe { /// shared reference to the client. client: Arc, /// shared reference to EpochChanges @@ -64,7 +64,7 @@ pub struct BabeRpc { deny_unsafe: DenyUnsafe, } -impl BabeRpc { +impl Babe { /// Creates a new instance of the BabeRpc handler. pub fn new( client: Arc, @@ -79,7 +79,7 @@ impl BabeRpc { } #[async_trait] -impl BabeApiServer for BabeRpc +impl BabeApiServer for Babe where B: BlockT, C: ProvideRuntimeApi @@ -239,7 +239,7 @@ mod tests { fn test_babe_rpc_module( deny_unsafe: DenyUnsafe, - ) -> BabeRpc> { + ) -> Babe> { let builder = TestClientBuilder::new(); let (client, longest_chain) = builder.build_with_longest_chain(); let client = Arc::new(client); @@ -250,7 +250,7 @@ mod tests { let epoch_changes = link.epoch_changes().clone(); let keystore = create_temp_keystore::(Sr25519Keyring::Alice).0; - BabeRpc::new(client.clone(), epoch_changes, keystore, config, longest_chain, deny_unsafe) + Babe::new(client.clone(), epoch_changes, keystore, config, longest_chain, deny_unsafe) } #[tokio::test] diff --git a/client/consensus/manual-seal/src/rpc.rs b/client/consensus/manual-seal/src/rpc.rs index 9043780e4aa59..b9bb06551f818 100644 --- a/client/consensus/manual-seal/src/rpc.rs +++ b/client/consensus/manual-seal/src/rpc.rs @@ -86,7 +86,7 @@ pub trait ManualSealApi { } /// A struct that implements the [`ManualSealApiServer`]. -pub struct ManualSealRpc { +pub struct ManualSeal { import_block_channel: mpsc::Sender>, } @@ -99,7 +99,7 @@ pub struct CreatedBlock { pub aux: ImportedAux, } -impl ManualSealRpc { +impl ManualSeal { /// Create new `ManualSeal` with the given reference to the client. pub fn new(import_block_channel: mpsc::Sender>) -> Self { Self { import_block_channel } @@ -107,7 +107,7 @@ impl ManualSealRpc { } #[async_trait] -impl ManualSealApiServer for ManualSealRpc { +impl ManualSealApiServer for ManualSeal { async fn create_block( &self, create_empty: bool, diff --git a/client/finality-grandpa/rpc/src/lib.rs b/client/finality-grandpa/rpc/src/lib.rs index cb51d71b20bf4..6283c85e7a4f3 100644 --- a/client/finality-grandpa/rpc/src/lib.rs +++ b/client/finality-grandpa/rpc/src/lib.rs @@ -66,7 +66,7 @@ pub trait GrandpaApi { } /// Provides RPC methods for interacting with GRANDPA. -pub struct GrandpaRpc { +pub struct Grandpa { executor: SubscriptionTaskExecutor, authority_set: AuthoritySet, voter_state: VoterState, @@ -74,7 +74,7 @@ pub struct GrandpaRpc { finality_proof_provider: Arc, } impl - GrandpaRpc + Grandpa { /// Prepare a new [`GrandpaRpc`] pub fn new( @@ -91,7 +91,7 @@ impl #[async_trait] impl GrandpaApiServer> - for GrandpaRpc + for Grandpa where VoterState: ReportVoterState + Send + Sync + 'static, AuthoritySet: ReportAuthoritySet + Send + Sync + 'static, @@ -243,7 +243,7 @@ mod tests { fn setup_io_handler( voter_state: VoterState, ) -> ( - RpcModule>, + RpcModule>, GrandpaJustificationSender, ) where @@ -256,7 +256,7 @@ mod tests { voter_state: VoterState, finality_proof: Option>, ) -> ( - RpcModule>, + RpcModule>, GrandpaJustificationSender, ) where @@ -266,7 +266,7 @@ mod tests { let finality_proof_provider = Arc::new(TestFinalityProofProvider { finality_proof }); let executor = Arc::new(TaskExecutor::default()); - let rpc = GrandpaRpc::new( + let rpc = Grandpa::new( executor, TestAuthoritySet, voter_state, diff --git a/client/sync-state-rpc/src/lib.rs b/client/sync-state-rpc/src/lib.rs index c99267cc6787d..2eb611c515257 100644 --- a/client/sync-state-rpc/src/lib.rs +++ b/client/sync-state-rpc/src/lib.rs @@ -132,14 +132,14 @@ pub trait SyncStateApi { } /// An api for sync state RPC calls. -pub struct SyncStateRpc { +pub struct SyncState { chain_spec: Box, client: Arc, shared_authority_set: SharedAuthoritySet, shared_epoch_changes: SharedEpochChanges, } -impl SyncStateRpc +impl SyncState where Block: BlockT, Client: HeaderBackend + sc_client_api::AuxStore + 'static, @@ -180,7 +180,7 @@ where } } -impl SyncStateApiServer for SyncStateRpc +impl SyncStateApiServer for SyncState where Block: BlockT, Backend: HeaderBackend + sc_client_api::AuxStore + 'static, diff --git a/frame/contracts/rpc/src/lib.rs b/frame/contracts/rpc/src/lib.rs index 599e80676cb19..77ae3f3ed35e3 100644 --- a/frame/contracts/rpc/src/lib.rs +++ b/frame/contracts/rpc/src/lib.rs @@ -173,12 +173,12 @@ where } /// Contracts RPC methods. -pub struct ContractsRpc { +pub struct Contracts { client: Arc, _marker: PhantomData, } -impl ContractsRpc { +impl Contracts { /// Create new `Contracts` with the given reference to the client. pub fn new(client: Arc) -> Self { Self { client, _marker: Default::default() } @@ -193,7 +193,7 @@ impl AccountId, Balance, Hash, - > for ContractsRpc + > for Contracts where Block: BlockT, Client: Send + Sync + 'static + ProvideRuntimeApi + HeaderBackend, diff --git a/frame/merkle-mountain-range/rpc/src/lib.rs b/frame/merkle-mountain-range/rpc/src/lib.rs index 12e4e11f88256..75032d40f492a 100644 --- a/frame/merkle-mountain-range/rpc/src/lib.rs +++ b/frame/merkle-mountain-range/rpc/src/lib.rs @@ -131,12 +131,12 @@ pub trait MmrApi { } /// MMR RPC methods. -pub struct MmrRpc { +pub struct Mmr { client: Arc, _marker: PhantomData, } -impl MmrRpc { +impl Mmr { /// Create new `Mmr` with the given reference to the client. pub fn new(client: Arc) -> Self { Self { client, _marker: Default::default() } @@ -144,8 +144,7 @@ impl MmrRpc { } #[async_trait] -impl MmrApiServer<::Hash> - for MmrRpc +impl MmrApiServer<::Hash> for Mmr where Block: BlockT, Client: Send + Sync + 'static + ProvideRuntimeApi + HeaderBackend, diff --git a/frame/transaction-payment/rpc/src/lib.rs b/frame/transaction-payment/rpc/src/lib.rs index b0be19fdb22a9..5851d8ffef2d0 100644 --- a/frame/transaction-payment/rpc/src/lib.rs +++ b/frame/transaction-payment/rpc/src/lib.rs @@ -51,13 +51,13 @@ pub trait TransactionPaymentApi { } /// Provides RPC methods to query a dispatchable's class, weight and fee. -pub struct TransactionPaymentRpc { +pub struct TransactionPayment { /// Shared reference to the client. client: Arc, _marker: std::marker::PhantomData

, } -impl TransactionPaymentRpc { +impl TransactionPayment { /// Creates a new instance of the TransactionPaymentRpc helper. pub fn new(client: Arc) -> Self { Self { client, _marker: Default::default() } @@ -84,7 +84,7 @@ impl From for i32 { #[async_trait] impl TransactionPaymentApiServer<::Hash, RuntimeDispatchInfo> - for TransactionPaymentRpc + for TransactionPayment where Block: BlockT, C: ProvideRuntimeApi + HeaderBackend + Send + Sync + 'static, diff --git a/utils/frame/rpc/state-trie-migration-rpc/src/lib.rs b/utils/frame/rpc/state-trie-migration-rpc/src/lib.rs index 91a03d18f346f..b6d403ff2fcfd 100644 --- a/utils/frame/rpc/state-trie-migration-rpc/src/lib.rs +++ b/utils/frame/rpc/state-trie-migration-rpc/src/lib.rs @@ -122,21 +122,21 @@ pub trait StateMigrationApi { } /// An implementation of state migration specific RPC methods. -pub struct StateMigrationRpc { +pub struct StateMigration { client: Arc, backend: Arc, deny_unsafe: DenyUnsafe, _marker: std::marker::PhantomData<(B, BA)>, } -impl StateMigrationRpc { +impl StateMigration { /// Create new state migration rpc for the given reference to the client. pub fn new(client: Arc, backend: Arc, deny_unsafe: DenyUnsafe) -> Self { - StateMigrationRpc { client, backend, deny_unsafe, _marker: Default::default() } + StateMigration { client, backend, deny_unsafe, _marker: Default::default() } } } -impl StateMigrationApiServer<::Hash> for StateMigrationRpc +impl StateMigrationApiServer<::Hash> for StateMigration where B: BlockT, C: Send + Sync + 'static + sc_client_api::HeaderBackend, diff --git a/utils/frame/rpc/system/src/lib.rs b/utils/frame/rpc/system/src/lib.rs index b044035c8120e..72ad99e435f72 100644 --- a/utils/frame/rpc/system/src/lib.rs +++ b/utils/frame/rpc/system/src/lib.rs @@ -70,14 +70,14 @@ impl From for i32 { } /// An implementation of System-specific RPC methods on full client. -pub struct SystemRpc { +pub struct System { client: Arc, pool: Arc

, deny_unsafe: DenyUnsafe, _marker: std::marker::PhantomData, } -impl SystemRpc { +impl System { /// Create new `FullSystem` given client and transaction pool. pub fn new(client: Arc, pool: Arc

, deny_unsafe: DenyUnsafe) -> Self { Self { client, pool, deny_unsafe, _marker: Default::default() } @@ -86,7 +86,7 @@ impl SystemRpc { #[async_trait] impl - SystemApiServer<::Hash, AccountId, Index> for SystemRpc + SystemApiServer<::Hash, AccountId, Index> for System where C: sp_api::ProvideRuntimeApi, C: HeaderBackend, @@ -251,7 +251,7 @@ mod tests { let ext1 = new_transaction(1); block_on(pool.submit_one(&BlockId::number(0), source, ext1)).unwrap(); - let accounts = SystemRpc::new(client, pool, DenyUnsafe::Yes); + let accounts = System::new(client, pool, DenyUnsafe::Yes); // when let nonce = accounts.nonce(AccountKeyring::Alice.into()).await; @@ -270,7 +270,7 @@ mod tests { let pool = BasicPool::new_full(Default::default(), true.into(), None, spawner, client.clone()); - let accounts = SystemRpc::new(client, pool, DenyUnsafe::Yes); + let accounts = System::new(client, pool, DenyUnsafe::Yes); // when let res = accounts.dry_run(vec![].into(), None).await; @@ -289,7 +289,7 @@ mod tests { let pool = BasicPool::new_full(Default::default(), true.into(), None, spawner, client.clone()); - let accounts = SystemRpc::new(client, pool, DenyUnsafe::No); + let accounts = System::new(client, pool, DenyUnsafe::No); let tx = Transfer { from: AccountKeyring::Alice.into(), @@ -317,7 +317,7 @@ mod tests { let pool = BasicPool::new_full(Default::default(), true.into(), None, spawner, client.clone()); - let accounts = SystemRpc::new(client, pool, DenyUnsafe::No); + let accounts = System::new(client, pool, DenyUnsafe::No); let tx = Transfer { from: AccountKeyring::Alice.into(), From dcdd362a6a13d18acab01f49eff630a26bcbedef Mon Sep 17 00:00:00 2001 From: koushiro Date: Fri, 20 May 2022 16:58:26 +0800 Subject: [PATCH 4/5] Update doc Signed-off-by: koushiro --- client/beefy/rpc/src/lib.rs | 4 ++-- client/consensus/babe/rpc/src/lib.rs | 2 +- client/finality-grandpa/rpc/src/lib.rs | 2 +- client/sync-state-rpc/src/lib.rs | 6 +++--- frame/transaction-payment/rpc/src/lib.rs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/client/beefy/rpc/src/lib.rs b/client/beefy/rpc/src/lib.rs index bad5bf96a1cf4..c248d33cb6c23 100644 --- a/client/beefy/rpc/src/lib.rs +++ b/client/beefy/rpc/src/lib.rs @@ -110,7 +110,7 @@ impl Beefy where Block: BlockT, { - /// Creates a new BeefyRpcHandler instance. + /// Creates a new Beefy Rpc handler instance. pub fn new( signed_commitment_stream: BeefySignedCommitmentStream, best_block_stream: BeefyBestBlockStream, @@ -198,7 +198,7 @@ mod tests { let expected_response = r#"{"jsonrpc":"2.0","error":{"code":1,"message":"BEEFY RPC endpoint not ready"},"id":1}"#.to_string(); let (result, _) = rpc.raw_json_request(&request).await.unwrap(); - assert_eq!(expected_response, result); + assert_eq!(expected_response, result,); } #[tokio::test] diff --git a/client/consensus/babe/rpc/src/lib.rs b/client/consensus/babe/rpc/src/lib.rs index 9a8a87b98df53..af19d410346e3 100644 --- a/client/consensus/babe/rpc/src/lib.rs +++ b/client/consensus/babe/rpc/src/lib.rs @@ -65,7 +65,7 @@ pub struct Babe { } impl Babe { - /// Creates a new instance of the BabeRpc handler. + /// Creates a new instance of the Babe Rpc handler. pub fn new( client: Arc, shared_epoch_changes: SharedEpochChanges, diff --git a/client/finality-grandpa/rpc/src/lib.rs b/client/finality-grandpa/rpc/src/lib.rs index 6283c85e7a4f3..bdb86c125e20a 100644 --- a/client/finality-grandpa/rpc/src/lib.rs +++ b/client/finality-grandpa/rpc/src/lib.rs @@ -76,7 +76,7 @@ pub struct Grandpa { impl Grandpa { - /// Prepare a new [`GrandpaRpc`] + /// Prepare a new [`Grandpa`] Rpc handler. pub fn new( executor: SubscriptionTaskExecutor, authority_set: AuthoritySet, diff --git a/client/sync-state-rpc/src/lib.rs b/client/sync-state-rpc/src/lib.rs index 2eb611c515257..9540d94c57918 100644 --- a/client/sync-state-rpc/src/lib.rs +++ b/client/sync-state-rpc/src/lib.rs @@ -37,12 +37,12 @@ //! ``` //! //! If the [`LightSyncStateExtension`] is not added as an extension to the chain spec, -//! the [`SyncStateRpc`] will fail at instantiation. +//! the [`SyncState`] will fail at instantiation. #![deny(unused_crate_dependencies)] use jsonrpsee::{ - core::{Error as RpcError, RpcResult}, + core::{Error as JsonRpseeError, RpcResult}, proc_macros::rpc, types::{error::CallError, ErrorObject}, }; @@ -79,7 +79,7 @@ pub enum Error { LightSyncStateExtensionNotFound, } -impl From> for RpcError { +impl From> for JsonRpseeError { fn from(error: Error) -> Self { let message = match error { Error::JsonRpc(s) => s, diff --git a/frame/transaction-payment/rpc/src/lib.rs b/frame/transaction-payment/rpc/src/lib.rs index 5851d8ffef2d0..75ec42321ef5e 100644 --- a/frame/transaction-payment/rpc/src/lib.rs +++ b/frame/transaction-payment/rpc/src/lib.rs @@ -58,7 +58,7 @@ pub struct TransactionPayment { } impl TransactionPayment { - /// Creates a new instance of the TransactionPaymentRpc helper. + /// Creates a new instance of the TransactionPayment Rpc helper. pub fn new(client: Arc) -> Self { Self { client, _marker: Default::default() } } From 7e2b22fbe54419c4c6bf54f6f0e984614e8d1f8d Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Fri, 20 May 2022 18:59:33 -0400 Subject: [PATCH 5/5] fix merge --- client/rpc/src/state/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/client/rpc/src/state/mod.rs b/client/rpc/src/state/mod.rs index f85147d5cf683..232be4edc8aab 100644 --- a/client/rpc/src/state/mod.rs +++ b/client/rpc/src/state/mod.rs @@ -202,7 +202,6 @@ pub struct State { deny_unsafe: DenyUnsafe, } -#[async_trait] impl StateApiServer for State where Block: BlockT + 'static,