Skip to main content

leo_lang/cli/commands/devnode/
mod.rs

1// Copyright (C) 2019-2026 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17mod 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/// Command for initializing and creating blocks for a local client node.
45#[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
70// A helper function to handle the Devnode command based on the subcommand provided.
71fn 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}