Skip to content

Commit

Permalink
Fix stupid errors
Browse files Browse the repository at this point in the history
  • Loading branch information
patrini32 committed Jun 4, 2024
1 parent afa0c7b commit 8bfca15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions swap/src/cli/cancel_and_refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub async fn cancel_and_refund(
db: Arc<dyn Database + Send + Sync>,
) -> Result<BobState> {
match cancel(swap_id, bitcoin_wallet.clone(), db.clone()).await {
Ok((_, state @ BobState::BtcCancelled { .. })) => {
Ok((_, state @ BobState::BtcPunished { .. })) => {
return Ok(state);
}
Err(err) => {
Expand Down Expand Up @@ -62,18 +62,23 @@ 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) {
tracing::debug!(%error_code, "parse rpc error");
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?;
Expand All @@ -83,7 +88,7 @@ pub async fn cancel(
}
bail!(err);
}
};
}
}

pub async fn refund(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8bfca15

Please sign in to comment.