Have --force flag only override the timelock check

It might very well be that the cancel transaction is already published.
If that is the case, there is no point in failing the command. We simply
transition to cancel and exit normally.

The reason this comes up now is because Alice now properly waits for
the cancel timelock as well and publishes the cancel transaction first.

Ultimately, she should not do that because there is no benefit to her
unless she can also publish the punish transaction.
This commit is contained in:
Thomas Eizinger 2021-04-01 17:28:38 +11:00
parent 24f444b9f7
commit 1b2f476cae
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
2 changed files with 7 additions and 20 deletions

View File

@ -239,9 +239,6 @@ async fn main() -> Result<()> {
"The Cancel Transaction cannot be published yet, \
because the timelock has not expired. Please try again later."
),
Err(bob::cancel::Error::CancelTxAlreadyPublished) => {
warn!("The Cancel Transaction has already been published.")
}
}
}
Command::Refund {

View File

@ -9,8 +9,6 @@ use uuid::Uuid;
pub enum Error {
#[error("The cancel timelock has not expired yet.")]
CancelTimelockNotExpiredYet,
#[error("The cancel transaction has already been published.")]
CancelTxAlreadyPublished,
}
pub async fn cancel(
@ -48,23 +46,15 @@ pub async fn cancel(
if let ExpiredTimelocks::None = state6.expired_timelock(bitcoin_wallet.as_ref()).await? {
return Ok(Err(Error::CancelTimelockNotExpiredYet));
}
}
if state6
.check_for_tx_cancel(bitcoin_wallet.as_ref())
.await
.is_ok()
{
let txid = if let Ok(tx) = state6.check_for_tx_cancel(bitcoin_wallet.as_ref()).await {
tracing::debug!(%swap_id, "Cancel transaction has already been published");
let state = BobState::BtcCancelled(state6);
let db_state = state.into();
db.insert_latest_state(swap_id, Swap::Bob(db_state)).await?;
return Ok(Err(Error::CancelTxAlreadyPublished));
}
}
let txid = state6.submit_tx_cancel(bitcoin_wallet.as_ref()).await?;
tx.txid()
} else {
state6.submit_tx_cancel(bitcoin_wallet.as_ref()).await?
};
let state = BobState::BtcCancelled(state6);
let db_state = state.clone().into();