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#[cfg(target_os = "linux")]
27#[global_allocator]
28static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
29
30#[derive(Parser, Debug)]
31#[command(author, version, about, long_about = None)]
32struct Cli {
33    #[command(subcommand)]
34    pub command: Commands,
35}
36
37/// Helper for running your HOPR nodes
38#[derive(Subcommand, Debug)]
39enum Commands {
40    /// Commands around identity
41    #[command(visible_alias = "id")]
42    Identity {
43        #[command(subcommand)]
44        command: IdentitySubcommands,
45    },
46
47    /// Fund given address and/or addressed derived from identity files native tokens or HOPR tokens
48    #[clap(about = "Fund given address and/or addressed derived from identity files native tokens or HOPR tokens")]
49    Faucet(FaucetArgs),
50
51    /// Commands around network registry.
52    #[command(visible_alias = "nr")]
53    NetworkRegistry {
54        #[command(subcommand)]
55        command: NetworkRegistrySubcommands,
56    },
57
58    /// Commands around safe module
59    #[command(visible_alias = "sm")]
60    SafeModule {
61        #[command(subcommand)]
62        command: SafeModuleSubcommands,
63    },
64
65    /// Commands around winning probability
66    #[command(visible_alias = "wp")]
67    WinProb {
68        #[command(subcommand)]
69        command: WinProbSubcommands,
70    },
71}
72
73#[tokio::main]
74async fn main() -> Result<(), HelperErrors> {
75    let env_filter = tracing_subscriber::EnvFilter::try_from_default_env()
76        .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info"));
77    let format = tracing_subscriber::fmt::layer()
78        .with_level(true)
79        .with_target(true)
80        .with_thread_ids(true)
81        .with_thread_names(false);
82
83    let subscriber = tracing_subscriber::Registry::default().with(env_filter).with(format);
84
85    tracing::subscriber::set_global_default(subscriber).expect("Failed to set tracing subscriber");
86
87    let cli = Cli::parse();
88
89    match cli.command {
90        Commands::Identity { command } => {
91            command.run()?;
92        }
93        Commands::Faucet(opt) => {
94            opt.async_run().await?;
95        }
96        Commands::NetworkRegistry { command } => {
97            command.async_run().await?;
98        }
99        Commands::SafeModule { command } => {
100            command.async_run().await?;
101        }
102        Commands::WinProb { command } => {
103            command.async_run().await?;
104        }
105    }
106
107    Ok(())
108}