diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 806d79e1..ba449102 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -1066,6 +1066,18 @@ interface ElectrumClient { [Throws=ElectrumError] string broadcast([ByRef] Transaction transaction); + + [Throws=ElectrumError] + ServerFeaturesRes server_features(); +}; + +dictionary ServerFeaturesRes { + string server_version; + string genesis_hash; + string protocol_min; + string protocol_max; + string? hash_function; + i64? pruning; }; // ------------------------------------------------------------------------ diff --git a/bdk-ffi/src/electrum.rs b/bdk-ffi/src/electrum.rs index c6b62582..40932044 100644 --- a/bdk-ffi/src/electrum.rs +++ b/bdk-ffi/src/electrum.rs @@ -7,11 +7,14 @@ use bdk_core::spk_client::FullScanRequest as BdkFullScanRequest; use bdk_core::spk_client::FullScanResponse as BdkFullScanResponse; use bdk_core::spk_client::SyncRequest as BdkSyncRequest; use bdk_core::spk_client::SyncResponse as BdkSyncResponse; +use bdk_electrum::electrum_client::ServerFeaturesRes as BdkServerFeaturesRes; use bdk_electrum::BdkElectrumClient as BdkBdkElectrumClient; use bdk_wallet::bitcoin::Transaction as BdkTransaction; use bdk_wallet::KeychainKind; use bdk_wallet::Update as BdkUpdate; +use bdk_core::bitcoin::hex::{Case, DisplayHex}; +use bdk_electrum::electrum_client::ElectrumApi; use std::collections::BTreeMap; use std::sync::Arc; @@ -93,4 +96,34 @@ impl ElectrumClient { .map_err(ElectrumError::from) .map(|txid| txid.to_string()) } + + pub fn server_features(&self) -> Result { + self.0 + .inner + .server_features() + .map_err(ElectrumError::from) + .map(ServerFeaturesRes::from) + } +} + +pub struct ServerFeaturesRes { + pub server_version: String, + pub genesis_hash: String, + pub protocol_min: String, + pub protocol_max: String, + pub hash_function: Option, + pub pruning: Option, +} + +impl From for ServerFeaturesRes { + fn from(value: BdkServerFeaturesRes) -> ServerFeaturesRes { + ServerFeaturesRes { + server_version: value.server_version, + genesis_hash: value.genesis_hash.to_hex_string(Case::Lower), + protocol_min: value.protocol_min, + protocol_max: value.protocol_max, + hash_function: value.hash_function, + pruning: value.pruning, + } + } } diff --git a/bdk-ffi/src/lib.rs b/bdk-ffi/src/lib.rs index 684d0fd0..9a2ef6c2 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -17,6 +17,7 @@ use crate::bitcoin::TxIn; use crate::bitcoin::TxOut; use crate::descriptor::Descriptor; use crate::electrum::ElectrumClient; +use crate::electrum::ServerFeaturesRes; use crate::error::AddressParseError; use crate::error::Bip32Error; use crate::error::Bip39Error;