pub async fn connect(
        &self,
        signer: impl Signer,
        chain_id: ChainId,
        request_id: Option<String>,
        memo: String,
        force: bool,
    ) -> Result<()> {
        let mut transaction = self
            .db_pool
            .begin()
            .await
            .context("unable to begin database transaction")?;

        let mut chain = chain::get_chain(&mut transaction, &chain_id)
            .await?
            .ok_or_else(|| anyhow!("chain details for {} not found", chain_id))?;

        let (already_established, channel_closed) = {
            match chain.connection_details {
                None => (false, true),
                Some(ref detail) => {
                    let port_id = &chain.config.port_id;
                    match &detail.tendermint_channel_id {
                        Some(channel_id) => {
                            let channel =
                                ibc_handler::get_channel(&mut *transaction, port_id, channel_id)
                                    .await?
                                    .ok_or_else(|| {
                                        anyhow!(
                                "channel for channel id ({}) and port id ({}) not found",
                                channel_id,
                                port_id
                            )
                                    })?;
                            (true, channel.state == ChannelState::Closed as i32)
                        }
                        None => (true, true),
                    }
                }
            }
        };
        if already_established && !channel_closed && !force {
            anyhow::bail!("connection is already established with given chain");
        }

        // if connection is not not established or connection is established, but need to force reconnect
        // create new client and connection first
        let rpc_client = HttpClient::new(chain.config.rpc_addr.as_str())
            .context("unable to connect to rpc client")?;
        let (client_id, connection_id) = if !already_established {
            let client_id = self
                .create_new_client(
                    &signer,
                    memo.clone(),
                    request_id.as_deref(),
                    &chain,
                    rpc_client.clone(),
                    &mut transaction,
                )
                .await?;
            let connection_id = self
                .create_connection(
                    &mut chain,
                    &signer,
                    &rpc_client,
                    &mut transaction,
                    &client_id.0,
                    &client_id.1,
                    memo.clone(),
                    request_id.as_deref(),
                )
                .await?;
            (client_id, connection_id)
        } else {
            if !channel_closed && !force {
                anyhow::bail!("connection is already established with given chain");
            }
            todo!("get solo_chaine_client_id and tendermint_client_id")
        };
        let (solo_machine_channel_id, tendermint_channel_id) = self
            .open_channel(
                &signer,
                memo,
                request_id.as_deref(),
                &mut chain,
                &rpc_client,
                &connection_id.0,
                &connection_id.1,
                &mut transaction,
            )
            .await?;
        let connection_details = ChainConnectionDetails {
            solo_machine_client_id: client_id.0.clone(),
            tendermint_client_id: client_id.1,
            solo_machine_connection_id: connection_id.0.clone(),
            tendermint_connection_id: connection_id.1,
            solo_machine_channel_id: Some(solo_machine_channel_id),
            tendermint_channel_id: Some(tendermint_channel_id),
        };

        chain::add_connection_details(&mut *transaction, &chain.id, &connection_details).await?;

        notify_event(
            &self.notifier,
            Event::ConnectionEstablished {
                chain_id,
                connection_details,
            },
        )?;

        transaction
            .commit()
            .await
            .context("unable to commit transaction for creating ibc connection")
    }
