hermes_cli/commands/client/
create.rs

1use cgp::prelude::*;
2use eyre::eyre;
3use ibc_relayer_types::core::ics02_client::trust_threshold::TrustThreshold;
4
5#[derive(Debug, clap::Parser, HasField)]
6pub struct CreateClientArgs {
7    /// Identifier of the chain that hosts the client
8    #[clap(
9        long = "target-chain",
10        required = true,
11        value_name = "TARGET_CHAIN_ID",
12        help_heading = "REQUIRED"
13    )]
14    pub target_chain_id: String,
15
16    /// Identifier of the chain targeted by the client
17    #[clap(
18        long = "counterparty-chain",
19        required = true,
20        value_name = "COUNTERPARTY_CHAIN_ID",
21        help_heading = "REQUIRED"
22    )]
23    pub counterparty_chain_id: String,
24
25    /// The maximum allowed clock drift for this client.
26    ///
27    /// The clock drift is a correction parameter. It helps deal with clocks
28    /// that are only approximately synchronized between the source and destination chains
29    /// of this client.
30    /// The destination chain for this client uses the clock drift parameter when deciding
31    /// to accept or reject a new header (originating from the source chain) for this client.
32    /// If this option is not specified, a suitable clock drift value is derived from the chain
33    /// configurations.
34    #[clap(long = "clock-drift", value_name = "CLOCK_DRIFT")]
35    pub clock_drift: Option<humantime::Duration>,
36
37    /// Override the trusting period specified in the config.
38    ///
39    /// The trusting period specifies how long a validator set is trusted for
40    /// (must be shorter than the chain's unbonding period).
41    #[clap(long = "trusting-period", value_name = "TRUSTING_PERIOD")]
42    pub trusting_period: Option<humantime::Duration>,
43
44    /// Override the trust threshold specified in the configuration.
45    ///
46    /// The trust threshold defines what fraction of the total voting power of a known
47    /// and trusted validator set is sufficient for a commit to be accepted going forward.
48    #[clap(
49        long = "trust-threshold",
50        value_name = "TRUST_THRESHOLD",
51        value_parser = parse_trust_threshold
52    )]
53    pub trust_threshold: Option<TrustThreshold>,
54}
55
56fn parse_trust_threshold(input: &str) -> eyre::Result<TrustThreshold> {
57    let (num_part, denom_part) = input
58        .split_once('/')
59        .ok_or_else(|| eyre!("expected a fractional argument, eg. '2/3'"))?;
60
61    let numerator = num_part
62        .trim()
63        .parse()
64        .map_err(|_| eyre!("invalid trust threshold numerator"))?;
65
66    let denominator = denom_part
67        .trim()
68        .parse()
69        .map_err(|_| eyre!("invalid trust threshold denominator"))?;
70
71    let trust_threshold = TrustThreshold::new(numerator, denominator)
72        .map_err(|e| eyre!("invalid trust threshold: {e}"))?;
73
74    Ok(trust_threshold)
75}