Skip to content

Commit

Permalink
feat: add broadcast method on electrum client
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed May 15, 2024
1 parent c2fd789 commit d99ad17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ interface ElectrumClient {

[Throws=ElectrumClientError]
Update sync(SyncRequest sync_request, u64 batch_size, boolean fetch_prev_txouts);

[Throws=ElectrumClientError]
string broadcast([ByRef] Transaction transaction);
};

// ------------------------------------------------------------------------
Expand Down
12 changes: 11 additions & 1 deletion bdk-ffi/src/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ use crate::types::{FullScanRequest, SyncRequest};
use crate::wallet::Update;
use std::collections::BTreeMap;

use bdk::bitcoin::Transaction as BdkTransaction;
use bdk::chain::spk_client::FullScanRequest as BdkFullScanRequest;
use bdk::chain::spk_client::FullScanResult as BdkFullScanResult;
use bdk::chain::spk_client::SyncRequest as BdkSyncRequest;
use bdk::chain::spk_client::SyncResult as BdkSyncResult;
use bdk::KeychainKind;
use bdk_electrum::electrum_client::Client as BdkBlockingClient;
use bdk_electrum::electrum_client::{Client as BdkBlockingClient, ElectrumApi};
use bdk_electrum::{ElectrumExt, ElectrumFullScanResult, ElectrumSyncResult};

use crate::bitcoin::Transaction;
use std::sync::Arc;

pub struct ElectrumClient(BdkBlockingClient);
Expand Down Expand Up @@ -82,4 +84,12 @@ impl ElectrumClient {

Ok(Arc::new(Update(update)))
}

pub fn broadcast(&self, transaction: &Transaction) -> Result<String, ElectrumClientError> {
let bdk_transaction: BdkTransaction = transaction.into();
self.0
.transaction_broadcast(&bdk_transaction)
.map_err(ElectrumClientError::from)
.map(|txid| txid.to_string())
}
}

0 comments on commit d99ad17

Please sign in to comment.