-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generic
create connection
cli (#524)
* Scaffold generic create connection command * First stab at generic create connection command * Call Chain::InitConnectionOptions correctly * Cargo fmt * Hook up generic create connection cli command * Delete cosmos-specific create connection cli * Addd some additional bounds to CommandRunner impl * Fix compilation error --------- Co-authored-by: Soares Chen <[email protected]>
- Loading branch information
1 parent
9dd5e35
commit ab0513f
Showing
7 changed files
with
178 additions
and
114 deletions.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
crates/cli/cli-components/src/impls/commands/connection/create.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
use core::fmt::Display; | ||
use core::marker::PhantomData; | ||
|
||
use cgp::prelude::*; | ||
use hermes_logging_components::traits::has_logger::HasLogger; | ||
use hermes_logging_components::traits::logger::CanLog; | ||
use hermes_logging_components::types::level::LevelInfo; | ||
use hermes_relayer_components::build::traits::builders::relay_builder::CanBuildRelay; | ||
use hermes_relayer_components::chain::traits::types::chain_id::HasChainIdType; | ||
use hermes_relayer_components::chain::traits::types::connection::HasInitConnectionOptionsType; | ||
use hermes_relayer_components::chain::traits::types::ibc::HasClientIdType; | ||
use hermes_relayer_components::multi::traits::chain_at::HasChainTypeAt; | ||
use hermes_relayer_components::multi::traits::relay_at::HasRelayTypeAt; | ||
use hermes_relayer_components::multi::types::index::Index; | ||
use hermes_relayer_components::relay::impls::connection::bootstrap::CanBootstrapConnection; | ||
use hermes_relayer_components::relay::traits::chains::HasRelayChains; | ||
|
||
use crate::traits::build::CanLoadBuilder; | ||
use crate::traits::command::CommandRunner; | ||
use crate::traits::output::{CanProduceOutput, HasOutputType}; | ||
use crate::traits::parse::CanParseArg; | ||
|
||
pub struct RunCreateConnectionCommand; | ||
|
||
#[derive(Debug, clap::Parser, HasField)] | ||
pub struct CreateConnectionArgs { | ||
#[clap( | ||
long = "target-chain-id", | ||
required = true, | ||
value_name = "TARGET_CHAIN_ID", | ||
help_heading = "REQUIRED" | ||
)] | ||
target_chain_id: String, | ||
|
||
#[clap( | ||
long = "target-client-id", | ||
required = true, | ||
value_name = "TARGET_CLIENT_ID", | ||
help_heading = "REQUIRED" | ||
)] | ||
target_client_id: String, | ||
|
||
#[clap( | ||
long = "counterparty-chain-id", | ||
required = true, | ||
value_name = "COUNTERPARTY_CHAIN_ID", | ||
help_heading = "REQUIRED" | ||
)] | ||
counterparty_chain_id: String, | ||
|
||
#[clap( | ||
long = "counterparty-client-id", | ||
required = true, | ||
value_name = "COUNTERPARTY_CLIENT_ID", | ||
help_heading = "REQUIRED" | ||
)] | ||
counterparty_client_id: String, | ||
} | ||
|
||
impl<App, Args, Builder, Chain, Counterparty, Relay> CommandRunner<App, Args> | ||
for RunCreateConnectionCommand | ||
where | ||
App: HasOutputType + HasErrorType, | ||
App: CanLoadBuilder<Builder = Builder> | ||
+ HasLogger | ||
+ CanProduceOutput<&'static str> | ||
+ CanRaiseError<Builder::Error> | ||
+ CanRaiseError<Relay::Error> | ||
+ CanParseArg<Args, symbol!("target_chain_id"), Parsed = Chain::ChainId> | ||
+ CanParseArg<Args, symbol!("counterparty_chain_id"), Parsed = Counterparty::ChainId> | ||
+ CanParseArg<Args, symbol!("target_client_id"), Parsed = Chain::ClientId> | ||
+ CanParseArg<Args, symbol!("counterparty_client_id"), Parsed = Counterparty::ClientId>, | ||
App::Logger: CanLog<LevelInfo>, | ||
Builder: HasChainTypeAt<Index<0>, Chain = Chain> | ||
+ HasChainTypeAt<Index<1>, Chain = Counterparty> | ||
+ CanBuildRelay<Index<0>, Index<1>, Relay = Relay> | ||
+ HasRelayTypeAt<Index<0>, Index<1>>, | ||
Chain: | ||
HasChainIdType + HasClientIdType<Counterparty> + HasInitConnectionOptionsType<Counterparty>, | ||
Counterparty: HasChainIdType + HasClientIdType<Chain>, | ||
Chain::InitConnectionOptions: Default, | ||
Chain::ChainId: Display, | ||
Chain::ClientId: Display, | ||
Counterparty::ChainId: Display, | ||
Counterparty::ClientId: Display, | ||
Relay: CanBootstrapConnection + HasRelayChains<SrcChain = Chain, DstChain = Counterparty>, | ||
Args: Async, | ||
{ | ||
async fn run_command(app: &App, args: &Args) -> Result<App::Output, App::Error> { | ||
let logger = app.logger(); | ||
let builder = app.load_builder().await?; | ||
|
||
let target_chain_id = app.parse_arg(args, PhantomData::<symbol!("target_chain_id")>)?; | ||
let target_client_id = app.parse_arg(args, PhantomData::<symbol!("target_client_id")>)?; | ||
let counterparty_chain_id = | ||
app.parse_arg(args, PhantomData::<symbol!("counterparty_chain_id")>)?; | ||
let counterparty_client_id = | ||
app.parse_arg(args, PhantomData::<symbol!("counterparty_client_id")>)?; | ||
|
||
logger | ||
.log( | ||
&format!( | ||
"Creating connection between {}:{} and {}:{}...", | ||
target_chain_id, | ||
target_client_id, | ||
counterparty_chain_id, | ||
counterparty_client_id | ||
), | ||
&LevelInfo, | ||
) | ||
.await; | ||
|
||
let relay = builder | ||
.build_relay( | ||
PhantomData::<(Index<0>, Index<1>)>, | ||
&target_chain_id, | ||
&counterparty_chain_id, | ||
&target_client_id, | ||
&counterparty_client_id, | ||
) | ||
.await | ||
.map_err(App::raise_error)?; | ||
|
||
let (target_connection_id, counterparty_connection_id) = relay | ||
.bootstrap_connection(&Default::default()) | ||
.await | ||
.map_err(App::raise_error)?; | ||
|
||
logger | ||
.log( | ||
&format!( | ||
"Connection {}:{} successfully created between {}:{} and {}:{}", | ||
target_connection_id, | ||
counterparty_connection_id, | ||
target_chain_id, | ||
target_client_id, | ||
counterparty_chain_id, | ||
counterparty_client_id, | ||
), | ||
&LevelInfo, | ||
) | ||
.await; | ||
|
||
Ok(app.produce_output("Done")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod create; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod bootstrap; | ||
pub mod client; | ||
pub mod connection; | ||
pub mod queries; | ||
pub mod start; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters