hopli/
main.rs

1//! `hopli` is a collection of commands to help with identity creation, funding, registration, etc. for HOPR nodes
2
3use clap::{Parser, Subcommand};
4use tracing_subscriber::layer::SubscriberExt;
5
6use crate::{
7    faucet::FaucetArgs,
8    identity::IdentitySubcommands,
9    network_registry::NetworkRegistrySubcommands,
10    safe_module::SafeModuleSubcommands,
11    utils::{Cmd, HelperErrors},
12    win_prob::WinProbSubcommands,
13};
14pub mod environment_config;
15pub mod faucet;
16pub mod identity;
17pub mod key_pair;
18pub mod methods;
19pub mod network_registry;
20pub mod safe_module;
21pub mod utils;
22pub mod win_prob;
23
24// Avoid musl's default allocator due to degraded performance
25// https://nickb.dev/blog/default-musl-allocator-considered-harmful-to-performance
26#[global_allocator]
27static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
28
29#[derive(Parser, Debug)]
30#[command(author, version, about, long_about = None)]
31struct Cli {
32    #[command(subcommand)]
33    pub command: Commands,
34}
35
36/// Helper for running your HOPR nodes
37#[derive(Subcommand, Debug)]
38enum Commands {
39    /// Commands around identity
40    #[command(visible_alias = "id")]
41    Identity {
42        #[command(subcommand)]
43        command: IdentitySubcommands,
44    },
45
46    /// Fund given address and/or addressed derived from identity files native tokens or HOPR tokens
47    #[clap(about = "Fund given address and/or addressed derived from identity files native tokens or HOPR tokens")]
48    Faucet(FaucetArgs),
49
50    /// Commands around network registry.
51    #[command(visible_alias = "nr")]
52    NetworkRegistry {
53        #[command(subcommand)]
54        command: NetworkRegistrySubcommands,
55    },
56
57    /// Commands around safe module
58    #[command(visible_alias = "sm")]
59    SafeModule {
60        #[command(subcommand)]
61        command: SafeModuleSubcommands,
62    },
63
64    /// Commands around winning probability
65    #[command(visible_alias = "wp")]
66    WinProb {
67        #[command(subcommand)]
68        command: WinProbSubcommands,
69    },
70}
71
72#[tokio::main]
73async fn main() -> Result<(), HelperErrors> {
74    let env_filter = tracing_subscriber::EnvFilter::try_from_default_env()
75        .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info"));
76    let format = tracing_subscriber::fmt::layer()
77        .with_level(true)
78        .with_target(true)
79        .with_thread_ids(true)
80        .with_thread_names(false);
81
82    let subscriber = tracing_subscriber::Registry::default().with(env_filter).with(format);
83
84    tracing::subscriber::set_global_default(subscriber).expect("Failed to set tracing subscriber");
85
86    let cli = Cli::parse();
87
88    match cli.command {
89        Commands::Identity { command } => {
90            command.run()?;
91        }
92        Commands::Faucet(opt) => {
93            opt.async_run().await?;
94        }
95        Commands::NetworkRegistry { command } => {
96            command.async_run().await?;
97        }
98        Commands::SafeModule { command } => {
99            command.async_run().await?;
100        }
101        Commands::WinProb { command } => {
102            command.async_run().await?;
103        }
104    }
105
106    Ok(())
107}