Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
3 changes: 3 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions bin/node-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ build = "build.rs"
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[lib]
name = "node_template"

[[bin]]
name = "node-template"

Expand Down
1 change: 1 addition & 0 deletions bin/node-template/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl SubstrateCli for Cli {
}

/// Parse and run command line arguments
#[allow(dead_code)]
pub fn run() -> sc_cli::Result<()> {
let cli = Cli::from_args();

Expand Down
6 changes: 6 additions & 0 deletions bin/node-template/node/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mod benchmarking;
mod chain_spec;
pub mod cli;
mod command;
mod rpc;
pub mod service;
3 changes: 3 additions & 0 deletions test-utils/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ nix = "0.26.2"
regex = "1.7.3"
tokio = { version = "1.22.0", features = ["full"] }
node-primitives = { path = "../../bin/node/primitives" }
node-template = { path = "../../bin/node-template/node" }
sc-cli = { path = "../../client/cli" }
sc-service = { path = "../../client/service" }
futures = "0.3.28"
29 changes: 29 additions & 0 deletions test-utils/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,35 @@ use std::{
};
use tokio::io::{AsyncBufReadExt, AsyncRead};

/// Similar to [`crate::start_node`] spawns a dev node on port `45789`, but works in environments
/// where the substarte binary is not accessible with `cargo_bin("substrate-node")`.
///
/// Helpful if you need a Substrate dev node running in the background of a project external to
/// `substrate`.
///
/// The downside compared to using [`crate::start_node`] is that this method is blocking rather than
/// returning a [`Child`]. Therefore, you may want to call this method inside a new thread.
///
/// # Example
/// ```ignore
/// // Spawn a dev node in the background.
/// let _ = std::thread::spawn(move || {
/// common::start_node_without_binary();
/// });
/// ```
pub fn start_node_without_binary() -> Result<(), sc_service::error::Error> {
use sc_cli::SubstrateCli;

let cli = node_template::cli::Cli::from_iter(vec![
"node-template", // first arg is ignored, this could be anything.
"--dev",
"--tmp",
"--rpc-port=45789",
]);
let runner = cli.create_runner(&cli.run).unwrap();
runner.run_node_until_exit(|config| async move { node_template::service::new_full(config) })
}

/// Starts a new Substrate node in development mode with a temporary chain.
///
/// This function creates a new Substrate node using the `substrate` binary.
Expand Down