Unify logging of broadcasted transactions

We eliminate unnecessary layers of indirection for broadcasting logic
and force our callers to provide us with the `kind` of transaction
that we are publishing.

Eventually, we can replace this string with some type-system magic
we can derive the name from the actual transaction. For now, we just
require the caller to duplicate this information because it is faster
and good enough TM.
This commit is contained in:
Thomas Eizinger 2021-03-02 12:29:11 +11:00
parent 3a503bf95f
commit 8c9b087e39
No known key found for this signature in database
GPG key ID: 651AC83A6C6C8B96
4 changed files with 44 additions and 66 deletions

View file

@ -25,7 +25,6 @@ use libp2p::PeerId;
use sha2::Sha256;
use std::sync::Arc;
use tokio::time::timeout;
use tracing::info;
// TODO(Franck): Use helper functions from xmr-btc instead of re-writing them
// here
@ -125,16 +124,6 @@ pub fn build_bitcoin_redeem_transaction(
Ok(tx)
}
pub async fn publish_bitcoin_redeem_transaction(
redeem_tx: bitcoin::Transaction,
bitcoin_wallet: Arc<bitcoin::Wallet>,
) -> Result<::bitcoin::Txid> {
info!("Attempting to publish bitcoin redeem txn");
let txid = bitcoin_wallet.broadcast(redeem_tx).await?;
Ok(txid)
}
pub async fn publish_cancel_transaction(
tx_lock: TxLock,
a: bitcoin::SecretKey,
@ -170,7 +159,7 @@ pub async fn publish_cancel_transaction(
.expect("sig_{a,b} to be valid signatures for tx_cancel");
// TODO(Franck): Error handling is delicate, why can't we broadcast?
bitcoin_wallet.broadcast(tx_cancel).await?;
bitcoin_wallet.broadcast(tx_cancel, "cancel").await?;
// TODO(Franck): Wait until transaction is mined and returned mined
// block height
@ -248,17 +237,3 @@ pub fn build_bitcoin_punish_transaction(
Ok(signed_tx_punish)
}
pub async fn publish_bitcoin_punish_transaction(
punish_tx: bitcoin::Transaction,
bitcoin_wallet: Arc<bitcoin::Wallet>,
execution_params: ExecutionParams,
) -> Result<bitcoin::Txid> {
let txid = bitcoin_wallet.broadcast(punish_tx).await?;
bitcoin_wallet
.wait_for_transaction_finality(txid, execution_params)
.await?;
Ok(txid)
}