From e3fc005aa7c8393b0be26bb57dfde1bc71dc3e0e Mon Sep 17 00:00:00 2001 From: Rob N Date: Tue, 10 Dec 2024 09:54:23 -1000 Subject: [PATCH] feat: add `broadcast_minimum` to `Client` --- examples/wallet.rs | 4 ++++ src/lib.rs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/examples/wallet.rs b/examples/wallet.rs index 2f298a6..2dcc7ca 100644 --- a/examples/wallet.rs +++ b/examples/wallet.rs @@ -66,6 +66,10 @@ async fn main() -> anyhow::Result<()> { tracing::info!("Local chain tip: {}", wallet.local_chain().tip().height()); let next = wallet.peek_address(KeychainKind::External, last_revealed + 1); tracing::info!("Next receiving address: {next}"); + tracing::info!( + "Broadcast minimum fee rate: {}", + receiver.broadcast_minimum() + ); } } } diff --git a/src/lib.rs b/src/lib.rs index 4aef450..d580357 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -168,6 +168,7 @@ use bdk_chain::{ }; use bdk_chain::{ConfirmationBlockTime, TxUpdate}; +pub use bdk_chain::bitcoin::FeeRate; pub use bdk_chain::local_chain::MissingGenesisError; pub extern crate kyoto; @@ -197,6 +198,8 @@ pub struct EventReceiver { chain: local_chain::LocalChain, // receive graph graph: IndexedTxGraph>, + // the network minimum to broadcast a transaction + min_broadcast_fee: FeeRate, } impl EventReceiver @@ -213,6 +216,7 @@ where receiver, chain: LocalChain::from_tip(cp)?, graph: IndexedTxGraph::new(index.clone()), + min_broadcast_fee: FeeRate::BROADCAST_MIN, }) } @@ -256,6 +260,11 @@ where }); break; } + NodeMessage::FeeFilter(fee_filter) => { + if self.min_broadcast_fee < fee_filter { + self.min_broadcast_fee = fee_filter; + } + } _ => (), } } @@ -379,11 +388,21 @@ where NodeMessage::TxBroadcastFailure(failure_payload) => { return Some(Event::TxFailed(failure_payload)); } + NodeMessage::FeeFilter(fee_filter) => { + if self.min_broadcast_fee < fee_filter { + self.min_broadcast_fee = fee_filter; + } + } _ => continue, } } None } + + /// The minimum fee required for a transaction to propagate to the connected peers. + pub fn broadcast_minimum(&self) -> FeeRate { + self.min_broadcast_fee + } } /// Handle dialog and state changes from a node with some arbitrary behavior.