| 1954 | } |
| 1955 | |
| 1956 | pub async fn take_1(&mut self, client: &AsyncClient) -> Result<Transaction, Error> { |
| 1957 | verify_if_not_mined(client, self.take_1_transaction.tx().compute_txid()).await?; |
| 1958 | verify_if_not_mined(client, self.challenge_transaction.tx().compute_txid()).await?; |
| 1959 | verify_if_not_mined(client, self.assert_initial_transaction.tx().compute_txid()).await?; |
| 1960 | verify_if_not_mined(client, self.disprove_chain_transaction.tx().compute_txid()).await?; |
| 1961 | |
| 1962 | let peg_in_confirm_status = client.get_tx_status(&self.peg_in_confirm_txid).await; |
| 1963 | |
| 1964 | let kick_off_1_txid = self.kick_off_1_transaction.tx().compute_txid(); |
| 1965 | let kick_off_1_status = client.get_tx_status(&kick_off_1_txid).await; |
| 1966 | |
| 1967 | let kick_off_2_txid = self.kick_off_2_transaction.tx().compute_txid(); |
| 1968 | let kick_off_2_status = client.get_tx_status(&kick_off_2_txid).await; |
| 1969 | |
| 1970 | let blockchain_height = client.get_height().await; |
| 1971 | |
| 1972 | match (peg_in_confirm_status, kick_off_1_status, kick_off_2_status) { |
| 1973 | (Ok(pic_stat), Ok(ko1_stat), Ok(ko2_stat)) => { |
| 1974 | match (pic_stat.confirmed, ko1_stat.confirmed, ko2_stat.confirmed) { |
| 1975 | (true, true, true) => match ko2_stat.block_height { |
| 1976 | Some(block_height) |
| 1977 | if blockchain_height.is_ok_and(|height| { |
| 1978 | block_height + self.connector_3.num_blocks_timelock <= height |
| 1979 | }) => |
| 1980 | { |
| 1981 | Ok(self.take_1_transaction.finalize()) |
| 1982 | } |
| 1983 | _ => Err(Error::Graph(GraphError::PrecedingTxTimelockNotMet( |
| 1984 | NamedTx::for_tx(&self.kick_off_2_transaction, ko2_stat.confirmed), |
| 1985 | ))), |
| 1986 | }, |
| 1987 | _ => Err(Error::Graph(GraphError::PrecedingTxNotConfirmed(vec![ |
| 1988 | NamedTx { |
| 1989 | txid: self.peg_in_confirm_txid, |
| 1990 | name: PEG_IN_CONFIRM_TX_NAME, |
| 1991 | confirmed: pic_stat.confirmed, |
| 1992 | }, |
| 1993 | NamedTx::for_tx(&self.kick_off_1_transaction, ko1_stat.confirmed), |
| 1994 | NamedTx::for_tx(&self.kick_off_2_transaction, ko2_stat.confirmed), |
| 1995 | ]))), |
| 1996 | } |
| 1997 | } |
| 1998 | (Err(e), _, _) | (_, Err(e), _) | (_, _, Err(e)) => Err(Error::Esplora(e)), |
| 1999 | } |
| 2000 | } |
| 2001 | |
| 2002 | pub async fn take_2( |
| 2003 | &mut self, |