feat(electrum): re-export transaction_broadcast method

Also: update `wallet_electrum` example to use the method.
This commit is contained in:
志宇 2024-06-04 11:59:39 +08:00
parent 53fa35096f
commit 2d2656acfa
No known key found for this signature in database
GPG Key ID: F6345C9837C2BDE8
2 changed files with 9 additions and 2 deletions

View File

@ -65,6 +65,13 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
Ok(tx) Ok(tx)
} }
/// Broadcasts a transaction to the network.
///
/// This is a re-export of [`ElectrumApi::transaction_broadcast`].
pub fn transaction_broadcast(&self, tx: &Transaction) -> Result<Txid, Error> {
self.inner.transaction_broadcast(tx)
}
/// Full scan the keychain scripts specified with the blockchain (via an Electrum client) and /// Full scan the keychain scripts specified with the blockchain (via an Electrum client) and
/// returns updates for [`bdk_chain`] data structures. /// returns updates for [`bdk_chain`] data structures.
/// ///

View File

@ -6,7 +6,7 @@ const BATCH_SIZE: usize = 5;
use std::io::Write; use std::io::Write;
use std::str::FromStr; use std::str::FromStr;
use bdk_electrum::electrum_client::{self, ElectrumApi}; use bdk_electrum::electrum_client;
use bdk_electrum::BdkElectrumClient; use bdk_electrum::BdkElectrumClient;
use bdk_file_store::Store; use bdk_file_store::Store;
use bdk_wallet::bitcoin::{Address, Amount}; use bdk_wallet::bitcoin::{Address, Amount};
@ -93,7 +93,7 @@ fn main() -> Result<(), anyhow::Error> {
assert!(finalized); assert!(finalized);
let tx = psbt.extract_tx()?; let tx = psbt.extract_tx()?;
client.inner.transaction_broadcast(&tx)?; client.transaction_broadcast(&tx)?;
println!("Tx broadcasted! Txid: {}", tx.txid()); println!("Tx broadcasted! Txid: {}", tx.txid());
Ok(()) Ok(())