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