Skip to content

Commit

Permalink
feat: add ElectrumClient::server_features method
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Dec 18, 2024
1 parent 10c4d25 commit b8b5a0a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

// ------------------------------------------------------------------------
Expand Down
33 changes: 33 additions & 0 deletions bdk-ffi/src/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -93,4 +96,34 @@ impl ElectrumClient {
.map_err(ElectrumError::from)
.map(|txid| txid.to_string())
}

pub fn server_features(&self) -> Result<ServerFeaturesRes, ElectrumError> {
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<String>,
pub pruning: Option<i64>,
}

impl From<BdkServerFeaturesRes> 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,
}
}
}
1 change: 1 addition & 0 deletions bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b8b5a0a

Please sign in to comment.