leo_lang/cli/commands/devnode/
mod.rs1mod advance;
18pub mod logger;
19pub mod rest;
20mod start;
21
22use super::*;
23use crate::cli::{
24 Command,
25 PrivateKeyOptions,
26 commands::{Context, Span},
27};
28use clap::Parser;
29
30#[derive(Parser, Debug)]
31pub enum DevnodeCommands {
32 #[clap(name = "start", about = "Start the Devnode")]
33 Start {
34 #[clap(flatten)]
35 command: start::Start,
36 },
37 #[clap(name = "advance", about = "Advance the ledger by a specified number of blocks")]
38 Advance {
39 #[clap(flatten)]
40 command: advance::Advance,
41 },
42}
43
44#[derive(Parser, Debug)]
46pub struct LeoDevnode {
47 #[clap(flatten)]
48 pub(crate) key_override: PrivateKeyOptions,
49 #[clap(subcommand)]
50 pub command: DevnodeCommands,
51}
52
53impl Command for LeoDevnode {
54 type Input = ();
55 type Output = ();
56
57 fn log_span(&self) -> Span {
58 tracing::span!(tracing::Level::INFO, "Leo")
59 }
60
61 fn prelude(&self, _context: Context) -> Result<Self::Input> {
62 Ok(())
63 }
64
65 fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
66 handle_devnode(self, context)
67 }
68}
69
70fn handle_devnode(devnode_command: LeoDevnode, context: Context) -> Result<<LeoDevnode as Command>::Output> {
72 let private_key = devnode_command.key_override.private_key;
73 match devnode_command.command {
74 DevnodeCommands::Start { command } => {
75 tracing::info!("Starting the Devnode server...");
76 command.apply(context, private_key)
77 }
78 DevnodeCommands::Advance { command } => command.apply(context, ()),
79 }
80}