From c2329b19a2597936881dea67f7508ba4417708ed Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 5 Mar 2021 16:24:02 +1100 Subject: [PATCH] Tell the user more about the monero lock transaction First, we tell the user that we are now waiting for Alice to lock the monero. Additionally, we tell them once we received the transfer proof which will lead directly into the "waiting for confirmations" function. --- swap/src/monero.rs | 6 ++++++ swap/src/monero/wallet.rs | 2 +- swap/src/protocol/bob/swap.rs | 11 +++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/swap/src/monero.rs b/swap/src/monero.rs index d086cfa7..77b7dae9 100644 --- a/swap/src/monero.rs +++ b/swap/src/monero.rs @@ -175,6 +175,12 @@ impl From for String { } } +impl fmt::Display for TxHash { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + #[derive(Debug, Clone, Copy, thiserror::Error)] #[error("transaction does not pay enough: expected {expected}, got {actual}")] pub struct InsufficientFunds { diff --git a/swap/src/monero/wallet.rs b/swap/src/monero/wallet.rs index 11514ff9..44f1b8f8 100644 --- a/swap/src/monero/wallet.rs +++ b/swap/src/monero/wallet.rs @@ -160,7 +160,7 @@ impl Wallet { expected_amount: Amount, conf_target: u32, ) -> Result<(), InsufficientFunds> { - let txid = &transfer_proof.tx_hash.0; + let txid = &transfer_proof.tx_hash(); tracing::info!(%txid, "Waiting for {} confirmation{} of Monero transaction", conf_target, if conf_target > 1 { "s" } else { "" }); diff --git a/swap/src/protocol/bob/swap.rs b/swap/src/protocol/bob/swap.rs index c6eefb7a..30f84ec6 100644 --- a/swap/src/protocol/bob/swap.rs +++ b/swap/src/protocol/bob/swap.rs @@ -133,16 +133,23 @@ async fn run_until_internal( // block 0 once we create the redeem wallet. let monero_wallet_restore_blockheight = monero_wallet.block_height().await?; + tracing::info!("Waiting for Alice to lock Monero"); + select! { transfer_proof = transfer_proof_watcher => { - let transfer_proof = transfer_proof?; + let transfer_proof = transfer_proof?.tx_lock_proof; + + tracing::info!(txid = %transfer_proof.tx_hash(), "Alice locked Monero"); + BobState::XmrLockProofReceived { state: state3, - lock_transfer_proof: transfer_proof.tx_lock_proof, + lock_transfer_proof: transfer_proof, monero_wallet_restore_blockheight } }, _ = cancel_timelock_expires => { + tracing::info!("Alice took too long to lock Monero, cancelling the swap"); + let state4 = state3.cancel(); BobState::CancelTimelockExpired(state4) }