mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-02-17 13:14:21 -05:00
Refund swap if resumed from a step that requires further communication
This commit is contained in:
parent
11cea9ba69
commit
c095693a5f
@ -45,12 +45,12 @@ pub enum AliceState {
|
|||||||
state0: State0,
|
state0: State0,
|
||||||
},
|
},
|
||||||
Negotiated {
|
Negotiated {
|
||||||
channel: ResponseChannel<AliceToBob>,
|
channel: Option<ResponseChannel<AliceToBob>>,
|
||||||
amounts: SwapAmounts,
|
amounts: SwapAmounts,
|
||||||
state3: State3,
|
state3: State3,
|
||||||
},
|
},
|
||||||
BtcLocked {
|
BtcLocked {
|
||||||
channel: ResponseChannel<AliceToBob>,
|
channel: Option<ResponseChannel<AliceToBob>>,
|
||||||
amounts: SwapAmounts,
|
amounts: SwapAmounts,
|
||||||
state3: State3,
|
state3: State3,
|
||||||
},
|
},
|
||||||
@ -159,7 +159,7 @@ pub async fn run_until(
|
|||||||
|
|
||||||
run_until(
|
run_until(
|
||||||
AliceState::Negotiated {
|
AliceState::Negotiated {
|
||||||
channel,
|
channel: Some(channel),
|
||||||
amounts,
|
amounts,
|
||||||
state3,
|
state3,
|
||||||
},
|
},
|
||||||
@ -176,48 +176,84 @@ pub async fn run_until(
|
|||||||
channel,
|
channel,
|
||||||
amounts,
|
amounts,
|
||||||
} => {
|
} => {
|
||||||
let _ =
|
match channel {
|
||||||
wait_for_locked_bitcoin(state3.tx_lock.txid(), bitcoin_wallet.clone(), config)
|
Some(channel) => {
|
||||||
|
let _ = wait_for_locked_bitcoin(
|
||||||
|
state3.tx_lock.txid(),
|
||||||
|
bitcoin_wallet.clone(),
|
||||||
|
config,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
run_until(
|
run_until(
|
||||||
AliceState::BtcLocked {
|
AliceState::BtcLocked {
|
||||||
channel,
|
channel: Some(channel),
|
||||||
amounts,
|
amounts,
|
||||||
state3,
|
state3,
|
||||||
},
|
},
|
||||||
is_target_state,
|
is_target_state,
|
||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
config,
|
config,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
tracing::info!("Cannot resume swap from negotiated state, aborting");
|
||||||
|
|
||||||
|
// Alice did not lock Xmr yet
|
||||||
|
run_until(
|
||||||
|
AliceState::SafelyAborted,
|
||||||
|
is_target_state,
|
||||||
|
event_loop_handle,
|
||||||
|
bitcoin_wallet,
|
||||||
|
monero_wallet,
|
||||||
|
config,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
AliceState::BtcLocked {
|
AliceState::BtcLocked {
|
||||||
channel,
|
channel,
|
||||||
amounts,
|
amounts,
|
||||||
state3,
|
state3,
|
||||||
} => {
|
} => match channel {
|
||||||
lock_xmr(
|
Some(channel) => {
|
||||||
channel,
|
lock_xmr(
|
||||||
amounts,
|
channel,
|
||||||
state3.clone(),
|
amounts,
|
||||||
&mut event_loop_handle,
|
state3.clone(),
|
||||||
monero_wallet.clone(),
|
&mut event_loop_handle,
|
||||||
)
|
monero_wallet.clone(),
|
||||||
.await?;
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
run_until(
|
run_until(
|
||||||
AliceState::XmrLocked { state3 },
|
AliceState::XmrLocked { state3 },
|
||||||
is_target_state,
|
is_target_state,
|
||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
config,
|
config,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
None => {
|
||||||
|
tracing::info!("Cannot resume swap from BTC locked state, aborting");
|
||||||
|
|
||||||
|
// Alice did not lock Xmr yet
|
||||||
|
swap(
|
||||||
|
AliceState::SafelyAborted,
|
||||||
|
event_loop_handle,
|
||||||
|
bitcoin_wallet,
|
||||||
|
monero_wallet,
|
||||||
|
config,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
},
|
||||||
AliceState::XmrLocked { state3 } => {
|
AliceState::XmrLocked { state3 } => {
|
||||||
// todo: match statement and wait for t1 can probably be expressed more cleanly
|
// todo: match statement and wait for t1 can probably be expressed more cleanly
|
||||||
match state3.current_epoch(bitcoin_wallet.as_ref()).await? {
|
match state3.current_epoch(bitcoin_wallet.as_ref()).await? {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user