| 2000 | } |
| 2001 | |
| 2002 | pub async fn take_2( |
| 2003 | &mut self, |
| 2004 | client: &AsyncClient, |
| 2005 | context: &OperatorContext, |
| 2006 | ) -> Result<Transaction, Error> { |
| 2007 | verify_if_not_mined(client, self.take_2_transaction.tx().compute_txid()).await?; |
| 2008 | verify_if_not_mined(client, self.take_1_transaction.tx().compute_txid()).await?; |
| 2009 | verify_if_not_mined(client, self.disprove_transaction.tx().compute_txid()).await?; |
| 2010 | |
| 2011 | let peg_in_confirm_status = client.get_tx_status(&self.peg_in_confirm_txid).await; |
| 2012 | |
| 2013 | let assert_final_txid = self.assert_final_transaction.tx().compute_txid(); |
| 2014 | let assert_final_status = client.get_tx_status(&assert_final_txid).await; |
| 2015 | |
| 2016 | let blockchain_height = client.get_height().await; |
| 2017 | |
| 2018 | match (peg_in_confirm_status, assert_final_status) { |
| 2019 | (Ok(pic_stat), Ok(assert_stat)) => match (pic_stat.confirmed, assert_stat.confirmed) { |
| 2020 | (true, true) => match assert_stat.block_height { |
| 2021 | Some(block_height) |
| 2022 | if blockchain_height.is_ok_and(|height| { |
| 2023 | block_height + self.connector_4.num_blocks_timelock <= height |
| 2024 | }) => |
| 2025 | { |
| 2026 | self.take_2_transaction.sign(context, &self.connector_c); |
| 2027 | Ok(self.take_2_transaction.finalize()) |
| 2028 | } |
| 2029 | _ => Err(Error::Graph(GraphError::PrecedingTxTimelockNotMet( |
| 2030 | NamedTx::for_tx(&self.assert_final_transaction, assert_stat.confirmed), |
| 2031 | ))), |
| 2032 | }, |
| 2033 | _ => Err(Error::Graph(GraphError::PrecedingTxNotConfirmed(vec![ |
| 2034 | NamedTx { |
| 2035 | txid: self.peg_in_confirm_txid, |
| 2036 | name: PEG_IN_CONFIRM_TX_NAME, |
| 2037 | confirmed: pic_stat.confirmed, |
| 2038 | }, |
| 2039 | NamedTx::for_tx(&self.assert_final_transaction, assert_stat.confirmed), |
| 2040 | ]))), |
| 2041 | }, |
| 2042 | (Err(e), _) | (_, Err(e)) => Err(Error::Esplora(e)), |
| 2043 | } |
| 2044 | } |
| 2045 | |
| 2046 | pub fn is_peg_out_initiated(&self) -> bool { |
| 2047 | self.peg_out_chain_event.is_some() |