mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-09-29 21:06:21 +00:00
Use early return to reduce one level of indentation
This commit is contained in:
parent
05849505b1
commit
0d8962762a
@ -70,14 +70,14 @@ async fn run_until_internal(
|
||||
) -> Result<AliceState> {
|
||||
info!("Current state: {}", state);
|
||||
if is_target_state(&state) {
|
||||
Ok(state)
|
||||
} else {
|
||||
return Ok(state);
|
||||
}
|
||||
|
||||
match state {
|
||||
AliceState::Started { state3 } => {
|
||||
timeout(
|
||||
env_config.bob_time_to_act,
|
||||
bitcoin_wallet
|
||||
.watch_until_status(&state3.tx_lock, |status| status.has_been_seen()),
|
||||
bitcoin_wallet.watch_until_status(&state3.tx_lock, |status| status.has_been_seen()),
|
||||
)
|
||||
.await
|
||||
.context("Failed to find lock Bitcoin tx")??;
|
||||
@ -267,11 +267,7 @@ async fn run_until_internal(
|
||||
.is_err()
|
||||
{
|
||||
let transaction = tx_cancel
|
||||
.complete_as_alice(
|
||||
state3.a.clone(),
|
||||
state3.B,
|
||||
state3.tx_cancel_sig_bob.clone(),
|
||||
)
|
||||
.complete_as_alice(state3.a.clone(), state3.B, state3.tx_cancel_sig_bob.clone())
|
||||
.context("Failed to complete Bitcoin cancel transaction")?;
|
||||
|
||||
if let Err(e) = bitcoin_wallet.broadcast(transaction, "cancel").await {
|
||||
@ -314,8 +310,7 @@ async fn run_until_internal(
|
||||
let seen_refund_tx =
|
||||
bitcoin_wallet.watch_until_status(&tx_refund, |status| status.has_been_seen());
|
||||
|
||||
let punish_timelock_expired = bitcoin_wallet
|
||||
.watch_until_status(&tx_cancel, |status| {
|
||||
let punish_timelock_expired = bitcoin_wallet.watch_until_status(&tx_cancel, |status| {
|
||||
status.is_confirmed_with(state3.punish_timelock)
|
||||
});
|
||||
|
||||
@ -389,8 +384,7 @@ async fn run_until_internal(
|
||||
)?;
|
||||
|
||||
let punish_tx_finalised = async {
|
||||
let (txid, finality) =
|
||||
bitcoin_wallet.broadcast(signed_tx_punish, "punish").await?;
|
||||
let (txid, finality) = bitcoin_wallet.broadcast(signed_tx_punish, "punish").await?;
|
||||
|
||||
finality.await?;
|
||||
|
||||
@ -462,5 +456,4 @@ async fn run_until_internal(
|
||||
AliceState::BtcPunished => Ok(AliceState::BtcPunished),
|
||||
AliceState::SafelyAborted => Ok(AliceState::SafelyAborted),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +63,9 @@ async fn run_until_internal(
|
||||
) -> Result<BobState> {
|
||||
trace!("Current state: {}", state);
|
||||
if is_target_state(&state) {
|
||||
Ok(state)
|
||||
} else {
|
||||
return Ok(state);
|
||||
}
|
||||
|
||||
match state {
|
||||
BobState::Started { btc_amount } => {
|
||||
let bitcoin_refund_address = bitcoin_wallet.new_address().await?;
|
||||
@ -373,7 +374,9 @@ async fn run_until_internal(
|
||||
// Bob has cancelled the swap
|
||||
let state = match state.expired_timelock(bitcoin_wallet.as_ref()).await? {
|
||||
ExpiredTimelocks::None => {
|
||||
bail!("Internal error: canceled state reached before cancel timelock was expired");
|
||||
bail!(
|
||||
"Internal error: canceled state reached before cancel timelock was expired"
|
||||
);
|
||||
}
|
||||
ExpiredTimelocks::Cancel => {
|
||||
state.refund_btc(bitcoin_wallet.as_ref()).await?;
|
||||
@ -404,7 +407,6 @@ async fn run_until_internal(
|
||||
BobState::SafelyAborted => Ok(BobState::SafelyAborted),
|
||||
BobState::XmrRedeemed { tx_lock_id } => Ok(BobState::XmrRedeemed { tx_lock_id }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn request_price_and_setup(
|
||||
|
Loading…
Reference in New Issue
Block a user