From 9d64f3fd2952fa5056ac5d7c06a9138b1b19fb43 Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Fri, 16 Oct 2020 14:16:06 +1100 Subject: [PATCH] Watch the blockchain during Bitcoin refund --- xmr-btc/src/bitcoin/transactions.rs | 4 ++++ xmr-btc/src/lib.rs | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/xmr-btc/src/bitcoin/transactions.rs b/xmr-btc/src/bitcoin/transactions.rs index 9eb7878d..1402c9cc 100644 --- a/xmr-btc/src/bitcoin/transactions.rs +++ b/xmr-btc/src/bitcoin/transactions.rs @@ -260,6 +260,10 @@ impl TxCancel { } } + pub fn txid(&self) -> Txid { + self.inner.txid() + } + pub fn digest(&self) -> SigHash { self.digest } diff --git a/xmr-btc/src/lib.rs b/xmr-btc/src/lib.rs index 5a5d95b9..479f2a0a 100644 --- a/xmr-btc/src/lib.rs +++ b/xmr-btc/src/lib.rs @@ -248,6 +248,7 @@ where if let Err(SwapFailed::AfterBtcLock(_)) = swap_result { let tx_cancel = bitcoin::TxCancel::new(&tx_lock, refund_timelock, A.clone(), b.public()); + let tx_cancel_txid = tx_cancel.txid(); let signed_tx_cancel = { let sig_a = tx_cancel_sig_a.clone(); let sig_b = b.sign(tx_cancel.digest()); @@ -260,9 +261,13 @@ where co.yield_(Action::CancelBitcoin(signed_tx_cancel)).await; - let signed_tx_refund = { - let tx_refund = bitcoin::TxRefund::new(&tx_cancel, &refund_address); + let _ = bitcoin_ledger + .watch_for_raw_transaction(tx_cancel_txid) + .await; + let tx_refund = bitcoin::TxRefund::new(&tx_cancel, &refund_address); + let tx_refund_txid = tx_refund.txid(); + let signed_tx_refund = { let adaptor = Adaptor::>::default(); let sig_a = @@ -275,6 +280,10 @@ where }; co.yield_(Action::RefundBitcoin(signed_tx_refund)).await; + + let _ = bitcoin_ledger + .watch_for_raw_transaction(tx_refund_txid) + .await; } }) }