Move txid getter to PartiallySignedBitcoinTransaction

This commit is contained in:
Steve Myers 2022-04-22 14:10:00 -07:00
parent 4665c551dd
commit 11ba16ec1b
No known key found for this signature in database
GPG Key ID: 8105A46B22C2D051
2 changed files with 10 additions and 8 deletions

View File

@ -116,7 +116,7 @@ interface Blockchain {
[Throws=BdkError]
constructor(BlockchainConfig config);
[Throws=BdkError]
string broadcast([ByRef] PartiallySignedBitcoinTransaction psbt);
void broadcast([ByRef] PartiallySignedBitcoinTransaction psbt);
};
callback interface Progress {
@ -143,6 +143,7 @@ interface PartiallySignedBitcoinTransaction {
[Throws=BdkError]
constructor(string psbt_base64);
string serialize();
string txid();
};
interface TxBuilder {

View File

@ -133,12 +133,9 @@ impl Blockchain {
self.blockchain_mutex.lock().expect("blockchain")
}
fn broadcast(&self, psbt: &PartiallySignedBitcoinTransaction) -> Result<String, Error> {
fn broadcast(&self, psbt: &PartiallySignedBitcoinTransaction) -> Result<(), Error> {
let tx = psbt.internal.lock().unwrap().clone().extract_tx();
self.get_blockchain().broadcast(&tx)?;
// TODO move txid getter to PartiallySignedBitcoinTransaction
let txid = tx.txid();
Ok(txid.to_hex())
self.get_blockchain().broadcast(&tx)
}
}
@ -184,6 +181,12 @@ impl PartiallySignedBitcoinTransaction {
let psbt = self.internal.lock().unwrap().clone();
psbt.to_string()
}
fn txid(&self) -> String {
let tx = self.internal.lock().unwrap().clone().extract_tx();
let txid = tx.txid();
txid.to_hex()
}
}
impl Wallet {
@ -220,8 +223,6 @@ impl Wallet {
&self,
blockchain: &Blockchain,
progress: Option<Box<dyn Progress>>,
//progress_update: Box<dyn BdkProgress>,
//max_address_param: Option<u32>,
) -> Result<(), BdkError> {
let bdk_sync_opts = BdkSyncOptions {
progress: progress.map(|p| {