From 13f31859ff6bb8faee3f64ee04a7fe09b7d3062e Mon Sep 17 00:00:00 2001 From: David Salami <31099392+Wizdave97@users.noreply.github.com> Date: Mon, 25 Sep 2023 08:38:42 +0100 Subject: [PATCH] Update ismp rpc (#27) --- Cargo.lock | 10 +++++----- parachain/node/src/rpc.rs | 22 +++++++++++++++++----- parachain/node/src/service.rs | 2 ++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 316aa8b5a..0d5b6a7ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5271,7 +5271,7 @@ dependencies = [ [[package]] name = "ismp-demo" version = "0.1.0" -source = "git+https://github.com/polytope-labs/substrate-ismp.git?branch=main#043dae1f4b373b241a2c7bdc63db5db49f62297a" +source = "git+https://github.com/polytope-labs/substrate-ismp.git?branch=main#66f4a78edbe91eee2879dc74048bf1278452ee87" dependencies = [ "frame-support", "frame-system", @@ -5336,7 +5336,7 @@ dependencies = [ [[package]] name = "ismp-primitives" version = "0.1.0" -source = "git+https://github.com/polytope-labs/substrate-ismp.git?branch=main#043dae1f4b373b241a2c7bdc63db5db49f62297a" +source = "git+https://github.com/polytope-labs/substrate-ismp.git?branch=main#66f4a78edbe91eee2879dc74048bf1278452ee87" dependencies = [ "ckb-merkle-mountain-range", "frame-support", @@ -5355,7 +5355,7 @@ dependencies = [ [[package]] name = "ismp-rpc" version = "0.1.0" -source = "git+https://github.com/polytope-labs/substrate-ismp.git?branch=main#043dae1f4b373b241a2c7bdc63db5db49f62297a" +source = "git+https://github.com/polytope-labs/substrate-ismp.git?branch=main#66f4a78edbe91eee2879dc74048bf1278452ee87" dependencies = [ "frame-system", "hex-literal 0.3.4", @@ -5377,7 +5377,7 @@ dependencies = [ [[package]] name = "ismp-runtime-api" version = "0.1.0" -source = "git+https://github.com/polytope-labs/substrate-ismp.git?branch=main#043dae1f4b373b241a2c7bdc63db5db49f62297a" +source = "git+https://github.com/polytope-labs/substrate-ismp.git?branch=main#66f4a78edbe91eee2879dc74048bf1278452ee87" dependencies = [ "ismp", "ismp-primitives", @@ -7592,7 +7592,7 @@ dependencies = [ [[package]] name = "pallet-ismp" version = "0.1.0" -source = "git+https://github.com/polytope-labs/substrate-ismp.git?branch=main#043dae1f4b373b241a2c7bdc63db5db49f62297a" +source = "git+https://github.com/polytope-labs/substrate-ismp.git?branch=main#66f4a78edbe91eee2879dc74048bf1278452ee87" dependencies = [ "ckb-merkle-mountain-range", "derive_more", diff --git a/parachain/node/src/rpc.rs b/parachain/node/src/rpc.rs index 552cf9436..097bae11a 100644 --- a/parachain/node/src/rpc.rs +++ b/parachain/node/src/rpc.rs @@ -21,18 +21,20 @@ use sp_core::H256; pub type RpcExtension = jsonrpsee::RpcModule<()>; /// Full client dependencies -pub struct FullDeps { +pub struct FullDeps { /// The client instance to use. pub client: Arc, /// Transaction pool instance. pub pool: Arc

, /// Whether to deny unsafe calls pub deny_unsafe: DenyUnsafe, + /// Backend used by the node. + pub backend: Arc, } /// Instantiate all RPC extensions. -pub fn create_full( - deps: FullDeps, +pub fn create_full( + deps: FullDeps, ) -> Result> where C: ProvideRuntimeApi @@ -49,17 +51,27 @@ where C::Api: BlockBuilder, C::Api: ismp_runtime_api::IsmpRuntimeApi, P: TransactionPool + Sync + Send + 'static, + B: sc_client_api::Backend + Send + Sync + 'static, + B::State: sc_client_api::StateBackend>, { 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) } diff --git a/parachain/node/src/service.rs b/parachain/node/src/service.rs index cb2d64638..063649bc3 100644 --- a/parachain/node/src/service.rs +++ b/parachain/node/src/service.rs @@ -222,6 +222,7 @@ 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, _| { @@ -229,6 +230,7 @@ async fn start_node_impl( client: client.clone(), pool: transaction_pool.clone(), deny_unsafe, + backend: backend.clone(), }; crate::rpc::create_full(deps).map_err(Into::into)