Fix stupid errors

This commit is contained in:
patrini32 2024-06-04 20:39:36 +03:00 committed by patrini32
parent 7e5c1ae45a
commit 957c33bffe
2 changed files with 11 additions and 6 deletions

View File

@ -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) => {
@ -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(

View File

@ -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;