From cc900017986764854aa7dd30fd51285557d440e1 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Thu, 1 Aug 2024 14:32:01 +0300 Subject: [PATCH] cumulus: Enable ChainSpec for polkadot-parachain Signed-off-by: Alexandru Vasile --- Cargo.lock | 1 + cumulus/polkadot-parachain/Cargo.toml | 1 + cumulus/polkadot-parachain/src/rpc.rs | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 7466975fa428..2b5e9cbac4cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13900,6 +13900,7 @@ dependencies = [ "sc-network", "sc-network-sync", "sc-rpc", + "sc-rpc-spec-v2", "sc-service", "sc-sysinfo", "sc-telemetry", diff --git a/cumulus/polkadot-parachain/Cargo.toml b/cumulus/polkadot-parachain/Cargo.toml index b20d2a28fa7f..c32c258f61e3 100644 --- a/cumulus/polkadot-parachain/Cargo.toml +++ b/cumulus/polkadot-parachain/Cargo.toml @@ -77,6 +77,7 @@ sp-block-builder = { workspace = true, default-features = true } sp-keystore = { workspace = true, default-features = true } sc-chain-spec = { workspace = true, default-features = true } sc-rpc = { workspace = true, default-features = true } +sc-rpc-spec-v2 = { workspace = true, default-features = true } sp-version = { workspace = true, default-features = true } sc-tracing = { workspace = true, default-features = true } sp-offchain = { workspace = true, default-features = true } diff --git a/cumulus/polkadot-parachain/src/rpc.rs b/cumulus/polkadot-parachain/src/rpc.rs index feb2ae912fe0..681e407d30ab 100644 --- a/cumulus/polkadot-parachain/src/rpc.rs +++ b/cumulus/polkadot-parachain/src/rpc.rs @@ -28,6 +28,7 @@ use sc_rpc::{ dev::{Dev, DevApiServer}, DenyUnsafe, }; +use sc_rpc_spec_v2::chain_spec::{ChainSpec, ChainSpecApiServer}; use std::{marker::PhantomData, sync::Arc}; use substrate_frame_rpc_system::{System, SystemApiServer}; use substrate_state_trie_migration_rpc::{StateMigration, StateMigrationApiServer}; @@ -95,6 +96,12 @@ where module.merge(StateMigration::new(client.clone(), backend, deny_unsafe).into_rpc())?; module.merge(Dev::new(client, deny_unsafe).into_rpc())?; + // RPC spec v2 method. + let chain_name = chain_spec.name().to_string(); + let genesis_hash = client.hash(0).ok().flatten().expect("Genesis block exists; qed"); + let properties = chain_spec.properties(); + module.merge(ChainSpec::new(chain_name, genesis_hash, properties).into_rpc())?; + Ok(module) }; build().map_err(Into::into)