From c004c8593cdbeef9899f04d9a8e090f2ea1747a2 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 7 Jan 2025 18:26:58 -0600 Subject: [PATCH] feat: add get_fee_estimates to EsploraClient --- bdk-ffi/src/bdk.udl | 23 +++++++++++++++++++++++ bdk-ffi/src/esplora.rs | 6 +++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index e90e27dc..747b0868 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -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 get_fee_estimates(); }; // ------------------------------------------------------------------------ diff --git a/bdk-ffi/src/esplora.rs b/bdk-ffi/src/esplora.rs index 52338979..808d96ae 100644 --- a/bdk-ffi/src/esplora.rs +++ b/bdk-ffi/src/esplora.rs @@ -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; @@ -93,4 +93,8 @@ impl EsploraClient { pub fn get_height(&self) -> Result { self.0.get_height().map_err(EsploraError::from) } + + pub fn get_fee_estimates(&self) -> Result, EsploraError> { + self.0.get_fee_estimates().map_err(EsploraError::from) + } }