Skip to content

Commit

Permalink
Unify rpc api naming (paritytech#652)
Browse files Browse the repository at this point in the history
* Unify rpc api naming

Signed-off-by: koushiro <[email protected]>

* Add some docs

Signed-off-by: koushiro <[email protected]>

* Make test more stable

Signed-off-by: koushiro <[email protected]>
  • Loading branch information
koushiro authored May 10, 2022
1 parent 4238c5c commit 667fc71
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 67 deletions.
3 changes: 0 additions & 3 deletions client/rpc-core/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions client/rpc-core/src/eth_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions client/rpc-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
2 changes: 0 additions & 2 deletions client/rpc-core/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions client/rpc/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B, C, P, CT, BE, H: ExHashT, A: ChainApi> EthApi<B, C, P, CT, BE, H, A>
impl<B, C, P, CT, BE, H: ExHashT, A: ChainApi> Eth<B, C, P, CT, BE, H, A>
where
B: BlockT<Hash = H256> + Send + Sync + 'static,
C: StorageProvider<B, BE> + HeaderBackend<B> + Send + Sync + 'static,
Expand Down
4 changes: 2 additions & 2 deletions client/rpc/src/eth/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B, C, P, CT, BE, H: ExHashT, A: ChainApi> EthApi<B, C, P, CT, BE, H, A>
impl<B, C, P, CT, BE, H: ExHashT, A: ChainApi> Eth<B, C, P, CT, BE, H, A>
where
B: BlockT<Hash = H256> + Send + Sync + 'static,
C: ProvideRuntimeApi<B> + StorageProvider<B, BE>,
Expand Down
4 changes: 2 additions & 2 deletions client/rpc/src/eth/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B, C, P, CT, BE, H: ExHashT, A: ChainApi> EthApi<B, C, P, CT, BE, H, A>
impl<B, C, P, CT, BE, H: ExHashT, A: ChainApi> Eth<B, C, P, CT, BE, H, A>
where
B: BlockT<Hash = H256> + Send + Sync + 'static,
C: ProvideRuntimeApi<B> + StorageProvider<B, BE>,
Expand Down
4 changes: 2 additions & 2 deletions client/rpc/src/eth/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B, C, P, CT, BE, H: ExHashT, A: ChainApi> EthApi<B, C, P, CT, BE, H, A>
impl<B, C, P, CT, BE, H: ExHashT, A: ChainApi> Eth<B, C, P, CT, BE, H, A>
where
B: BlockT<Hash = H256> + Send + Sync + 'static,
C: ProvideRuntimeApi<B> + StorageProvider<B, BE>,
Expand Down
10 changes: 5 additions & 5 deletions client/rpc/src/eth/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B: BlockT, C, BE> {
pub struct EthFilter<B: BlockT, C, BE> {
client: Arc<C>,
backend: Arc<fc_db::Backend<B>>,
filter_pool: FilterPool,
Expand All @@ -50,7 +50,7 @@ pub struct EthFilterApi<B: BlockT, C, BE> {
_marker: PhantomData<BE>,
}

impl<B: BlockT, C, BE> EthFilterApi<B, C, BE> {
impl<B: BlockT, C, BE> EthFilter<B, C, BE> {
pub fn new(
client: Arc<C>,
backend: Arc<fc_db::Backend<B>>,
Expand All @@ -71,7 +71,7 @@ impl<B: BlockT, C, BE> EthFilterApi<B, C, BE> {
}
}

impl<B, C, BE> EthFilterApi<B, C, BE>
impl<B, C, BE> EthFilter<B, C, BE>
where
B: BlockT<Hash = H256> + Send + Sync + 'static,
C: HeaderBackend<B> + Send + Sync + 'static,
Expand Down Expand Up @@ -109,7 +109,7 @@ where
}
}

impl<B, C, BE> EthFilterApiT for EthFilterApi<B, C, BE>
impl<B, C, BE> EthFilterApi for EthFilter<B, C, BE>
where
B: BlockT<Hash = H256> + Send + Sync + 'static,
C: ProvideRuntimeApi<B> + StorageProvider<B, BE>,
Expand Down
4 changes: 2 additions & 2 deletions client/rpc/src/eth/mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B: BlockT, C, P, CT, BE, H: ExHashT, A: ChainApi> EthApi<B, C, P, CT, BE, H, A> {
impl<B: BlockT, C, P, CT, BE, H: ExHashT, A: ChainApi> Eth<B, C, P, CT, BE, H, A> {
pub fn is_mining(&self) -> Result<bool> {
Ok(self.is_authority)
}
Expand Down
12 changes: 7 additions & 5 deletions client/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B: BlockT, C, P, CT, BE, H: ExHashT, A: ChainApi> {
/// Eth API implementation.
pub struct Eth<B: BlockT, C, P, CT, BE, H: ExHashT, A: ChainApi> {
pool: Arc<P>,
graph: Arc<Pool<A>>,
client: Arc<C>,
Expand All @@ -73,7 +74,7 @@ pub struct EthApi<B: BlockT, C, P, CT, BE, H: ExHashT, A: ChainApi> {
_marker: PhantomData<(B, BE)>,
}

impl<B: BlockT, C, P, CT, BE, H: ExHashT, A: ChainApi> EthApi<B, C, P, CT, BE, H, A> {
impl<B: BlockT, C, P, CT, BE, H: ExHashT, A: ChainApi> Eth<B, C, P, CT, BE, H, A> {
pub fn new(
client: Arc<C>,
pool: Arc<P>,
Expand Down Expand Up @@ -106,7 +107,7 @@ impl<B: BlockT, C, P, CT, BE, H: ExHashT, A: ChainApi> EthApi<B, C, P, CT, BE, H
}
}

impl<B, C, P, CT, BE, H: ExHashT, A> EthApiT for EthApi<B, C, P, CT, BE, H, A>
impl<B, C, P, CT, BE, H: ExHashT, A> EthApi for Eth<B, C, P, CT, BE, H, A>
where
B: BlockT<Hash = H256> + Send + Sync + 'static,
C: ProvideRuntimeApi<B> + StorageProvider<B, BE>,
Expand All @@ -121,6 +122,7 @@ where
// ########################################################################
// Client
// ########################################################################

fn protocol_version(&self) -> Result<u64> {
self.protocol_version()
}
Expand Down
4 changes: 2 additions & 2 deletions client/rpc/src/eth/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B, C, P, CT, BE, H: ExHashT, A: ChainApi> EthApi<B, C, P, CT, BE, H, A>
impl<B, C, P, CT, BE, H: ExHashT, A: ChainApi> Eth<B, C, P, CT, BE, H, A>
where
B: BlockT<Hash = H256> + Send + Sync + 'static,
C: ProvideRuntimeApi<B> + StorageProvider<B, BE>,
Expand Down
4 changes: 2 additions & 2 deletions client/rpc/src/eth/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B, C, P, CT, BE, H: ExHashT, A: ChainApi> EthApi<B, C, P, CT, BE, H, A>
impl<B, C, P, CT, BE, H: ExHashT, A: ChainApi> Eth<B, C, P, CT, BE, H, A>
where
B: BlockT<Hash = H256> + Send + Sync + 'static,
C: ProvideRuntimeApi<B> + StorageProvider<B, BE>,
Expand Down
4 changes: 2 additions & 2 deletions client/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B, C, P, CT, BE, H: ExHashT, A: ChainApi> EthApi<B, C, P, CT, BE, H, A>
impl<B, C, P, CT, BE, H: ExHashT, A: ChainApi> Eth<B, C, P, CT, BE, H, A>
where
B: BlockT<Hash = H256> + Send + Sync + 'static,
C: ProvideRuntimeApi<B> + StorageProvider<B, BE> + HeaderBackend<B> + Send + Sync + 'static,
Expand Down
13 changes: 6 additions & 7 deletions client/rpc/src/eth_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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)]
Expand Down Expand Up @@ -80,7 +78,8 @@ impl IdProvider for HexEncodedIdProvider {
}
}

pub struct EthPubSubApi<B: BlockT, P, C, BE, H: ExHashT> {
/// Eth pub-sub API implementation.
pub struct EthPubSub<B: BlockT, P, C, BE, H: ExHashT> {
pool: Arc<P>,
client: Arc<C>,
network: Arc<NetworkService<B, H>>,
Expand All @@ -90,7 +89,7 @@ pub struct EthPubSubApi<B: BlockT, P, C, BE, H: ExHashT> {
_marker: PhantomData<BE>,
}

impl<B: BlockT, P, C, BE, H: ExHashT> EthPubSubApi<B, P, C, BE, H>
impl<B: BlockT, P, C, BE, H: ExHashT> EthPubSub<B, P, C, BE, H>
where
C: HeaderBackend<B> + Send + Sync + 'static,
{
Expand Down Expand Up @@ -224,7 +223,7 @@ impl SubscriptionResult {
}
}

impl<B: BlockT, P, C, BE, H: ExHashT> EthPubSubApiT for EthPubSubApi<B, P, C, BE, H>
impl<B: BlockT, P, C, BE, H: ExHashT> EthPubSubApi for EthPubSub<B, P, C, BE, H>
where
B: BlockT<Hash = H256> + Send + Sync + 'static,
P: TransactionPool<Block = B> + Send + Sync + 'static,
Expand Down
12 changes: 5 additions & 7 deletions client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions client/rpc/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B: BlockT, C, H: ExHashT> {
/// Net API implementation.
pub struct Net<B: BlockT, C, H: ExHashT> {
client: Arc<C>,
network: Arc<NetworkService<B, H>>,
peer_count_as_hex: bool,
}

impl<B: BlockT, C, H: ExHashT> NetApi<B, C, H> {
impl<B: BlockT, C, H: ExHashT> Net<B, C, H> {
pub fn new(
client: Arc<C>,
network: Arc<NetworkService<B, H>>,
Expand All @@ -50,7 +51,7 @@ impl<B: BlockT, C, H: ExHashT> NetApi<B, C, H> {
}
}

impl<B, C, H: ExHashT> NetApiT for NetApi<B, C, H>
impl<B, C, H: ExHashT> NetApi for Net<B, C, H>
where
B: BlockT<Hash = H256> + Send + Sync + 'static,
C: HeaderBackend<B> + ProvideRuntimeApi<B> + Send + Sync + 'static,
Expand Down
9 changes: 5 additions & 4 deletions client/rpc/src/web3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B, C> {
/// Web3 API implementation.
pub struct Web3<B, C> {
client: Arc<C>,
_marker: PhantomData<B>,
}

impl<B, C> Web3Api<B, C> {
impl<B, C> Web3<B, C> {
pub fn new(client: Arc<C>) -> Self {
Self {
client,
Expand All @@ -44,7 +45,7 @@ impl<B, C> Web3Api<B, C> {
}
}

impl<B, C> Web3ApiT for Web3Api<B, C>
impl<B, C> Web3Api for Web3<B, C>
where
B: BlockT<Hash = H256> + Send + Sync + 'static,
C: HeaderBackend<B> + ProvideRuntimeApi<B> + Send + Sync + 'static,
Expand Down
Loading

0 comments on commit 667fc71

Please sign in to comment.