Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add chainSpec RPC methods
  • Loading branch information
nazar-pc committed Nov 14, 2022
commit b98620972a43343ff1633009b57a0a657dee0338
4 changes: 4 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/subspace-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.
parity-scale-codec = "3.1.5"
parity-util-mem = { version = "0.12.0", default-features = false, features = ["primitive-types"] }
sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-consensus = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-consensus-fraud-proof = { version = "0.1.0", path = "../sc-consensus-fraud-proof" }
Expand All @@ -35,6 +36,7 @@ sc-network = { version = "0.10.0-dev", git = "https://github.com/subspace/substr
sc-piece-cache = { version = "0.1.0", path = "../sc-piece-cache" }
sc-rpc = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-rpc-spec-v2 = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-service = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f", default-features = false, features = ["wasmtime"] }
sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-tracing = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
Expand Down
2 changes: 2 additions & 0 deletions crates/subspace-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,13 @@ where
let reward_signing_notification_stream = reward_signing_notification_stream.clone();
let archived_segment_notification_stream = archived_segment_notification_stream.clone();
let transaction_pool = transaction_pool.clone();
let chain_spec = config.chain_spec.cloned_box();

Box::new(move |deny_unsafe, subscription_executor| {
let deps = rpc::FullDeps {
client: client.clone(),
pool: transaction_pool.clone(),
chain_spec: chain_spec.cloned_box(),
deny_unsafe,
subscription_executor,
new_slot_notification_stream: new_slot_notification_stream.clone(),
Expand Down
13 changes: 13 additions & 0 deletions crates/subspace-service/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use sc_consensus_subspace_rpc::{SubspaceRpc, SubspaceRpcApiServer};
use sc_piece_cache::PieceCache;
use sc_rpc::SubscriptionTaskExecutor;
use sc_rpc_api::DenyUnsafe;
use sc_rpc_spec_v2::chain_spec::{ChainSpec, ChainSpecApiServer};
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
Expand All @@ -48,6 +49,8 @@ pub struct FullDeps<C, P, PC> {
pub client: Arc<C>,
/// Transaction pool instance.
pub pool: Arc<P>,
/// A copy of the chain spec.
pub chain_spec: Box<dyn sc_chain_spec::ChainSpec>,
/// Whether to deny unsafe calls.
pub deny_unsafe: DenyUnsafe,
/// Executor to drive the subscription manager in the Grandpa RPC handler.
Expand Down Expand Up @@ -88,6 +91,7 @@ where
let FullDeps {
client,
pool,
chain_spec,
deny_unsafe,
subscription_executor,
new_slot_notification_stream,
Expand All @@ -96,6 +100,15 @@ where
piece_cache,
} = deps;

let chain_name = chain_spec.name().to_string();
let genesis_hash = client
.block_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())?;

module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;

Expand Down
2 changes: 2 additions & 0 deletions domains/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ pallet-transaction-payment-rpc = { git = "https://github.com/subspace/substrate"
substrate-frame-rpc-system = { git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }

## Substrate Client Dependencies
sc-chain-spec = { git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-client-api = { git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-consensus = { git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-executor = { git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-network = { git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-rpc = { git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-rpc-api = { git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-rpc-spec-v2 = { git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-service = { git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f", default-features = false, features = ["wasmtime"] }
sc-telemetry = { git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
sc-transaction-pool = { git = "https://github.com/subspace/substrate", rev = "66d3f73c5ef66c975fa5f54b6736ccd6821e395f" }
Expand Down
2 changes: 2 additions & 0 deletions domains/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,13 @@ where
let rpc_builder = {
let client = client.clone();
let transaction_pool = transaction_pool.clone();
let chain_spec = secondary_chain_config.chain_spec.cloned_box();

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

Expand Down
16 changes: 15 additions & 1 deletion domains/service/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

use jsonrpsee::RpcModule;
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use sc_client_api::AuxStore;
use sc_client_api::{AuxStore, BlockBackend};
use sc_rpc::DenyUnsafe;
use sc_rpc_spec_v2::chain_spec::{ChainSpec, ChainSpecApiServer};
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
Expand All @@ -24,6 +25,8 @@ pub struct FullDeps<C, P> {
pub client: Arc<C>,
/// Transaction pool instance.
pub pool: Arc<P>,
/// A copy of the chain spec.
pub chain_spec: Box<dyn sc_chain_spec::ChainSpec>,
/// Whether to deny unsafe calls
pub deny_unsafe: DenyUnsafe,
}
Expand All @@ -34,6 +37,7 @@ pub fn create_full<C, P>(
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
+ BlockBackend<Block>
+ HeaderBackend<Block>
+ AuxStore
+ HeaderMetadata<Block, Error = BlockChainError>
Expand All @@ -49,9 +53,19 @@ where
let FullDeps {
client,
pool,
chain_spec,
deny_unsafe,
} = deps;

let chain_name = chain_spec.name().to_string();
let genesis_hash = client
.block_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())?;

module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client).into_rpc())?;

Expand Down