Introduce Watchable abstraction for Bitcoin wallet

We have a repeated pattern where we construct one of our
Tx{Cancel,Redeem,Punish,Refund,Lock} transactions and wait until
the status of this transaction changes. We can make this more
ergonomic by creating and implementing a `Watchable` trait that
gives access to the TxId and relevant script for this transaction.
This allows us to remove a parameter from the `watch_until_status`
function.

Additionally, there is a 2nd pattern: "Completing" one of these
transaction and waiting until they are confirmed with the configured
number of blocks for finality. We can make this more ergonomic by
returning a future from `broadcast` that callers can await in case
they want to wait for the broadcasted transaction to reach finality.
This commit is contained in:
Thomas Eizinger 2021-03-16 19:11:14 +11:00
parent a0830f099f
commit 273cf15631
No known key found for this signature in database
GPG key ID: 651AC83A6C6C8B96
11 changed files with 204 additions and 152 deletions

View file

@ -104,12 +104,10 @@ async fn run_until_internal(
.sign_and_finalize(tx_lock.clone().into())
.await
.context("Failed to sign Bitcoin lock transaction")?;
let tx_lock_id = bitcoin_wallet.broadcast(signed_tx, "lock").await?;
let (..) = bitcoin_wallet.broadcast(signed_tx, "lock").await?;
bitcoin_wallet
.watch_until_status(tx_lock_id, tx_lock.script_pubkey(), |status| {
status.is_confirmed()
})
.watch_until_status(&tx_lock, |status| status.is_confirmed())
.await?;
let state = BobState::BtcLocked(state3);