Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Remove extra Rpc naming in the structs
Browse files Browse the repository at this point in the history
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
  • Loading branch information
koushiro committed May 20, 2022
1 parent 7c32da8 commit ad1b7cb
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 64 deletions.
8 changes: 4 additions & 4 deletions bin/node-template/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ where
C::Api: BlockBuilder<Block>,
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
Expand Down
32 changes: 16 additions & 16 deletions bin/node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ where
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
{
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;
Expand All @@ -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,
Expand All @@ -159,7 +159,7 @@ where
.into_rpc(),
)?;
io.merge(
GrandpaRpc::new(
Grandpa::new(
subscription_executor,
shared_authority_set.clone(),
shared_voter_state,
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions client/beefy/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ pub trait BeefyApi<Notification, Hash> {
}

/// Implements the BeefyApi RPC trait for interacting with BEEFY.
pub struct BeefyRpc<Block: BlockT> {
pub struct Beefy<Block: BlockT> {
signed_commitment_stream: BeefySignedCommitmentStream<Block>,
beefy_best_block: Arc<RwLock<Option<Block::Hash>>>,
executor: SubscriptionTaskExecutor,
}

impl<Block> BeefyRpc<Block>
impl<Block> Beefy<Block>
where
Block: BlockT,
{
Expand All @@ -131,7 +131,7 @@ where
}

#[async_trait]
impl<Block> BeefyApiServer<notification::EncodedSignedCommitment, Block::Hash> for BeefyRpc<Block>
impl<Block> BeefyApiServer<notification::EncodedSignedCommitment, Block::Hash> for Beefy<Block>
where
Block: BlockT,
{
Expand Down Expand Up @@ -173,19 +173,19 @@ mod tests {
use sp_runtime::traits::{BlakeTwo256, Hash};
use substrate_test_runtime_client::runtime::Block;

fn setup_io_handler() -> (RpcModule<BeefyRpc<Block>>, BeefySignedCommitmentSender<Block>) {
fn setup_io_handler() -> (RpcModule<Beefy<Block>>, BeefySignedCommitmentSender<Block>) {
let (_, stream) = BeefyBestBlockStream::<Block>::channel();
setup_io_handler_with_best_block_stream(stream)
}

fn setup_io_handler_with_best_block_stream(
best_block_stream: BeefyBestBlockStream<Block>,
) -> (RpcModule<BeefyRpc<Block>>, BeefySignedCommitmentSender<Block>) {
) -> (RpcModule<Beefy<Block>>, BeefySignedCommitmentSender<Block>) {
let (commitment_sender, commitment_stream) =
BeefySignedCommitmentStream::<Block>::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)
Expand Down
10 changes: 5 additions & 5 deletions client/consensus/babe/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub trait BabeApi {
}

/// Provides RPC methods for interacting with Babe.
pub struct BabeRpc<B: BlockT, C, SC> {
pub struct Babe<B: BlockT, C, SC> {
/// shared reference to the client.
client: Arc<C>,
/// shared reference to EpochChanges
Expand All @@ -64,7 +64,7 @@ pub struct BabeRpc<B: BlockT, C, SC> {
deny_unsafe: DenyUnsafe,
}

impl<B: BlockT, C, SC> BabeRpc<B, C, SC> {
impl<B: BlockT, C, SC> Babe<B, C, SC> {
/// Creates a new instance of the BabeRpc handler.
pub fn new(
client: Arc<C>,
Expand All @@ -79,7 +79,7 @@ impl<B: BlockT, C, SC> BabeRpc<B, C, SC> {
}

#[async_trait]
impl<B: BlockT, C, SC> BabeApiServer for BabeRpc<B, C, SC>
impl<B: BlockT, C, SC> BabeApiServer for Babe<B, C, SC>
where
B: BlockT,
C: ProvideRuntimeApi<B>
Expand Down Expand Up @@ -239,7 +239,7 @@ mod tests {

fn test_babe_rpc_module(
deny_unsafe: DenyUnsafe,
) -> BabeRpc<Block, TestClient, sc_consensus::LongestChain<Backend, Block>> {
) -> Babe<Block, TestClient, sc_consensus::LongestChain<Backend, Block>> {
let builder = TestClientBuilder::new();
let (client, longest_chain) = builder.build_with_longest_chain();
let client = Arc::new(client);
Expand All @@ -250,7 +250,7 @@ mod tests {
let epoch_changes = link.epoch_changes().clone();
let keystore = create_temp_keystore::<AuthorityPair>(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]
Expand Down
6 changes: 3 additions & 3 deletions client/consensus/manual-seal/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub trait ManualSealApi<Hash> {
}

/// A struct that implements the [`ManualSealApiServer`].
pub struct ManualSealRpc<Hash> {
pub struct ManualSeal<Hash> {
import_block_channel: mpsc::Sender<EngineCommand<Hash>>,
}

Expand All @@ -99,15 +99,15 @@ pub struct CreatedBlock<Hash> {
pub aux: ImportedAux,
}

impl<Hash> ManualSealRpc<Hash> {
impl<Hash> ManualSeal<Hash> {
/// Create new `ManualSeal` with the given reference to the client.
pub fn new(import_block_channel: mpsc::Sender<EngineCommand<Hash>>) -> Self {
Self { import_block_channel }
}
}

#[async_trait]
impl<Hash: Send + 'static> ManualSealApiServer<Hash> for ManualSealRpc<Hash> {
impl<Hash: Send + 'static> ManualSealApiServer<Hash> for ManualSeal<Hash> {
async fn create_block(
&self,
create_empty: bool,
Expand Down
12 changes: 6 additions & 6 deletions client/finality-grandpa/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ pub trait GrandpaApi<Notification, Hash, Number> {
}

/// Provides RPC methods for interacting with GRANDPA.
pub struct GrandpaRpc<AuthoritySet, VoterState, Block: BlockT, ProofProvider> {
pub struct Grandpa<AuthoritySet, VoterState, Block: BlockT, ProofProvider> {
executor: SubscriptionTaskExecutor,
authority_set: AuthoritySet,
voter_state: VoterState,
justification_stream: GrandpaJustificationStream<Block>,
finality_proof_provider: Arc<ProofProvider>,
}
impl<AuthoritySet, VoterState, Block: BlockT, ProofProvider>
GrandpaRpc<AuthoritySet, VoterState, Block, ProofProvider>
Grandpa<AuthoritySet, VoterState, Block, ProofProvider>
{
/// Prepare a new [`GrandpaRpc`]
pub fn new(
Expand All @@ -91,7 +91,7 @@ impl<AuthoritySet, VoterState, Block: BlockT, ProofProvider>
#[async_trait]
impl<AuthoritySet, VoterState, Block, ProofProvider>
GrandpaApiServer<JustificationNotification, Block::Hash, NumberFor<Block>>
for GrandpaRpc<AuthoritySet, VoterState, Block, ProofProvider>
for Grandpa<AuthoritySet, VoterState, Block, ProofProvider>
where
VoterState: ReportVoterState + Send + Sync + 'static,
AuthoritySet: ReportAuthoritySet + Send + Sync + 'static,
Expand Down Expand Up @@ -243,7 +243,7 @@ mod tests {
fn setup_io_handler<VoterState>(
voter_state: VoterState,
) -> (
RpcModule<GrandpaRpc<TestAuthoritySet, VoterState, Block, TestFinalityProofProvider>>,
RpcModule<Grandpa<TestAuthoritySet, VoterState, Block, TestFinalityProofProvider>>,
GrandpaJustificationSender<Block>,
)
where
Expand All @@ -256,7 +256,7 @@ mod tests {
voter_state: VoterState,
finality_proof: Option<FinalityProof<Header>>,
) -> (
RpcModule<GrandpaRpc<TestAuthoritySet, VoterState, Block, TestFinalityProofProvider>>,
RpcModule<Grandpa<TestAuthoritySet, VoterState, Block, TestFinalityProofProvider>>,
GrandpaJustificationSender<Block>,
)
where
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions client/sync-state-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ pub trait SyncStateApi {
}

/// An api for sync state RPC calls.
pub struct SyncStateRpc<Block: BlockT, Client> {
pub struct SyncState<Block: BlockT, Client> {
chain_spec: Box<dyn sc_chain_spec::ChainSpec>,
client: Arc<Client>,
shared_authority_set: SharedAuthoritySet<Block>,
shared_epoch_changes: SharedEpochChanges<Block>,
}

impl<Block, Client> SyncStateRpc<Block, Client>
impl<Block, Client> SyncState<Block, Client>
where
Block: BlockT,
Client: HeaderBackend<Block> + sc_client_api::AuxStore + 'static,
Expand Down Expand Up @@ -180,7 +180,7 @@ where
}
}

impl<Block, Backend> SyncStateApiServer for SyncStateRpc<Block, Backend>
impl<Block, Backend> SyncStateApiServer for SyncState<Block, Backend>
where
Block: BlockT,
Backend: HeaderBackend<Block> + sc_client_api::AuxStore + 'static,
Expand Down
6 changes: 3 additions & 3 deletions frame/contracts/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ where
}

/// Contracts RPC methods.
pub struct ContractsRpc<Client, Block> {
pub struct Contracts<Client, Block> {
client: Arc<Client>,
_marker: PhantomData<Block>,
}

impl<Client, Block> ContractsRpc<Client, Block> {
impl<Client, Block> Contracts<Client, Block> {
/// Create new `Contracts` with the given reference to the client.
pub fn new(client: Arc<Client>) -> Self {
Self { client, _marker: Default::default() }
Expand All @@ -193,7 +193,7 @@ impl<Client, Block, AccountId, Balance, Hash>
AccountId,
Balance,
Hash,
> for ContractsRpc<Client, Block>
> for Contracts<Client, Block>
where
Block: BlockT,
Client: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,
Expand Down
7 changes: 3 additions & 4 deletions frame/merkle-mountain-range/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,20 @@ pub trait MmrApi<BlockHash> {
}

/// MMR RPC methods.
pub struct MmrRpc<Client, Block> {
pub struct Mmr<Client, Block> {
client: Arc<Client>,
_marker: PhantomData<Block>,
}

impl<C, B> MmrRpc<C, B> {
impl<C, B> Mmr<C, B> {
/// Create new `Mmr` with the given reference to the client.
pub fn new(client: Arc<C>) -> Self {
Self { client, _marker: Default::default() }
}
}

#[async_trait]
impl<Client, Block, MmrHash> MmrApiServer<<Block as BlockT>::Hash>
for MmrRpc<Client, (Block, MmrHash)>
impl<Client, Block, MmrHash> MmrApiServer<<Block as BlockT>::Hash> for Mmr<Client, (Block, MmrHash)>
where
Block: BlockT,
Client: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,
Expand Down
6 changes: 3 additions & 3 deletions frame/transaction-payment/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ pub trait TransactionPaymentApi<BlockHash, ResponseType> {
}

/// Provides RPC methods to query a dispatchable's class, weight and fee.
pub struct TransactionPaymentRpc<C, P> {
pub struct TransactionPayment<C, P> {
/// Shared reference to the client.
client: Arc<C>,
_marker: std::marker::PhantomData<P>,
}

impl<C, P> TransactionPaymentRpc<C, P> {
impl<C, P> TransactionPayment<C, P> {
/// Creates a new instance of the TransactionPaymentRpc helper.
pub fn new(client: Arc<C>) -> Self {
Self { client, _marker: Default::default() }
Expand All @@ -84,7 +84,7 @@ impl From<Error> for i32 {
#[async_trait]
impl<C, Block, Balance>
TransactionPaymentApiServer<<Block as BlockT>::Hash, RuntimeDispatchInfo<Balance>>
for TransactionPaymentRpc<C, Block>
for TransactionPayment<C, Block>
where
Block: BlockT,
C: ProvideRuntimeApi<Block> + HeaderBackend<Block> + Send + Sync + 'static,
Expand Down
8 changes: 4 additions & 4 deletions utils/frame/rpc/state-trie-migration-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,21 @@ pub trait StateMigrationApi<BlockHash> {
}

/// An implementation of state migration specific RPC methods.
pub struct StateMigrationRpc<C, B, BA> {
pub struct StateMigration<C, B, BA> {
client: Arc<C>,
backend: Arc<BA>,
deny_unsafe: DenyUnsafe,
_marker: std::marker::PhantomData<(B, BA)>,
}

impl<C, B, BA> StateMigrationRpc<C, B, BA> {
impl<C, B, BA> StateMigration<C, B, BA> {
/// Create new state migration rpc for the given reference to the client.
pub fn new(client: Arc<C>, backend: Arc<BA>, deny_unsafe: DenyUnsafe) -> Self {
StateMigrationRpc { client, backend, deny_unsafe, _marker: Default::default() }
StateMigration { client, backend, deny_unsafe, _marker: Default::default() }
}
}

impl<C, B, BA> StateMigrationApiServer<<B as BlockT>::Hash> for StateMigrationRpc<C, B, BA>
impl<C, B, BA> StateMigrationApiServer<<B as BlockT>::Hash> for StateMigration<C, B, BA>
where
B: BlockT,
C: Send + Sync + 'static + sc_client_api::HeaderBackend<B>,
Expand Down
Loading

0 comments on commit ad1b7cb

Please sign in to comment.