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

@ -147,14 +147,20 @@ impl Wallet {
self.inner.lock().await.network()
}
pub async fn broadcast(&self, transaction: Transaction) -> Result<Txid> {
/// Broadcast the given transaction to the network and emit a log statement
/// if done so successfully.
pub async fn broadcast(&self, transaction: Transaction, kind: &str) -> Result<Txid> {
let txid = transaction.txid();
self.inner
.lock()
.await
.broadcast(transaction)
.with_context(|| format!("failed to broadcast transaction {}", txid))?;
.with_context(|| {
format!("failed to broadcast Bitcoin {} transaction {}", kind, txid)
})?;
tracing::info!("Published Bitcoin {} transaction as {}", txid, kind);
Ok(txid)
}