Skip to content

Commit

Permalink
feat: add broadcast_minimum to Client
Browse files Browse the repository at this point in the history
  • Loading branch information
rustaceanrob committed Dec 10, 2024
1 parent cdef1cf commit 6918258
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ 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: {}", client.broadcast_minimum());
}
}
}
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ use core::fmt;
use std::collections::BTreeMap;

use bdk_chain::{
bitcoin::FeeRate,
keychain_txout::KeychainTxOutIndex,
local_chain::{self, CheckPoint, LocalChain},
spk_client::FullScanResult,
Expand Down Expand Up @@ -195,6 +196,8 @@ pub struct Client<K> {
chain: local_chain::LocalChain,
// receive graph
graph: IndexedTxGraph<ConfirmationBlockTime, KeychainTxOutIndex<K>>,
// the network minimum to broadcast a transaction
min_broadcast_fee: FeeRate,
}

impl<K> Client<K>
Expand All @@ -213,6 +216,7 @@ where
receiver,
chain: LocalChain::from_tip(cp)?,
graph: IndexedTxGraph::new(index.clone()),
min_broadcast_fee: FeeRate::BROADCAST_MIN,
})
}

Expand Down Expand Up @@ -256,6 +260,11 @@ where
});
break;
}
NodeMessage::FeeFilter(fee_filter) => {
if self.min_broadcast_fee < fee_filter {
self.min_broadcast_fee = fee_filter;
}
}
_ => (),
}
}
Expand Down Expand Up @@ -377,6 +386,11 @@ 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,
}
}
Expand All @@ -397,6 +411,11 @@ where
.await
}

/// The minimum fee required for a transaction to propagate to the connected peers.
pub fn broadcast_minimum(&self) -> FeeRate {
self.min_broadcast_fee
}

/// Add more scripts to the node. For example, a user may reveal a Bitcoin address to receive a
/// payment, so this script should be added to the [`Node`].
///
Expand Down

0 comments on commit 6918258

Please sign in to comment.