From 957c33bffe53c62220719372b5bd737864aa837b Mon Sep 17 00:00:00 2001 From: patrini32 <171664803+patrini32@users.noreply.github.com> Date: Tue, 4 Jun 2024 20:39:36 +0300 Subject: [PATCH] Fix stupid errors --- swap/src/cli/cancel_and_refund.rs | 15 ++++++++++----- ...lly_punishes_after_bob_dead_and_bob_cancels.rs | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/swap/src/cli/cancel_and_refund.rs b/swap/src/cli/cancel_and_refund.rs index 9a152d0f..e71db5ef 100644 --- a/swap/src/cli/cancel_and_refund.rs +++ b/swap/src/cli/cancel_and_refund.rs @@ -12,7 +12,7 @@ pub async fn cancel_and_refund( db: Arc, ) -> Result { match cancel(swap_id, bitcoin_wallet.clone(), db.clone()).await { - Ok((_, state @ BobState::BtcCancelled { .. })) => { + Ok((_, state @ BobState::BtcPunished { .. })) => { return Ok(state); } Err(err) => { @@ -62,10 +62,12 @@ pub async fn cancel( match state6.submit_tx_cancel(bitcoin_wallet.as_ref()).await { Ok((txid, _)) => { - let state = BobState::BtcCancelled(state6); + let state = BobState::BtcPunished { + tx_lock_id: state6.tx_lock_id(), + }; db.insert_latest_state(swap_id, state.clone().into()) .await?; - return Ok((txid, state)); + Ok((txid, state)) } Err(err) => { if let Ok(error_code) = parse_rpc_error_code(&err) { @@ -73,7 +75,10 @@ pub async fn cancel( if error_code == i64::from(RpcErrorCode::RpcVerifyAlreadyInChain) || error_code == i64::from(RpcErrorCode::RpcVerifyError) { - let txid = state6.construct_tx_cancel().unwrap().txid(); + let txid = state6 + .construct_tx_cancel() + .expect("Error when constructing tx_cancel") + .txid(); let state = BobState::BtcCancelled(state6); db.insert_latest_state(swap_id, state.clone().into()) .await?; @@ -83,7 +88,7 @@ pub async fn cancel( } bail!(err); } - }; + } } pub async fn refund( diff --git a/swap/tests/alice_manually_punishes_after_bob_dead_and_bob_cancels.rs b/swap/tests/alice_manually_punishes_after_bob_dead_and_bob_cancels.rs index de0ba4e7..5eacefd1 100644 --- a/swap/tests/alice_manually_punishes_after_bob_dead_and_bob_cancels.rs +++ b/swap/tests/alice_manually_punishes_after_bob_dead_and_bob_cancels.rs @@ -76,7 +76,7 @@ async fn alice_manually_punishes_after_bob_dead_and_bob_cancels() { let state = cli::cancel_and_refund(bob_swap_id, bob_swap.bitcoin_wallet, bob_swap.db).await?; - assert!(matches!(state, BobState::BtcCancelled { .. })); + assert!(matches!(state, BobState::BtcPunished { .. })); Ok(()) }) .await;