Fail the swap early if Bitcoin TxLock is never published

This helps distinguish between the case where the refund timelock is
reached before the bitcoin is locked and the case where the refund
timelock is reached after the bitcoin is locked and before Alice sends
over the transfer proof for locking up the monero. In the first case
we can abort without doing anything, but in the second case we must
instruct the caller to refund the bitcoin.
This commit is contained in:
Lucas Soriano del Pino 2020-10-16 11:25:41 +11:00
parent 9f1bf72c7b
commit 7d307e581a

View File

@ -145,6 +145,8 @@ where
Gen::new_boxed(|co| async move {
let swap_result: Result<(), SwapFailed> = async {
let btc_has_expired = bitcoin_time_is_gte(bitcoin_ledger, refund_timelock).shared();
let poll_until_btc_has_expired = poll_until(btc_has_expired.clone()).shared();
futures::pin_mut!(poll_until_btc_has_expired);
if btc_has_expired.clone().await {
return Err(SwapFailed::BeforeBtcLock);
@ -152,8 +154,15 @@ where
co.yield_(Action::LockBitcoin(tx_lock.clone())).await;
let poll_until_btc_has_expired = poll_until(btc_has_expired).shared();
futures::pin_mut!(poll_until_btc_has_expired);
match select(
bitcoin_ledger.watch_for_raw_transaction(tx_lock.txid()),
poll_until_btc_has_expired.clone(),
)
.await
{
Either::Left(_) => {}
Either::Right(_) => return Err(SwapFailed::BeforeBtcLock),
}
let transfer_proof = match select(
network.receive_transfer_proof(),