mod advance;
pub mod logger;
pub mod rest;
mod start;
use super::*;
use crate::cli::{
Command,
PrivateKeyOptions,
commands::{Context, Span},
};
use clap::Parser;
#[derive(Parser, Debug)]
pub enum DevnodeCommands {
#[clap(name = "start", about = "Start the Devnode")]
Start {
#[clap(flatten)]
command: start::Start,
},
#[clap(name = "advance", about = "Advance the ledger by a specified number of blocks")]
Advance {
#[clap(flatten)]
command: advance::Advance,
},
}
#[derive(Parser, Debug)]
pub struct LeoDevnode {
#[clap(flatten)]
pub(crate) key_override: PrivateKeyOptions,
#[clap(subcommand)]
pub command: DevnodeCommands,
}
impl Command for LeoDevnode {
type Input = ();
type Output = ();
fn log_span(&self) -> Span {
tracing::span!(tracing::Level::INFO, "Leo")
}
fn prelude(&self, _context: Context) -> Result<Self::Input> {
Ok(())
}
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
handle_devnode(self, context)
}
}
fn handle_devnode(devnode_command: LeoDevnode, context: Context) -> Result<<LeoDevnode as Command>::Output> {
let private_key = devnode_command.key_override.private_key;
match devnode_command.command {
DevnodeCommands::Start { command } => {
tracing::info!("Starting the Devnode server...");
command.apply(context, private_key)
}
DevnodeCommands::Advance { command } => command.apply(context, ()),
}
}