fn handshake(&mut self) -> Result<(), ConnectionError> {
        let done = '🥂';

        let a_chain = self.a_side.chain.clone();
        let b_chain = self.b_side.chain.clone();

        // Try connOpenInit on a_chain
        let mut counter = 0;
        while counter < MAX_ITER {
            counter += 1;
            match self.flipped().build_conn_init_and_send() {
                Err(e) => {
                    error!("Failed ConnInit {:?}: {}", self.a_side, e);
                    continue;
                }
                Ok(result) => {
                    self.a_side.connection_id = extract_connection_id(&result)?.clone();
                    println!("🥂  {} => {:#?}\n", self.a_side.chain.id(), result);
                    break;
                }
            }
        }

        // Try connOpenTry on b_chain
        counter = 0;
        while counter < MAX_ITER {
            counter += 1;
            match self.build_conn_try_and_send() {
                Err(e) => {
                    error!("Failed ConnTry {:?}: {}", self.b_side, e);
                    continue;
                }
                Ok(result) => {
                    self.b_side.connection_id = extract_connection_id(&result)?.clone();
                    println!("{}  {} => {:#?}\n", done, self.b_side.chain.id(), result);
                    break;
                }
            }
        }

        counter = 0;
        while counter < MAX_ITER {
            counter += 1;

            // Continue loop if query error
            let a_connection = a_chain.query_connection(&self.src_connection_id(), Height::zero());
            if a_connection.is_err() {
                continue;
            }
            let b_connection = b_chain.query_connection(&self.dst_connection_id(), Height::zero());
            if b_connection.is_err() {
                continue;
            }

            match (
                a_connection.unwrap().state().clone(),
                b_connection.unwrap().state().clone(),
            ) {
                (State::Init, State::TryOpen) | (State::TryOpen, State::TryOpen) => {
                    // Ack to a_chain
                    match self.flipped().build_conn_ack_and_send() {
                        Err(e) => error!("Failed ConnAck {:?}: {}", self.a_side, e),
                        Ok(event) => {
                            println!("{}  {} => {:#?}\n", done, self.a_side.chain.id(), event)
                        }
                    }
                }
                (State::Open, State::TryOpen) => {
                    // Confirm to b_chain
                    match self.build_conn_confirm_and_send() {
                        Err(e) => error!("Failed ConnConfirm {:?}: {}", self.b_side, e),
                        Ok(event) => {
                            println!("{}  {} => {:#?}\n", done, self.b_side.chain.id(), event)
                        }
                    }
                }
                (State::TryOpen, State::Open) => {
                    // Confirm to a_chain
                    match self.flipped().build_conn_confirm_and_send() {
                        Err(e) => error!("Failed ConnConfirm {:?}: {}", self.a_side, e),
                        Ok(event) => {
                            println!("{}  {} => {:#?}\n", done, self.a_side.chain.id(), event)
                        }
                    }
                }
                (State::Open, State::Open) => {
                    println!(
                        "{0}{0}{0}  Connection handshake finished for [{1:#?}]\n",
                        done, self
                    );
                    return Ok(());
                }
                _ => {}
            }
        }

        Err(ConnectionError::Failed(format!(
            "Failed to finish connection handshake in {:?} iterations",
            MAX_ITER
        )))
    }
