Skip to content

Commit

Permalink
Update ismp rpc (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizdave97 authored Sep 25, 2023
1 parent 37ef6bc commit 13f3185
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions parachain/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ use sp_core::H256;
pub type RpcExtension = jsonrpsee::RpcModule<()>;

/// Full client dependencies
pub struct FullDeps<C, P> {
pub struct FullDeps<C, P, B> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
pub pool: Arc<P>,
/// Whether to deny unsafe calls
pub deny_unsafe: DenyUnsafe,
/// Backend used by the node.
pub backend: Arc<B>,
}

/// Instantiate all RPC extensions.
pub fn create_full<C, P>(
deps: FullDeps<C, P>,
pub fn create_full<C, P, B>(
deps: FullDeps<C, P, B>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
Expand All @@ -49,17 +51,27 @@ where
C::Api: BlockBuilder<Block>,
C::Api: ismp_runtime_api::IsmpRuntimeApi<Block, H256>,
P: TransactionPool + Sync + Send + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::StateBackend<sp_runtime::traits::HashingFor<Block>>,
{
use ismp_rpc::{IsmpApiServer, IsmpRpcHandler};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};

let mut module = RpcExtension::new(());
let FullDeps { client, pool, deny_unsafe } = deps;
let FullDeps { client, pool, deny_unsafe, backend } = deps;

module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
module.merge(IsmpRpcHandler::new(client).into_rpc())?;
module.merge(
IsmpRpcHandler::new(
client,
backend
.offchain_storage()
.ok_or("Backend doesn't provide the required offchain storage")?,
)
.into_rpc(),
)?;

Ok(module)
}
2 changes: 2 additions & 0 deletions parachain/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,15 @@ async fn start_node_impl(

let rpc_builder = {
let client = client.clone();
let backend = backend.clone();
let transaction_pool = transaction_pool.clone();

Box::new(move |deny_unsafe, _| {
let deps = crate::rpc::FullDeps {
client: client.clone(),
pool: transaction_pool.clone(),
deny_unsafe,
backend: backend.clone(),
};

crate::rpc::create_full(deps).map_err(Into::into)
Expand Down

0 comments on commit 13f3185

Please sign in to comment.