feat: add broadcast method on esplora blocking client

This commit is contained in:
thunderbiscuit
2023-11-17 13:25:33 -05:00
parent 26352edfbe
commit 15c1f19c96
10 changed files with 168 additions and 9 deletions

View File

@@ -221,6 +221,9 @@ interface EsploraClient {
[Throws=BdkError]
Update scan(Wallet wallet, u64 stop_gap, u64 parallel_requests);
[Throws=BdkError]
void broadcast(Transaction transaction);
};
// ------------------------------------------------------------------------

View File

@@ -209,6 +209,12 @@ impl From<BdkTransaction> for Transaction {
}
}
impl From<Transaction> for BdkTransaction {
fn from(tx: Transaction) -> Self {
tx.inner
}
}
pub struct PartiallySignedTransaction {
pub(crate) inner: Mutex<BdkPartiallySignedTransaction>,
}

View File

@@ -1,4 +1,5 @@
use crate::wallet::{Update, Wallet};
use std::ops::Deref;
use bdk::wallet::Update as BdkUpdate;
use bdk::Error as BdkError;
@@ -56,7 +57,12 @@ impl EsploraClient {
// pub fn sync();
// pub fn broadcast();
pub fn broadcast(&self, transaction: Arc<crate::bitcoin::Transaction>) -> Result<(), BdkError> {
let bdk_transaction: bdk::bitcoin::Transaction = transaction.deref().clone().into();
self.0
.broadcast(&bdk_transaction)
.map_err(|e| BdkError::Generic(e.to_string()))
}
// pub fn estimate_fee();
}

View File

@@ -7,8 +7,8 @@ use std::collections::HashSet;
use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
use bdk::bitcoin::OutPoint as BdkOutPoint;
use bdk::wallet::Update as BdkUpdate;
use bdk::{SignOptions, Wallet as BdkWallet};
use bdk::{Error as BdkError, FeeRate};
use bdk::{SignOptions, Wallet as BdkWallet};
use bdk::wallet::tx_builder::ChangeSpendPolicy;
use std::sync::{Arc, Mutex, MutexGuard};
@@ -88,10 +88,9 @@ impl Wallet {
// sign_options: Option<SignOptions>,
) -> Result<bool, BdkError> {
let mut psbt = psbt.inner.lock().unwrap();
self.get_wallet().sign(
&mut psbt,
SignOptions::default(),
).map_err(|e| BdkError::Generic(e.to_string()))
self.get_wallet()
.sign(&mut psbt, SignOptions::default())
.map_err(|e| BdkError::Generic(e.to_string()))
}
}