From 667fc7159b49a1836c95f59bce8074c41329ea21 Mon Sep 17 00:00:00 2001 From: Qinxuan Chen Date: Tue, 10 May 2022 21:13:02 +0800 Subject: [PATCH] Unify rpc api naming (#652) * Unify rpc api naming Signed-off-by: koushiro * Add some docs Signed-off-by: koushiro * Make test more stable Signed-off-by: koushiro --- client/rpc-core/src/eth.rs | 3 --- client/rpc-core/src/eth_pubsub.rs | 2 -- client/rpc-core/src/lib.rs | 8 ++++---- client/rpc-core/src/net.rs | 2 -- client/rpc/src/eth/block.rs | 4 ++-- client/rpc/src/eth/client.rs | 4 ++-- client/rpc/src/eth/execute.rs | 4 ++-- client/rpc/src/eth/fee.rs | 4 ++-- client/rpc/src/eth/filter.rs | 10 +++++----- client/rpc/src/eth/mining.rs | 4 ++-- client/rpc/src/eth/mod.rs | 12 +++++++----- client/rpc/src/eth/state.rs | 4 ++-- client/rpc/src/eth/submit.rs | 4 ++-- client/rpc/src/eth/transaction.rs | 4 ++-- client/rpc/src/eth_pubsub.rs | 13 ++++++------- client/rpc/src/lib.rs | 12 +++++------- client/rpc/src/net.rs | 9 +++++---- client/rpc/src/web3.rs | 9 +++++---- template/node/src/rpc.rs | 15 +++++++-------- 19 files changed, 60 insertions(+), 67 deletions(-) diff --git a/client/rpc-core/src/eth.rs b/client/rpc-core/src/eth.rs index e18458aba9ecc..604782cd03f57 100644 --- a/client/rpc-core/src/eth.rs +++ b/client/rpc-core/src/eth.rs @@ -24,9 +24,6 @@ use jsonrpc_derive::rpc; use crate::types::*; -pub use rpc_impl_EthApi::gen_server::EthApi as EthApiServer; -pub use rpc_impl_EthFilterApi::gen_server::EthFilterApi as EthFilterApiServer; - /// Eth rpc interface. #[rpc(server)] pub trait EthApi { diff --git a/client/rpc-core/src/eth_pubsub.rs b/client/rpc-core/src/eth_pubsub.rs index 6032381a171bd..d059e95753f6e 100644 --- a/client/rpc-core/src/eth_pubsub.rs +++ b/client/rpc-core/src/eth_pubsub.rs @@ -24,8 +24,6 @@ use jsonrpc_pubsub::{typed, SubscriptionId}; use crate::types::pubsub; -pub use rpc_impl_EthPubSubApi::gen_server::EthPubSubApi as EthPubSubApiServer; - /// Eth PUB-SUB rpc interface. #[rpc(server)] pub trait EthPubSubApi { diff --git a/client/rpc-core/src/lib.rs b/client/rpc-core/src/lib.rs index ed2c5bc934cf7..1de8dfea39642 100644 --- a/client/rpc-core/src/lib.rs +++ b/client/rpc-core/src/lib.rs @@ -24,8 +24,8 @@ mod net; mod web3; pub use self::{ - eth::{EthApi, EthApiServer, EthFilterApi, EthFilterApiServer}, - eth_pubsub::{EthPubSubApi, EthPubSubApiServer}, - net::{NetApi, NetApiServer}, - web3::{Web3Api, Web3ApiServer}, + eth::{EthApi, EthFilterApi}, + eth_pubsub::EthPubSubApi, + net::NetApi, + web3::Web3Api, }; diff --git a/client/rpc-core/src/net.rs b/client/rpc-core/src/net.rs index 6a51650eabb0b..417f750dec13a 100644 --- a/client/rpc-core/src/net.rs +++ b/client/rpc-core/src/net.rs @@ -23,8 +23,6 @@ use jsonrpc_derive::rpc; use crate::types::PeerCount; -pub use rpc_impl_NetApi::gen_server::NetApi as NetApiServer; - /// Net rpc interface. #[rpc(server)] pub trait NetApi { diff --git a/client/rpc/src/eth/block.rs b/client/rpc/src/eth/block.rs index 1529e915452f1..a05bf36755ab5 100644 --- a/client/rpc/src/eth/block.rs +++ b/client/rpc/src/eth/block.rs @@ -31,11 +31,11 @@ use sp_runtime::traits::{BlakeTwo256, Block as BlockT}; use fc_rpc_core::types::*; use crate::{ - eth::{rich_block_build, EthApi}, + eth::{rich_block_build, Eth}, frontier_backend_client, internal_err, }; -impl EthApi +impl Eth where B: BlockT + Send + Sync + 'static, C: StorageProvider + HeaderBackend + Send + Sync + 'static, diff --git a/client/rpc/src/eth/client.rs b/client/rpc/src/eth/client.rs index ccacb298370e8..d72953ced586b 100644 --- a/client/rpc/src/eth/client.rs +++ b/client/rpc/src/eth/client.rs @@ -32,9 +32,9 @@ use sp_runtime::{ use fc_rpc_core::types::*; use fp_rpc::EthereumRuntimeRPCApi; -use crate::{eth::EthApi, frontier_backend_client, internal_err}; +use crate::{eth::Eth, frontier_backend_client, internal_err}; -impl EthApi +impl Eth where B: BlockT + Send + Sync + 'static, C: ProvideRuntimeApi + StorageProvider, diff --git a/client/rpc/src/eth/execute.rs b/client/rpc/src/eth/execute.rs index e7776b4b94d7a..ce21801711e17 100644 --- a/client/rpc/src/eth/execute.rs +++ b/client/rpc/src/eth/execute.rs @@ -37,11 +37,11 @@ use fc_rpc_core::types::*; use fp_rpc::EthereumRuntimeRPCApi; use crate::{ - eth::{pending_runtime_api, EthApi}, + eth::{pending_runtime_api, Eth}, frontier_backend_client, internal_err, }; -impl EthApi +impl Eth where B: BlockT + Send + Sync + 'static, C: ProvideRuntimeApi + StorageProvider, diff --git a/client/rpc/src/eth/fee.rs b/client/rpc/src/eth/fee.rs index fab7bd525e2a1..c898f767a2238 100644 --- a/client/rpc/src/eth/fee.rs +++ b/client/rpc/src/eth/fee.rs @@ -32,9 +32,9 @@ use sp_runtime::{ use fc_rpc_core::types::*; use fp_rpc::EthereumRuntimeRPCApi; -use crate::{eth::EthApi, frontier_backend_client, internal_err}; +use crate::{eth::Eth, frontier_backend_client, internal_err}; -impl EthApi +impl Eth where B: BlockT + Send + Sync + 'static, C: ProvideRuntimeApi + StorageProvider, diff --git a/client/rpc/src/eth/filter.rs b/client/rpc/src/eth/filter.rs index 1f2428cceb3dc..afe1cf98de29f 100644 --- a/client/rpc/src/eth/filter.rs +++ b/client/rpc/src/eth/filter.rs @@ -34,13 +34,13 @@ use sp_runtime::{ }, }; -use fc_rpc_core::{types::*, EthFilterApi as EthFilterApiT}; +use fc_rpc_core::{types::*, EthFilterApi}; use fp_rpc::{EthereumRuntimeRPCApi, TransactionStatus}; use fp_storage::EthereumStorageSchema; use crate::{frontier_backend_client, internal_err, EthBlockDataCache}; -pub struct EthFilterApi { +pub struct EthFilter { client: Arc, backend: Arc>, filter_pool: FilterPool, @@ -50,7 +50,7 @@ pub struct EthFilterApi { _marker: PhantomData, } -impl EthFilterApi { +impl EthFilter { pub fn new( client: Arc, backend: Arc>, @@ -71,7 +71,7 @@ impl EthFilterApi { } } -impl EthFilterApi +impl EthFilter where B: BlockT + Send + Sync + 'static, C: HeaderBackend + Send + Sync + 'static, @@ -109,7 +109,7 @@ where } } -impl EthFilterApiT for EthFilterApi +impl EthFilterApi for EthFilter where B: BlockT + Send + Sync + 'static, C: ProvideRuntimeApi + StorageProvider, diff --git a/client/rpc/src/eth/mining.rs b/client/rpc/src/eth/mining.rs index ab0fd2d21afec..e5db9ef8b492c 100644 --- a/client/rpc/src/eth/mining.rs +++ b/client/rpc/src/eth/mining.rs @@ -25,9 +25,9 @@ use sp_runtime::traits::Block as BlockT; use fc_rpc_core::types::*; -use crate::eth::EthApi; +use crate::eth::Eth; -impl EthApi { +impl Eth { pub fn is_mining(&self) -> Result { Ok(self.is_authority) } diff --git a/client/rpc/src/eth/mod.rs b/client/rpc/src/eth/mod.rs index d73be9a032985..378173e4a5475 100644 --- a/client/rpc/src/eth/mod.rs +++ b/client/rpc/src/eth/mod.rs @@ -47,17 +47,18 @@ use sp_runtime::{ traits::{BlakeTwo256, Block as BlockT, UniqueSaturatedInto}, }; -use fc_rpc_core::{types::*, EthApi as EthApiT}; +use fc_rpc_core::{types::*, EthApi}; use fp_rpc::{ConvertTransactionRuntimeApi, EthereumRuntimeRPCApi, TransactionStatus}; use crate::{internal_err, overrides::OverrideHandle, public_key, signer::EthSigner}; pub use self::{ cache::{EthBlockDataCache, EthTask}, - filter::EthFilterApi, + filter::EthFilter, }; -pub struct EthApi { +/// Eth API implementation. +pub struct Eth { pool: Arc

, graph: Arc>, client: Arc, @@ -73,7 +74,7 @@ pub struct EthApi { _marker: PhantomData<(B, BE)>, } -impl EthApi { +impl Eth { pub fn new( client: Arc, pool: Arc

, @@ -106,7 +107,7 @@ impl EthApi EthApiT for EthApi +impl EthApi for Eth where B: BlockT + Send + Sync + 'static, C: ProvideRuntimeApi + StorageProvider, @@ -121,6 +122,7 @@ where // ######################################################################## // Client // ######################################################################## + fn protocol_version(&self) -> Result { self.protocol_version() } diff --git a/client/rpc/src/eth/state.rs b/client/rpc/src/eth/state.rs index c16739f9b8b3e..69e1fc3a9eb5a 100644 --- a/client/rpc/src/eth/state.rs +++ b/client/rpc/src/eth/state.rs @@ -36,11 +36,11 @@ use fc_rpc_core::types::*; use fp_rpc::EthereumRuntimeRPCApi; use crate::{ - eth::{pending_runtime_api, EthApi}, + eth::{pending_runtime_api, Eth}, frontier_backend_client, internal_err, }; -impl EthApi +impl Eth where B: BlockT + Send + Sync + 'static, C: ProvideRuntimeApi + StorageProvider, diff --git a/client/rpc/src/eth/submit.rs b/client/rpc/src/eth/submit.rs index 8cd22526e2c70..4c0b7c0ab8817 100644 --- a/client/rpc/src/eth/submit.rs +++ b/client/rpc/src/eth/submit.rs @@ -36,9 +36,9 @@ use sp_runtime::{ use fc_rpc_core::types::*; use fp_rpc::{ConvertTransaction, ConvertTransactionRuntimeApi, EthereumRuntimeRPCApi}; -use crate::{eth::EthApi, internal_err}; +use crate::{eth::Eth, internal_err}; -impl EthApi +impl Eth where B: BlockT + Send + Sync + 'static, C: ProvideRuntimeApi + StorageProvider, diff --git a/client/rpc/src/eth/transaction.rs b/client/rpc/src/eth/transaction.rs index 4a0577e865aaa..7de26317562d3 100644 --- a/client/rpc/src/eth/transaction.rs +++ b/client/rpc/src/eth/transaction.rs @@ -38,11 +38,11 @@ use fc_rpc_core::types::*; use fp_rpc::EthereumRuntimeRPCApi; use crate::{ - eth::{transaction_build, EthApi}, + eth::{transaction_build, Eth}, frontier_backend_client, internal_err, }; -impl EthApi +impl Eth where B: BlockT + Send + Sync + 'static, C: ProvideRuntimeApi + StorageProvider + HeaderBackend + Send + Sync + 'static, diff --git a/client/rpc/src/eth_pubsub.rs b/client/rpc/src/eth_pubsub.rs index 4227c12e756a5..c29a14266ad32 100644 --- a/client/rpc/src/eth_pubsub.rs +++ b/client/rpc/src/eth_pubsub.rs @@ -37,7 +37,7 @@ use sc_client_api::{ use sc_network::{ExHashT, NetworkService}; use sc_rpc::Metadata; use sc_transaction_pool_api::TransactionPool; -use sp_api::{BlockId, ProvideRuntimeApi}; +use sp_api::{ApiExt, BlockId, ProvideRuntimeApi}; use sp_blockchain::HeaderBackend; use sp_core::hashing::keccak_256; use sp_runtime::traits::{BlakeTwo256, Block as BlockT, UniqueSaturatedInto}; @@ -47,12 +47,10 @@ use fc_rpc_core::{ pubsub::{Kind, Params, PubSubSyncStatus, Result as PubSubResult, SyncStatusMetadata}, Bytes, FilteredParams, Header, Log, Rich, }, - EthPubSubApi as EthPubSubApiT, + EthPubSubApi, }; use fp_rpc::EthereumRuntimeRPCApi; -use sp_api::ApiExt; - use crate::{frontier_backend_client, overrides::OverrideHandle}; #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] @@ -80,7 +78,8 @@ impl IdProvider for HexEncodedIdProvider { } } -pub struct EthPubSubApi { +/// Eth pub-sub API implementation. +pub struct EthPubSub { pool: Arc

, client: Arc, network: Arc>, @@ -90,7 +89,7 @@ pub struct EthPubSubApi { _marker: PhantomData, } -impl EthPubSubApi +impl EthPubSub where C: HeaderBackend + Send + Sync + 'static, { @@ -224,7 +223,7 @@ impl SubscriptionResult { } } -impl EthPubSubApiT for EthPubSubApi +impl EthPubSubApi for EthPubSub where B: BlockT + Send + Sync + 'static, P: TransactionPool + Send + Sync + 'static, diff --git a/client/rpc/src/lib.rs b/client/rpc/src/lib.rs index c9027150edf68..5e29e62953fe1 100644 --- a/client/rpc/src/lib.rs +++ b/client/rpc/src/lib.rs @@ -24,21 +24,19 @@ mod signer; mod web3; pub use self::{ - eth::{EthApi, EthBlockDataCache, EthFilterApi, EthTask}, - eth_pubsub::{EthPubSubApi, HexEncodedIdProvider}, - net::NetApi, + eth::{Eth, EthBlockDataCache, EthFilter, EthTask}, + eth_pubsub::{EthPubSub, HexEncodedIdProvider}, + net::Net, overrides::{ OverrideHandle, RuntimeApiStorageOverride, SchemaV1Override, SchemaV2Override, SchemaV3Override, StorageOverride, }, signer::{EthDevSigner, EthSigner}, - web3::Web3Api, + web3::Web3, }; pub use ethereum::TransactionV2 as EthereumTransaction; -pub use fc_rpc_core::{ - EthApiServer, EthFilterApiServer, EthPubSubApiServer, NetApiServer, Web3ApiServer, -}; +pub use fc_rpc_core::{EthApi, EthFilterApi, EthPubSubApi, NetApi, Web3Api}; pub mod frontier_backend_client { use super::internal_err; diff --git a/client/rpc/src/net.rs b/client/rpc/src/net.rs index 5cd85fcf3aab3..437d7606b94e6 100644 --- a/client/rpc/src/net.rs +++ b/client/rpc/src/net.rs @@ -25,18 +25,19 @@ use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_runtime::{generic::BlockId, traits::Block as BlockT}; -use fc_rpc_core::{types::PeerCount, NetApi as NetApiT}; +use fc_rpc_core::{types::PeerCount, NetApi}; use fp_rpc::EthereumRuntimeRPCApi; use crate::internal_err; -pub struct NetApi { +/// Net API implementation. +pub struct Net { client: Arc, network: Arc>, peer_count_as_hex: bool, } -impl NetApi { +impl Net { pub fn new( client: Arc, network: Arc>, @@ -50,7 +51,7 @@ impl NetApi { } } -impl NetApiT for NetApi +impl NetApi for Net where B: BlockT + Send + Sync + 'static, C: HeaderBackend + ProvideRuntimeApi + Send + Sync + 'static, diff --git a/client/rpc/src/web3.rs b/client/rpc/src/web3.rs index ef3fe6b86db7e..53f107f138d0f 100644 --- a/client/rpc/src/web3.rs +++ b/client/rpc/src/web3.rs @@ -25,17 +25,18 @@ use sp_blockchain::HeaderBackend; use sp_core::keccak_256; use sp_runtime::{generic::BlockId, traits::Block as BlockT}; -use fc_rpc_core::{types::Bytes, Web3Api as Web3ApiT}; +use fc_rpc_core::{types::Bytes, Web3Api}; use fp_rpc::EthereumRuntimeRPCApi; use crate::internal_err; -pub struct Web3Api { +/// Web3 API implementation. +pub struct Web3 { client: Arc, _marker: PhantomData, } -impl Web3Api { +impl Web3 { pub fn new(client: Arc) -> Self { Self { client, @@ -44,7 +45,7 @@ impl Web3Api { } } -impl Web3ApiT for Web3Api +impl Web3Api for Web3 where B: BlockT + Send + Sync + 'static, C: HeaderBackend + ProvideRuntimeApi + Send + Sync + 'static, diff --git a/template/node/src/rpc.rs b/template/node/src/rpc.rs index 40df36e694e07..0288d3fdb382d 100644 --- a/template/node/src/rpc.rs +++ b/template/node/src/rpc.rs @@ -120,9 +120,8 @@ where A: ChainApi + 'static, { use fc_rpc::{ - EthApi, EthApiServer, EthDevSigner, EthFilterApi, EthFilterApiServer, EthPubSubApi, - EthPubSubApiServer, EthSigner, HexEncodedIdProvider, NetApi, NetApiServer, Web3Api, - Web3ApiServer, + Eth, EthApi, EthDevSigner, EthFilter, EthFilterApi, EthPubSub, EthPubSubApi, EthSigner, + HexEncodedIdProvider, Net, NetApi, Web3, Web3Api, }; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi}; use substrate_frame_rpc_system::{FullSystem, SystemApi}; @@ -161,7 +160,7 @@ where signers.push(Box::new(EthDevSigner::new()) as Box); } - io.extend_with(EthApiServer::to_delegate(EthApi::new( + io.extend_with(EthApi::to_delegate(Eth::new( client.clone(), pool.clone(), graph, @@ -177,7 +176,7 @@ where ))); if let Some(filter_pool) = filter_pool { - io.extend_with(EthFilterApiServer::to_delegate(EthFilterApi::new( + io.extend_with(EthFilterApi::to_delegate(EthFilter::new( client.clone(), backend, filter_pool.clone(), @@ -187,16 +186,16 @@ where ))); } - io.extend_with(NetApiServer::to_delegate(NetApi::new( + io.extend_with(NetApi::to_delegate(Net::new( client.clone(), network.clone(), // Whether to format the `peer_count` response as Hex (default) or not. true, ))); - io.extend_with(Web3ApiServer::to_delegate(Web3Api::new(client.clone()))); + io.extend_with(Web3Api::to_delegate(Web3::new(client.clone()))); - io.extend_with(EthPubSubApiServer::to_delegate(EthPubSubApi::new( + io.extend_with(EthPubSubApi::to_delegate(EthPubSub::new( pool.clone(), client.clone(), network.clone(),