Skip to content

Commit

Permalink
Add export-embedded-runtime subcommand (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
MOZGIII authored Nov 21, 2022
1 parent 76c563b commit 3dbb789
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
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

0 comments on commit 3dbb789

Please sign in to comment.