/// Executes a connection handshake protocol (ICS 003) for this connection object
Executes a connection handshake protocol (ICS 003) for this connection object
Executes a connection handshake protocol ( ICS 003 ) for this connection object
fn handshake(&mut self) -> Result<(), ConnectionError> {
        let done = '🥂';
        let a_chain = self.a_side.chain.clone();
        let b_chain = self.b_side.chain.clone();
        // Try connOpenInit on a_chain
        let mut counter = 0;
        while counter < MAX_ITER {
            counter += 1;
            match self.flipped().build_conn_init_and_send() {
                Err(e) => {
                    error!("Failed ConnInit {:?}: {}", self.a_side, e);
                    continue;
                }
                Ok(result) => {
                    self.a_side.connection_id = extract_connection_id(&result)?.clone();
                    println!("🥂  {} => {:#?}\n", self.a_side.chain.id(), result);
                    break;
                }
            }
        }
        // Try connOpenTry on b_chain
        counter = 0;
        while counter < MAX_ITER {
            counter += 1;
            match self.build_conn_try_and_send() {
                Err(e) => {
                    error!("Failed ConnTry {:?}: {}", self.b_side, e);
                    continue;
                }
                Ok(result) => {
                    self.b_side.connection_id = extract_connection_id(&result)?.clone();
                    println!("{}  {} => {:#?}\n", done, self.b_side.chain.id(), result);
                    break;
                }
            }
        }
        counter = 0;
        while counter < MAX_ITER {
            counter += 1;
            // Continue loop if query error
            let a_connection = a_chain.query_connection(&self.src_connection_id(), Height::zero());
            if a_connection.is_err() {
                continue;
            }
            let b_connection = b_chain.query_connection(&self.dst_connection_id(), Height::zero());
            if b_connection.is_err() {
                continue;
            }
            match (
                a_connection.unwrap().state().clone(),
                b_connection.unwrap().state().clone(),
            ) {
                (State::Init, State::TryOpen) | (State::TryOpen, State::TryOpen) => {
                    // Ack to a_chain
                    match self.flipped().build_conn_ack_and_send() {
                        Err(e) => error!("Failed ConnAck {:?}: {}", self.a_side, e),
                        Ok(event) => {
                            println!("{}  {} => {:#?}\n", done, self.a_side.chain.id(), event)
                        }
                    }
                }
                (State::Open, State::TryOpen) => {
                    // Confirm to b_chain
                    match self.build_conn_confirm_and_send() {
                        Err(e) => error!("Failed ConnConfirm {:?}: {}", self.b_side, e),
                        Ok(event) => {
                            println!("{}  {} => {:#?}\n", done, self.b_side.chain.id(), event)
                        }
                    }
                }
                (State::TryOpen, State::Open) => {
                    // Confirm to a_chain
                    match self.flipped().build_conn_confirm_and_send() {
                        Err(e) => error!("Failed ConnConfirm {:?}: {}", self.a_side, e),
                        Ok(event) => {
                            println!("{}  {} => {:#?}\n", done, self.a_side.chain.id(), event)
                        }
                    }
                }
                (State::Open, State::Open) => {
                    println!(
                        "{0}{0}{0}  Connection handshake finished for [{1:#?}]\n",
                        done, self
                    );
                    return Ok(());
                }
                _ => {}
            }
        }
        Err(ConnectionError::Failed(format!(
            "Failed to finish connection handshake in {:?} iterations",
            MAX_ITER
        )))
    }
fn handshake ( & mut self ) -> Result < ( ) , ConnectionError > { let done = '🥂'; let a_chain = self . a_side . chain . clone ( ) ; let b_chain = self . b_side . chain . clone ( ) ; // Try connOpenInit on a_chain let mut counter = 0 ; while counter < MAX_ITER { counter += 1 ; match self . flipped ( ) . build_conn_init_and_send ( ) { Err ( e ) => { error ! ( " " self a_side e ) ; continue ; } Ok ( result ) => { self . a_side . connection_id = extract_connection_id ( & result ) ? . clone ( ) ; println ! ( " ,  s f.a_ ide.ch in.id ), r ult); break ; } } } // Try connOpenTry on b_chain counter = 0 ; while counter < MAX_ITER { counter += 1 ; match self . build_conn_try_and_send ( ) { Err ( e ) => { error ! ( " " self b_side e ) ; continue ; } Ok ( result ) => { self . b_side . connection_id = extract_connection_id ( & result ) ? . clone ( ) ; println ! ( " \n " done self b_side chain id ( ) result ) ; break ; } } } counter = 0 ; while counter < MAX_ITER { counter += 1 ; // Continue loop if query error let a_connection = a_chain . query_connection ( & self . src_connection_id ( ) , Height :: zero ( ) ) ; if a_connection . is_err ( ) { continue ; } let b_connection = b_chain . query_connection ( & self . dst_connection_id ( ) , Height :: zero ( ) ) ; if b_connection . is_err ( ) { continue ; } match ( a_connection . unwrap ( ) . state ( ) . clone ( ) , b_connection . unwrap ( ) . state ( ) . clone ( ) , ) { ( State :: Init , State :: TryOpen ) | ( State :: TryOpen , State :: TryOpen ) => { // Ack to a_chain match self . flipped ( ) . build_conn_ack_and_send ( ) { Err ( e ) => error ! ( " " self a_side e ) , Ok ( event ) => { println ! ( " \n " done self a_side chain id ( ) event ) } } } ( State :: Open , State :: TryOpen ) => { // Confirm to b_chain match self . build_conn_confirm_and_send ( ) { Err ( e ) => error ! ( " " self b_side e ) , Ok ( event ) => { println ! ( " \n " done self b_side chain id ( ) event ) } } } ( State :: TryOpen , State :: Open ) => { // Confirm to a_chain match self . flipped ( ) . build_conn_confirm_and_send ( ) { Err ( e ) => error ! ( " " self a_side e ) , Ok ( event ) => { println ! ( " \n " done self a_side chain id ( ) event ) } } } ( State :: Open , State :: Open ) => { println ! ( " \n " done self ) ; return Ok ( ( ) ) ; } _ => { } } } Err ( ConnectionError :: Failed ( format ! ( " " MAX_ITER ) ) ) }
Executes a connection handshake protocol (ICS 003) for this connection object
Executes a connection handshake protocol ( ICS 003 ) for this connection object
&mut self
&mut self