Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add export-embedded-runtime subcommand #505

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions crates/humanode-peer/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pub async fn run() -> sc_cli::Result<()> {
cmd.run(partial.client, frontier_backend)
})
}
Some(Subcommand::ExportEmbeddedRuntime(cmd)) => cmd.run().await,
#[cfg(feature = "try-runtime")]
Some(Subcommand::TryRuntime(cmd)) => {
let runner = root.create_humanode_runner(cmd)?;
Expand Down
30 changes: 30 additions & 0 deletions crates/humanode-peer/src/cli/subcommand/export_embedded_runtime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! The command to export embedded runtime WASM.

use std::path::PathBuf;

use tokio::io::AsyncWriteExt;

/// The command.
#[derive(Debug, clap::Parser)]
pub struct ExportEmbeddedRuntimeCmd {
/// Specify the output path.
#[clap(long, short = 'o')]
out: Option<PathBuf>,
}

impl ExportEmbeddedRuntimeCmd {
/// Run the export embedded runtime command.
pub async fn run(&self) -> sc_cli::Result<()> {
let data = humanode_runtime::WASM_BINARY.ok_or_else(|| {
sc_cli::Error::Application("WASM binary is not embedded in this build".into())
})?;

match self.out {
Some(ref path) => tokio::fs::write(path, data).await,
None => tokio::io::stdout().write_all(data).await,
}
.map_err(sc_cli::Error::Io)?;

Ok(())
}
}
4 changes: 4 additions & 0 deletions crates/humanode-peer/src/cli/subcommand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::CliConfigurationExt;

pub mod bioauth;
pub mod ethereum;
pub mod export_embedded_runtime;

/// Humanode peer subcommands.
#[derive(Debug, clap::Subcommand)]
Expand Down Expand Up @@ -51,6 +52,9 @@ pub enum Subcommand {
/// Db meta columns information.
FrontierDb(fc_cli::FrontierDbCmd),

/// Export the runtime WASM code embedded in this binary.
ExportEmbeddedRuntime(export_embedded_runtime::ExportEmbeddedRuntimeCmd),

/// Try some command against runtime state.
#[cfg(feature = "try-runtime")]
TryRuntime(try_runtime_cli::TryRuntimeCmd),
Expand Down