Skip to content

Commit

Permalink
Add StorageProvider trait bound to Client (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgmichel committed Jun 4, 2020
1 parent 6131ebe commit d290857
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ sp-runtime = { path = "../vendor/substrate/primitives/runtime" }
sp-api = { path = "../vendor/substrate/primitives/api" }
sp-consensus = { path = "../vendor/substrate/primitives/consensus/common" }
sp-transaction-pool = { path = "../vendor/substrate/primitives/transaction-pool" }
sp-storage = { path = "../vendor/substrate/primitives/storage" }
sc-service = { path = "../vendor/substrate/client/service" }
sc-client-api = { path = "../vendor/substrate/client/api" }
ethereum = { version = "0.2", features = ["codec"] }
codec = { package = "parity-scale-codec", version = "1.0.0" }
rlp = "0.4"
Expand Down
16 changes: 10 additions & 6 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ use sp_runtime::transaction_validity::TransactionSource;
use sp_api::{ProvideRuntimeApi, BlockId};
use sp_consensus::SelectChain;
use sp_transaction_pool::TransactionPool;
use sc_client_api::backend::{StorageProvider, Backend, StateBackend};
use sha3::{Keccak256, Digest};
use sp_runtime::traits::BlakeTwo256;

use frontier_rpc_core::EthApi as EthApiT;
use frontier_rpc_core::types::{
Expand All @@ -42,15 +44,15 @@ fn internal_err(message: &str) -> Error {
}
}

pub struct EthApi<B: BlockT, C, SC, P, CT> {
pub struct EthApi<B: BlockT, C, SC, P, CT, BE> {
pool: Arc<P>,
client: Arc<C>,
select_chain: SC,
convert_transaction: CT,
_marker: PhantomData<B>,
_marker: PhantomData<(B,BE)>,
}

impl<B: BlockT, C, SC, P, CT> EthApi<B, C, SC, P, CT> {
impl<B: BlockT, C, SC, P, CT, BE> EthApi<B, C, SC, P, CT, BE> {
pub fn new(
client: Arc<C>,
select_chain: SC,
Expand All @@ -61,10 +63,12 @@ impl<B: BlockT, C, SC, P, CT> EthApi<B, C, SC, P, CT> {
}
}

impl<B, C, SC, P, CT> EthApiT for EthApi<B, C, SC, P, CT> where
C: ProvideRuntimeApi<B>,
impl<B, C, SC, P, CT, BE> EthApiT for EthApi<B, C, SC, P, CT, BE> where
C: ProvideRuntimeApi<B> + StorageProvider<B,BE>,
C::Api: EthereumRuntimeApi<B>,
B: BlockT + Send + Sync + 'static,
BE: Backend<B> + 'static,
BE::State: StateBackend<BlakeTwo256>,
B: BlockT<Hash=H256> + Send + Sync + 'static,
C: Send + Sync + 'static,
SC: SelectChain<B> + Clone + 'static,
P: TransactionPool<Block=B> + Send + Sync + 'static,
Expand Down
8 changes: 6 additions & 2 deletions template/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use sp_transaction_pool::TransactionPool;
use sp_blockchain::{Error as BlockChainError, HeaderMetadata, HeaderBackend};
use sp_consensus::SelectChain;
use sc_rpc_api::DenyUnsafe;
use sc_client_api::backend::{StorageProvider, Backend, StateBackend};
use sp_runtime::traits::BlakeTwo256;

/// Light client extra dependencies.
pub struct LightDeps<C, F, P> {
Expand All @@ -51,10 +53,12 @@ pub struct FullDeps<C, P, SC> {
}

/// Instantiate all Full RPC extensions.
pub fn create_full<C, P, M, SC>(
pub fn create_full<C, P, M, SC, BE>(
deps: FullDeps<C, P, SC>,
) -> jsonrpc_core::IoHandler<M> where
C: ProvideRuntimeApi<Block>,
BE: Backend<Block> + 'static,
BE::State: StateBackend<BlakeTwo256>,
C: ProvideRuntimeApi<Block> + StorageProvider<Block, BE>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error=BlockChainError> + 'static,
C: Send + Sync + 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
Expand Down

0 comments on commit d290857

Please sign in to comment.