Skip to content

Commit

Permalink
feat: add get_fee_estimates to EsploraClient
Browse files Browse the repository at this point in the history
  • Loading branch information
reez committed Jan 10, 2025
1 parent cdac6b4 commit da9027e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
23 changes: 23 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -1031,23 +1031,46 @@ interface Descriptor {
// bdk_esplora crate
// ------------------------------------------------------------------------

/// Wrapper around an esplora_client::BlockingClient which includes an internal in-memory transaction
/// cache to avoid re-fetching already downloaded transactions.
interface EsploraClient {
/// Creates a new bdk client from a esplora_client::BlockingClient
constructor(string url);

/// Scan keychain scripts for transactions against Esplora, returning an update that can be
/// applied to the receiving structures.
///
/// `request` provides the data required to perform a script-pubkey-based full scan
/// (see [`FullScanRequest`]). The full scan for each keychain (`K`) stops after a gap of
/// `stop_gap` script pubkeys with no associated transactions. `parallel_requests` specifies
/// the maximum number of HTTP requests to make in parallel.
[Throws=EsploraError]
Update full_scan(FullScanRequest request, u64 stop_gap, u64 parallel_requests);

/// Sync a set of scripts, txids, and/or outpoints against Esplora.
///
/// `request` provides the data required to perform a script-pubkey-based sync (see
/// [`SyncRequest`]). `parallel_requests` specifies the maximum number of HTTP requests to make
/// in parallel.
[Throws=EsploraError]
Update sync(SyncRequest request, u64 parallel_requests);

/// Broadcast a [`Transaction`] to Esplora.
[Throws=EsploraError]
void broadcast([ByRef] Transaction transaction);

/// Get a [`Transaction`] option given its [`Txid`].
[Throws=EsploraError]
Transaction? get_tx(string txid);

/// Get the height of the current blockchain tip.
[Throws=EsploraError]
u32 get_height();

/// Get a map where the key is the confirmation target (in number of
/// blocks) and the value is the estimated feerate (in sat/vB).
[Throws=EsploraError]
record<u16, f64> get_fee_estimates();
};

// ------------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion bdk-ffi/src/esplora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use bdk_wallet::chain::spk_client::SyncResponse as BdkSyncResponse;
use bdk_wallet::KeychainKind;
use bdk_wallet::Update as BdkUpdate;

use std::collections::BTreeMap;
use std::collections::{BTreeMap, HashMap};
use std::str::FromStr;
use std::sync::Arc;

Expand Down Expand Up @@ -93,4 +93,8 @@ impl EsploraClient {
pub fn get_height(&self) -> Result<u32, EsploraError> {
self.0.get_height().map_err(EsploraError::from)
}

pub fn get_fee_estimates(&self) -> Result<HashMap<u16, f64>, EsploraError> {
self.0.get_fee_estimates().map_err(EsploraError::from)
}
}

0 comments on commit da9027e

Please sign in to comment.