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