hopli/
main.rs

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! `hopli` is a collection of commands to help with identity creation, funding, registration, etc. for HOPR nodes

use crate::faucet::FaucetArgs;
use crate::identity::IdentitySubcommands;
use crate::network_registry::NetworkRegistrySubcommands;
use crate::safe_module::SafeModuleSubcommands;
use crate::utils::{Cmd, HelperErrors};
use crate::win_prob::WinProbSubcommands;
use clap::{Parser, Subcommand};
use tracing_subscriber::layer::SubscriberExt;
pub mod environment_config;
pub mod faucet;
pub mod identity;
pub mod key_pair;
pub mod methods;
pub mod network_registry;
pub mod safe_module;
pub mod utils;
pub mod win_prob;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Cli {
    #[command(subcommand)]
    pub command: Commands,
}

/// Helper for running your HOPR nodes
#[derive(Subcommand, Debug)]
enum Commands {
    /// Commands around identity
    #[command(visible_alias = "id")]
    Identity {
        #[command(subcommand)]
        command: IdentitySubcommands,
    },

    /// Fund given address and/or addressed derived from identity files native tokens or HOPR tokens
    #[clap(about = "Fund given address and/or addressed derived from identity files native tokens or HOPR tokens")]
    Faucet(FaucetArgs),

    /// Commands around network registry.
    #[command(visible_alias = "nr")]
    NetworkRegistry {
        #[command(subcommand)]
        command: NetworkRegistrySubcommands,
    },

    /// Commands around safe module
    #[command(visible_alias = "sm")]
    SafeModule {
        #[command(subcommand)]
        command: SafeModuleSubcommands,
    },

    /// Commands around winning probability
    #[command(visible_alias = "wp")]
    WinProb {
        #[command(subcommand)]
        command: WinProbSubcommands,
    },
}

#[async_std::main]
async fn main() -> Result<(), HelperErrors> {
    let env_filter = tracing_subscriber::EnvFilter::try_from_default_env()
        .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info"));
    let format = tracing_subscriber::fmt::layer()
        .with_level(true)
        .with_target(true)
        .with_thread_ids(true)
        .with_thread_names(false);

    let subscriber = tracing_subscriber::Registry::default().with(env_filter).with(format);

    tracing::subscriber::set_global_default(subscriber).expect("Failed to set tracing subscriber");

    let cli = Cli::parse();

    match cli.command {
        Commands::Identity { command } => {
            command.run()?;
        }
        Commands::Faucet(opt) => {
            opt.async_run().await?;
        }
        Commands::NetworkRegistry { command } => {
            command.async_run().await?;
        }
        Commands::SafeModule { command } => {
            command.async_run().await?;
        }
        Commands::WinProb { command } => {
            command.async_run().await?;
        }
    }

    Ok(())
}