149: Fix Alice redeem scenario r=da-kami a=da-kami

Follow up of #144, partial fix of https://github.com/comit-network/xmr-btc-swap/issues/137

 Fix Alice redeem scenario

- Properly check the timelocks before trying to redeem
- Distinguish different failure scenarios and reactions to it.
    - if we fail to construct the redeem transaction: wait for cancel.
    - if we fail to publish the redeem transaction: wait for cancel but let the user know that restarting the application will result in retrying to publish the tx.
    - if we succeed to publish the tx but then fail when waiting for finality, print error to the user (secreat already leaked, the user has to check manually if the tx was included)



Co-authored-by: Daniel Karzel <daniel@comit.network>
This commit is contained in:
bors[bot] 2021-01-21 06:27:38 +00:00 committed by GitHub
commit 4e858197c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 51 deletions

View file

@ -186,19 +186,16 @@ pub fn build_bitcoin_redeem_transaction(
pub async fn publish_bitcoin_redeem_transaction<W>(
redeem_tx: bitcoin::Transaction,
bitcoin_wallet: Arc<W>,
config: Config,
) -> Result<()>
) -> Result<::bitcoin::Txid>
where
W: BroadcastSignedTransaction + WaitForTransactionFinality,
{
info!("Attempting to publish bitcoin redeem txn");
let tx_id = bitcoin_wallet
let txid = bitcoin_wallet
.broadcast_signed_transaction(redeem_tx)
.await?;
bitcoin_wallet
.wait_for_transaction_finality(tx_id, config)
.await
Ok(txid)
}
pub async fn publish_cancel_transaction<W>(