Skip to content

Commit

Permalink
Merge pull request #76 from rustaceanrob/fee-filter-12-10
Browse files Browse the repository at this point in the history
Add `broadcast_minimum` to `Client`
  • Loading branch information
rustaceanrob committed Dec 11, 2024
2 parents ce16626 + e3fc005 commit 024faa8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bdk_kyoto"
version = "0.4.0"
version = "0.5.0"
authors = ["Rob <[email protected]>", "Bitcoin Dev Kit Developers"]
description = "BDK blockchain integration using P2P light client Kyoto"
license = "MIT OR Apache-2.0"
Expand Down
4 changes: 4 additions & 0 deletions examples/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
}
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -197,6 +198,8 @@ pub struct EventReceiver<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> EventReceiver<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 @@ -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.
Expand Down

0 comments on commit 024faa8

Please sign in to comment.