Skip to content

Commit cd9b71c

Browse files
committed
feat(kyoto): add avg feerate and connect
Users may want to add a `Peer` while the node is running, perhaps after the user updates a list. This is easily done. Developers that are working on desktop or even server platforms may have less strict bandwidth requirements than in the mobile case. These users could make use of fetching the average fee rate for a block, which could be used in some cases to fall-back or roughly estimate fee rates with.
1 parent 49c1635 commit cd9b71c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

bdk-ffi/src/kyoto.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::time::Duration;
2323

2424
use tokio::sync::Mutex;
2525

26+
use crate::bitcoin::BlockHash;
2627
use crate::bitcoin::Transaction;
2728
use crate::error::{CbfBuilderError, CbfError};
2829
use crate::types::Update;
@@ -340,6 +341,27 @@ impl CbfClient {
340341
.map(|fee| Arc::new(FeeRate(fee)))
341342
}
342343

344+
/// Fetch the average fee rate for a block by requesting it from a peer. Not recommend for
345+
/// resource-limited devices.
346+
pub async fn average_fee_rate(
347+
&self,
348+
blockhash: Arc<BlockHash>,
349+
) -> Result<Arc<FeeRate>, CbfError> {
350+
let fee_rate = self
351+
.sender
352+
.average_fee_rate(blockhash.0)
353+
.await
354+
.map_err(|_| CbfError::NodeStopped)?;
355+
Ok(Arc::new(fee_rate.into()))
356+
}
357+
358+
/// Add another [`Peer`] to attempt a connection with.
359+
pub fn connect(&self, peer: Peer) -> Result<(), CbfError> {
360+
self.sender
361+
.add_peer(peer)
362+
.map_err(|_| CbfError::NodeStopped)
363+
}
364+
343365
/// Query a Bitcoin DNS seeder using the configured resolver.
344366
///
345367
/// This is **not** a generic DNS implementation. Host names are prefixed with a `x849` to filter

0 commit comments

Comments
 (0)