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 std::sync::Arc;
16
17use mithril_client::{ClientBuilder, MithrilResult};
18
19use crate::{configuration::ConfigParameters, utils::ForcedEraFetcher};
20
21const CLIENT_TYPE_CLI: &str = "CLI";
22
23pub(crate) fn client_builder(params: &ConfigParameters) -> MithrilResult<ClientBuilder> {
24    let builder = ClientBuilder::aggregator(
25        &params.require("aggregator_endpoint")?,
26        &params.require("genesis_verification_key")?,
27    );
28
29    Ok(finalize_builder_config(builder, params))
30}
31
32pub(crate) fn client_builder_with_fallback_genesis_key(
33    params: &ConfigParameters,
34) -> MithrilResult<ClientBuilder> {
35    // TODO: This should not be done this way.
36    // Now that mithril-client-cli uses the mithril-client library, the genesis verification key is required for all commands
37    let fallback_genesis_verification_key = "5b33322c3235332c3138362c3230312c3137372c31312c3131372c3133352c3138372c3136372c3138312c3138\
38        382c32322c35392c3230362c3130352c3233312c3135302c3231352c33302c37382c3231322c37362c31362c323\
39        5322c3138302c37322c3133342c3133372c3234372c3136312c36385d";
40
41    let builder = ClientBuilder::aggregator(
42        &params.require("aggregator_endpoint")?,
43        &params.get_or(
44            "genesis_verification_key",
45            fallback_genesis_verification_key,
46        ),
47    );
48
49    Ok(finalize_builder_config(builder, params))
50}
51
52fn finalize_builder_config(mut builder: ClientBuilder, params: &ConfigParameters) -> ClientBuilder {
53    builder = builder
54        .with_origin_tag(params.get("origin_tag"))
55        .with_client_type(Some(CLIENT_TYPE_CLI.to_string()));
56
57    if let Some(era) = params.get("era") {
58        builder = builder.with_era_fetcher(Arc::new(ForcedEraFetcher::new(era.to_string())));
59    }
60
61    builder
62}