Skip to main content

cargo_tangle/command/debug/
spawn.rs

1use crate::command::run::tangle::run_blueprint;
2use crate::command::tangle::{DevnetStack, SpawnMethod, run_opts_from_stack};
3use crate::settings::load_protocol_settings;
4use blueprint_runner::config::Protocol;
5use clap::Args;
6use color_eyre::eyre::{Result, eyre};
7use std::path::PathBuf;
8
9#[derive(Args, Debug)]
10pub struct SpawnArgs {
11    /// Optional settings file to seed blueprint configuration.
12    #[arg(long, value_name = "FILE", default_value = "./settings.env")]
13    pub settings_file: PathBuf,
14    /// Stream Anvil stdout/stderr for debugging.
15    #[arg(long)]
16    pub include_anvil_logs: bool,
17    /// Allow unchecked attestations when running the manager.
18    #[arg(long)]
19    pub allow_unchecked_attestations: bool,
20    /// Preferred runtime for the spawned service.
21    #[arg(long, value_enum, default_value_t = SpawnMethod::Vm)]
22    pub spawn_method: SpawnMethod,
23}
24
25pub async fn execute(args: SpawnArgs) -> Result<()> {
26    let settings = load_protocol_settings(Protocol::Tangle, &args.settings_file)
27        .map_err(|e| eyre!(e.to_string()))?;
28    let tangle_settings = settings
29        .tangle()
30        .map_err(|e| eyre!("failed to load Tangle settings: {e}"))?;
31
32    let stack = DevnetStack::spawn(args.include_anvil_logs).await?;
33
34    println!(
35        "Anvil testnet ready at HTTP {} / WS {}",
36        stack.http_rpc_url(),
37        stack.ws_rpc_url()
38    );
39    println!("Press Ctrl+C to stop the blueprint and tear down the stack.");
40
41    let run_opts = run_opts_from_stack(
42        &stack,
43        tangle_settings,
44        args.allow_unchecked_attestations,
45        args.spawn_method,
46    );
47
48    // Run the blueprint manager until the user terminates the process.
49    run_blueprint(run_opts).await?;
50
51    stack.shutdown().await;
52    Ok(())
53}