/// Establishes connection with an IBC enabled chain
Establishes connection with an IBC enabled chain
Establishes connection with an IBC enabled chain
pub async fn connect(
        &self,
        signer: impl Signer,
        chain_id: ChainId,
        request_id: Option<String>,
        memo: String,
        force: bool,
    ) -> Result<()> {
        let mut transaction = self
            .db_pool
            .begin()
            .await
            .context("unable to begin database transaction")?;
        let mut chain = chain::get_chain(&mut transaction, &chain_id)
            .await?
            .ok_or_else(|| anyhow!("chain details for {} not found", chain_id))?;
        let (already_established, channel_closed) = {
            match chain.connection_details {
                None => (false, true),
                Some(ref detail) => {
                    let port_id = &chain.config.port_id;
                    match &detail.tendermint_channel_id {
                        Some(channel_id) => {
                            let channel =
                                ibc_handler::get_channel(&mut *transaction, port_id, channel_id)
                                    .await?
                                    .ok_or_else(|| {
                                        anyhow!(
                                "channel for channel id ({}) and port id ({}) not found",
                                channel_id,
                                port_id
                            )
                                    })?;
                            (true, channel.state == ChannelState::Closed as i32)
                        }
                        None => (true, true),
                    }
                }
            }
        };
        if already_established && !channel_closed && !force {
            anyhow::bail!("connection is already established with given chain");
        }
        // if connection is not not established or connection is established, but need to force reconnect
        // create new client and connection first
        let rpc_client = HttpClient::new(chain.config.rpc_addr.as_str())
            .context("unable to connect to rpc client")?;
        let (client_id, connection_id) = if !already_established {
            let client_id = self
                .create_new_client(
                    &signer,
                    memo.clone(),
                    request_id.as_deref(),
                    &chain,
                    rpc_client.clone(),
                    &mut transaction,
                )
                .await?;
            let connection_id = self
                .create_connection(
                    &mut chain,
                    &signer,
                    &rpc_client,
                    &mut transaction,
                    &client_id.0,
                    &client_id.1,
                    memo.clone(),
                    request_id.as_deref(),
                )
                .await?;
            (client_id, connection_id)
        } else {
            if !channel_closed && !force {
                anyhow::bail!("connection is already established with given chain");
            }
            todo!("get solo_chaine_client_id and tendermint_client_id")
        };
        let (solo_machine_channel_id, tendermint_channel_id) = self
            .open_channel(
                &signer,
                memo,
                request_id.as_deref(),
                &mut chain,
                &rpc_client,
                &connection_id.0,
                &connection_id.1,
                &mut transaction,
            )
            .await?;
        let connection_details = ChainConnectionDetails {
            solo_machine_client_id: client_id.0.clone(),
            tendermint_client_id: client_id.1,
            solo_machine_connection_id: connection_id.0.clone(),
            tendermint_connection_id: connection_id.1,
            solo_machine_channel_id: Some(solo_machine_channel_id),
            tendermint_channel_id: Some(tendermint_channel_id),
        };
        chain::add_connection_details(&mut *transaction, &chain.id, &connection_details).await?;
        notify_event(
            &self.notifier,
            Event::ConnectionEstablished {
                chain_id,
                connection_details,
            },
        )?;
        transaction
            .commit()
            .await
            .context("unable to commit transaction for creating ibc connection")
    }
pub async fn connect ( & self , signer : impl Signer , chain_id : ChainId , request_id : Option < String > , memo : String , force : bool , ) -> Result < ( ) > { let mut transaction = self . db_pool . begin ( ) . await . context ( " " ) ? ; let mut chain = chain :: get_chain ( & mut transaction , & chain_id ) . await ? . ok_or_else ( | | anyhow ! ( " " chain_id ) ) ? ; let ( already_established , channel_closed ) = { match chain . connection_details { None => ( false , true ) , Some ( ref detail ) => { let port_id = & chain . config . port_id ; match & detail . tendermint_channel_id { Some ( channel_id ) => { let channel = ibc_handler :: get_channel ( & mut * transaction , port_id , channel_id ) . await ? . ok_or_else ( | | { anyhow ! ( " " channel_id port_id ) } ) ? ; ( true , channel . state == ChannelState :: Closed as i32 ) } None => ( true , true ) , } } } } ; if already_established && ! channel_closed && ! force { anyhow :: bail ! ( " " ) ; } // if connection is not not established or connection is established, but need to force reconnect // create new client and connection first let rpc_client = HttpClient :: new ( chain . config . rpc_addr . as_str ( ) ) . context ( " " ) ? ; let ( client_id , connection_id ) = if ! already_established { let client_id = self . create_new_client ( & signer , memo . clone ( ) , request_id . as_deref ( ) , & chain , rpc_client . clone ( ) , & mut transaction , ) . await ? ; let connection_id = self . create_connection ( & mut chain , & signer , & rpc_client , & mut transaction , & client_id . 0 , & client_id . 1 , memo . clone ( ) , request_id . as_deref ( ) , ) . await ? ; ( client_id , connection_id ) } else { if ! channel_closed && ! force { anyhow :: bail ! ( " " ) ; } todo ! ( " " ) } ; let ( solo_machine_channel_id , tendermint_channel_id ) = self . open_channel ( & signer , memo , request_id . as_deref ( ) , & mut chain , & rpc_client , & connection_id . 0 , & connection_id . 1 , & mut transaction , ) . await ? ; let connection_details = ChainConnectionDetails { solo_machine_client_id : client_id . 0 . clone ( ) , tendermint_client_id : client_id . 1 , solo_machine_connection_id : connection_id . 0 . clone ( ) , tendermint_connection_id : connection_id . 1 , solo_machine_channel_id : Some ( solo_machine_channel_id ) , tendermint_channel_id : Some ( tendermint_channel_id ) , } ; chain :: add_connection_details ( & mut * transaction , & chain . id , & connection_details ) . await ? ; notify_event ( & self . notifier , Event :: ConnectionEstablished { chain_id , connection_details , } , ) ? ; transaction . commit ( ) . await . context ( " " ) }
Establishes connection with an IBC enabled chain
Establishes connection with an IBC enabled chain
&self
signer
impl Signer
chain_id
ChainId
request_id
Option<String>
memo
String
force
bool
&self
signer
impl Signer
chain_id
ChainId
request_id
Option<String>
memo
String
force
bool