| 1842 | } |
| 1843 | |
| 1844 | pub async fn disprove( |
| 1845 | &mut self, |
| 1846 | client: &AsyncClient, |
| 1847 | output_script_pubkey: ScriptBuf, |
| 1848 | verifying_key: &ZkProofVerifyingKey, |
| 1849 | ) -> Result<Transaction, Error> { |
| 1850 | verify_if_not_mined(client, self.disprove_transaction.tx().compute_txid()).await?; |
| 1851 | |
| 1852 | let assert_commit_1_txid = self.assert_commit_1_transaction.tx().compute_txid(); |
| 1853 | let assert_commit_2_txid = self.assert_commit_2_transaction.tx().compute_txid(); |
| 1854 | let Some(onchain_assert_commit_1_tx) = client |
| 1855 | .get_tx(&assert_commit_1_txid) |
| 1856 | .await |
| 1857 | .map_err(Error::Esplora)? |
| 1858 | else { |
| 1859 | return Err(Error::Other(format!( |
| 1860 | "Esplora failed to retrieve a tx {} with id: {}", |
| 1861 | self.assert_commit_1_transaction.name(), |
| 1862 | assert_commit_1_txid |
| 1863 | ))); |
| 1864 | }; |
| 1865 | let Some(onchain_assert_commit_2_tx) = client |
| 1866 | .get_tx(&assert_commit_2_txid) |
| 1867 | .await |
| 1868 | .map_err(Error::Esplora)? |
| 1869 | else { |
| 1870 | return Err(Error::Other(format!( |
| 1871 | "Esplora failed to retrieve a tx {} with id: {}", |
| 1872 | self.assert_commit_2_transaction.name(), |
| 1873 | assert_commit_2_txid |
| 1874 | ))); |
| 1875 | }; |
| 1876 | |
| 1877 | let assert_final_txid = self.assert_final_transaction.tx().compute_txid(); |
| 1878 | let assert_final_status = client.get_tx_status(&assert_final_txid).await; |
| 1879 | |
| 1880 | match assert_final_status { |
| 1881 | Ok(status) => match status.confirmed { |
| 1882 | true => { |
| 1883 | // get commit from assert_commit txs |
| 1884 | let assert_commit_1_witness = |
| 1885 | get_commit_from_assert_commit_tx(&onchain_assert_commit_1_tx); |
| 1886 | let assert_commit_2_witness = |
| 1887 | get_commit_from_assert_commit_tx(&onchain_assert_commit_2_tx); |
| 1888 | |
| 1889 | let (input_script_index, disprove_witness) = |
| 1890 | self.connector_c.generate_disprove_witness( |
| 1891 | assert_commit_1_witness, |
| 1892 | assert_commit_2_witness, |
| 1893 | verifying_key, |
| 1894 | )?; |
| 1895 | self.disprove_transaction.add_input_output( |
| 1896 | &self.connector_c, |
| 1897 | input_script_index, |
| 1898 | disprove_witness, |
| 1899 | output_script_pubkey, |
| 1900 | ); |
| 1901 | Ok(self.disprove_transaction.finalize()) |