mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-12-11 23:05:38 -05:00
Use transaction created by check_for_tx_cancel and delete construct_tx_cancel
This commit is contained in:
parent
0c2b5de533
commit
b1319368a4
2 changed files with 9 additions and 21 deletions
|
|
@ -65,22 +65,13 @@ pub async fn cancel(
|
||||||
Ok((txid, state))
|
Ok((txid, state))
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if state6
|
if let Ok(tx) = state6.check_for_tx_cancel(bitcoin_wallet.as_ref()).await {
|
||||||
.check_for_tx_cancel(bitcoin_wallet.as_ref())
|
|
||||||
.await
|
|
||||||
.is_ok()
|
|
||||||
{
|
|
||||||
// Alice already cancelled, so we are out-of-sync with Alice.
|
// 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.
|
let state = BobState::BtcCancelled(state6); // Set state to cancelled to sync with Alice.
|
||||||
db.insert_latest_state(swap_id, state.clone().into())
|
db.insert_latest_state(swap_id, state.clone().into())
|
||||||
.await?;
|
.await?;
|
||||||
tracing::info!("Cancel transaction has already been confirmed on chain. The swap has therefore already been cancelled by Alice.");
|
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) {
|
if let Ok(error_code) = parse_rpc_error_code(&err) {
|
||||||
tracing::debug!(%error_code, "parse rpc error");
|
tracing::debug!(%error_code, "parse rpc error");
|
||||||
|
|
|
||||||
|
|
@ -701,9 +701,12 @@ impl State6 {
|
||||||
let tx = bitcoin_wallet.get_raw_transaction(tx_punish.txid()).await?;
|
let tx = bitcoin_wallet.get_raw_transaction(tx_punish.txid()).await?;
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
pub fn construct_tx_cancel(&self) -> Result<Transaction> {
|
|
||||||
// Just construct the tx_cancel without broadcasting.
|
pub async fn submit_tx_cancel(
|
||||||
bitcoin::TxCancel::new(
|
&self,
|
||||||
|
bitcoin_wallet: &bitcoin::Wallet,
|
||||||
|
) -> Result<(Txid, Subscription)> {
|
||||||
|
let transaction = bitcoin::TxCancel::new(
|
||||||
&self.tx_lock,
|
&self.tx_lock,
|
||||||
self.cancel_timelock,
|
self.cancel_timelock,
|
||||||
self.A,
|
self.A,
|
||||||
|
|
@ -711,13 +714,7 @@ impl State6 {
|
||||||
self.tx_cancel_fee,
|
self.tx_cancel_fee,
|
||||||
)?
|
)?
|
||||||
.complete_as_bob(self.A, self.b.clone(), self.tx_cancel_sig_a.clone())
|
.complete_as_bob(self.A, self.b.clone(), self.tx_cancel_sig_a.clone())
|
||||||
.context("Failed to complete Bitcoin cancel transaction")
|
.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()?;
|
|
||||||
|
|
||||||
let (tx_id, subscription) = bitcoin_wallet.broadcast(transaction, "cancel").await?;
|
let (tx_id, subscription) = bitcoin_wallet.broadcast(transaction, "cancel").await?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue