// Copyright 2019-2021 Parity Technologies (UK) Ltd. // This file is part of Parity Bridges Common. // Parity Bridges Common is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // Parity Bridges Common is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with Parity Bridges Common. If not, see . use crate::cli::{PrometheusParams, SourceConnectionParams, TargetConnectionParams, TargetSigningParams}; use crate::finality_pipeline::SubstrateFinalitySyncPipeline; use structopt::{clap::arg_enum, StructOpt}; /// Start headers relayer process. #[derive(StructOpt)] pub struct RelayHeaders { /// A bridge instance to relay headers for. #[structopt(possible_values = &RelayHeadersBridge::variants(), case_insensitive = true)] bridge: RelayHeadersBridge, #[structopt(flatten)] source: SourceConnectionParams, #[structopt(flatten)] target: TargetConnectionParams, #[structopt(flatten)] target_sign: TargetSigningParams, #[structopt(flatten)] prometheus_params: PrometheusParams, } // TODO [#851] Use kebab-case. arg_enum! { #[derive(Debug)] /// Headers relay bridge. pub enum RelayHeadersBridge { MillauToRialto, RialtoToMillau, WestendToMillau, } } macro_rules! select_bridge { ($bridge: expr, $generic: tt) => { match $bridge { RelayHeadersBridge::MillauToRialto => { type Source = relay_millau_client::Millau; type Target = relay_rialto_client::Rialto; type Finality = crate::rialto_millau::millau_headers_to_rialto::MillauFinalityToRialto; $generic } RelayHeadersBridge::RialtoToMillau => { type Source = relay_rialto_client::Rialto; type Target = relay_millau_client::Millau; type Finality = crate::rialto_millau::rialto_headers_to_millau::RialtoFinalityToMillau; $generic } RelayHeadersBridge::WestendToMillau => { type Source = relay_westend_client::Westend; type Target = relay_millau_client::Millau; type Finality = crate::rialto_millau::westend_headers_to_millau::WestendFinalityToMillau; $generic } } }; } impl RelayHeaders { /// Run the command. pub async fn run(self) -> anyhow::Result<()> { select_bridge!(self.bridge, { let source_client = self.source.into_client::().await?; let target_client = self.target.into_client::().await?; let target_sign = self.target_sign.into_keypair::()?; let metrics_params = Finality::customize_metrics(self.prometheus_params.into())?; crate::finality_pipeline::run( Finality::new(target_client.clone(), target_sign), source_client, target_client, metrics_params, ) .await }) } }