mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-04-20 07:56:05 -04:00
Use transaction created by check_for_tx_cancel and delete construct_tx_cancel
This commit is contained in:
parent
d1cbc0c8d9
commit
67df816a8c
@ -65,22 +65,13 @@ pub async fn cancel(
|
||||
Ok((txid, state))
|
||||
}
|
||||
Err(err) => {
|
||||
if state6
|
||||
.check_for_tx_cancel(bitcoin_wallet.as_ref())
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
if let Ok(tx) = state6.check_for_tx_cancel(bitcoin_wallet.as_ref()).await {
|
||||
// Alice already cancelled, so we are out-of-sync with Alice.
|
||||
let txid = state6
|
||||
// Construct tx_cancel without broadcasting to the network, because swap has already been cancelled by Alice.
|
||||
.construct_tx_cancel()
|
||||
.expect("Error when constructing tx_cancel")
|
||||
.txid();
|
||||
let state = BobState::BtcCancelled(state6); // Set state to cancelled to sync with Alice.
|
||||
db.insert_latest_state(swap_id, state.clone().into())
|
||||
.await?;
|
||||
tracing::info!("Cancel transaction has already been confirmed on chain. The swap has therefore already been cancelled by Alice.");
|
||||
return Ok((txid, state));
|
||||
return Ok((tx.txid(), state));
|
||||
}
|
||||
if let Ok(error_code) = parse_rpc_error_code(&err) {
|
||||
tracing::debug!(%error_code, "parse rpc error");
|
||||
|
@ -701,9 +701,12 @@ impl State6 {
|
||||
let tx = bitcoin_wallet.get_raw_transaction(tx_punish.txid()).await?;
|
||||
Ok(tx)
|
||||
}
|
||||
pub fn construct_tx_cancel(&self) -> Result<Transaction> {
|
||||
// Just construct the tx_cancel without broadcasting.
|
||||
bitcoin::TxCancel::new(
|
||||
|
||||
pub async fn submit_tx_cancel(
|
||||
&self,
|
||||
bitcoin_wallet: &bitcoin::Wallet,
|
||||
) -> Result<(Txid, Subscription)> {
|
||||
let transaction = bitcoin::TxCancel::new(
|
||||
&self.tx_lock,
|
||||
self.cancel_timelock,
|
||||
self.A,
|
||||
@ -711,13 +714,7 @@ impl State6 {
|
||||
self.tx_cancel_fee,
|
||||
)?
|
||||
.complete_as_bob(self.A, self.b.clone(), self.tx_cancel_sig_a.clone())
|
||||
.context("Failed to complete Bitcoin cancel transaction")
|
||||
}
|
||||
pub async fn submit_tx_cancel(
|
||||
&self,
|
||||
bitcoin_wallet: &bitcoin::Wallet,
|
||||
) -> Result<(Txid, Subscription)> {
|
||||
let transaction = self.construct_tx_cancel()?;
|
||||
.context("Failed to complete Bitcoin cancel transaction")?;
|
||||
|
||||
let (tx_id, subscription) = bitcoin_wallet.broadcast(transaction, "cancel").await?;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user