1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::controller::{Error, UserInteractionController};
use clap::Parser;
use jormungandr_automation::jormungandr::explorer::configuration::ExplorerParams;
use jortestkit::prelude::InteractiveCommandError;

#[derive(Parser, Debug)]
pub enum Explorer {
    /// Sends transaction
    Tip(ExplorerTip),
}

impl Explorer {
    pub fn exec(&self, controller: &mut UserInteractionController) -> Result<(), Error> {
        match self {
            Explorer::Tip(tip) => tip.exec(controller),
        }
    }
}

#[derive(Parser, Debug)]
pub struct ExplorerTip {
    #[clap(short = 'a', long = "alias")]
    pub alias: String,
}

impl ExplorerTip {
    pub fn exec(&self, controller: &mut UserInteractionController) -> Result<(), Error> {
        let node = controller
            .nodes()
            .iter()
            .find(|x| *x.alias() == self.alias)
            .ok_or_else(|| {
                InteractiveCommandError::UserError(format!("Node '{}' not found", self.alias))
            })?;
        println!(
            "{:#?}",
            node.explorer(ExplorerParams::default())?
                .client()
                .last_block()?
        );
        Ok(())
    }
}