Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_fee_estimates to EsploraClient #648

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading