mithril_client_cli/commands/
mod.rs

1//! Command module
2//! This module holds the subcommands that can be used from the CLI.
3//!
4//!
5
6pub mod cardano_db;
7pub mod cardano_stake_distribution;
8pub mod cardano_transaction;
9mod deprecation;
10pub mod mithril_stake_distribution;
11pub mod tools;
12
13pub use deprecation::{DeprecatedCommand, Deprecation};
14
15use clap::Args;
16use mithril_client::{ClientBuilder, MithrilResult};
17
18use crate::configuration::ConfigParameters;
19
20const CLIENT_TYPE_CLI: &str = "CLI";
21
22/// Shared arguments for all commands
23#[derive(Debug, Clone, Args)]
24pub struct SharedArgs {
25    /// Enable JSON output for command results
26    #[clap(long)]
27    json: bool,
28}
29
30pub(crate) fn client_builder(params: &ConfigParameters) -> MithrilResult<ClientBuilder> {
31    let builder = ClientBuilder::aggregator(
32        &params.require("aggregator_endpoint")?,
33        &params.require("genesis_verification_key")?,
34    )
35    .with_origin_tag(params.get("origin_tag"))
36    .with_client_type(Some(CLIENT_TYPE_CLI.to_string()));
37
38    Ok(builder)
39}
40
41pub(crate) fn client_builder_with_fallback_genesis_key(
42    params: &ConfigParameters,
43) -> MithrilResult<ClientBuilder> {
44    // TODO: This should not be done this way.
45    // Now that mithril-client-cli uses the mithril-client library, the genesis verification key is required for all commands
46    let fallback_genesis_verification_key = "5b33322c3235332c3138362c3230312c3137372c31312c3131372c3133352c3138372c3136372c3138312c3138\
47        382c32322c35392c3230362c3130352c3233312c3135302c3231352c33302c37382c3231322c37362c31362c323\
48        5322c3138302c37322c3133342c3133372c3234372c3136312c36385d";
49
50    let builder = ClientBuilder::aggregator(
51        &params.require("aggregator_endpoint")?,
52        &params.get_or(
53            "genesis_verification_key",
54            fallback_genesis_verification_key,
55        ),
56    )
57    .with_origin_tag(params.get("origin_tag"))
58    .with_client_type(Some(CLIENT_TYPE_CLI.to_string()));
59
60    Ok(builder)
61}