| 1663 | } |
| 1664 | |
| 1665 | pub async fn kick_off_timeout( |
| 1666 | &mut self, |
| 1667 | client: &AsyncClient, |
| 1668 | output_script_pubkey: ScriptBuf, |
| 1669 | ) -> Result<Transaction, Error> { |
| 1670 | verify_if_not_mined( |
| 1671 | client, |
| 1672 | self.kick_off_timeout_transaction.tx().compute_txid(), |
| 1673 | ) |
| 1674 | .await?; |
| 1675 | |
| 1676 | let kick_off_1_txid = self.kick_off_1_transaction.tx().compute_txid(); |
| 1677 | let kick_off_1_status = client.get_tx_status(&kick_off_1_txid).await; |
| 1678 | |
| 1679 | let blockchain_height = client.get_height().await; |
| 1680 | |
| 1681 | match kick_off_1_status { |
| 1682 | Ok(status) => match status.confirmed { |
| 1683 | true => match status.block_height { |
| 1684 | Some(block_height) |
| 1685 | if blockchain_height.is_ok_and(|height| { |
| 1686 | block_height + self.connector_1.num_blocks_timelock_leaf_1 <= height |
| 1687 | }) => |
| 1688 | { |
| 1689 | self.kick_off_timeout_transaction |
| 1690 | .add_output(output_script_pubkey); |
| 1691 | Ok(self.kick_off_timeout_transaction.finalize()) |
| 1692 | } |
| 1693 | _ => Err(Error::Graph(GraphError::PrecedingTxTimelockNotMet( |
| 1694 | NamedTx::for_tx(&self.kick_off_1_transaction, status.confirmed), |
| 1695 | ))), |
| 1696 | }, |
| 1697 | false => Err(Error::Graph(GraphError::PrecedingTxNotConfirmed(vec![ |
| 1698 | NamedTx::for_tx(&self.kick_off_1_transaction, status.confirmed), |
| 1699 | ]))), |
| 1700 | }, |
| 1701 | Err(e) => Err(Error::Esplora(e)), |
| 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | pub async fn assert_initial(&mut self, client: &AsyncClient) -> Result<Transaction, Error> { |
| 1706 | verify_if_not_mined(client, self.assert_initial_transaction.tx().compute_txid()).await?; |