Experimenting with two-party PSBT signing.

This commit is contained in:
Dave Hrycyszyn
2024-07-25 12:34:26 +01:00
parent 09c10b8d45
commit 62a8a7020c
2 changed files with 84 additions and 25 deletions

View File

@@ -39,17 +39,45 @@ impl EsploraWallet {
recipient: Address,
amount: Amount,
) -> Result<bitcoin::Transaction, anyhow::Error> {
let mut tx_builder = self.wallet.build_tx();
let mut tx_builder = self.build_tx()?;
tx_builder
.add_recipient(recipient.script_pubkey(), amount)
.enable_rbf();
let mut psbt = tx_builder.finish()?;
let finalized = self.wallet.sign(&mut psbt, SignOptions::default())?;
assert!(finalized);
let tx = psbt.extract_tx()?;
let tx = self.sign(&mut psbt, true)?.extract_tx()?;
Ok(tx)
}
pub(crate) fn build_tx(
&mut self,
) -> Result<
bdk_wallet::TxBuilder<bdk_wallet::wallet::coin_selection::BranchAndBoundCoinSelection>,
anyhow::Error,
> {
Ok(self.wallet.build_tx())
}
pub(crate) fn sign(
&self,
psbt: &mut bitcoin::Psbt,
finalize: bool,
) -> Result<bitcoin::Psbt, anyhow::Error> {
tracing::info!("{} signing PSBT", self.name);
let options = SignOptions {
try_finalize: finalize,
..Default::default()
};
let finalized = self.wallet.sign(psbt, options)?;
// make sure the PSBT is finalized if we asked for it
if finalize {
assert!(finalized)
}
Ok(psbt.to_owned())
}
/// Syncs the wallet with the latest state of the Bitcoin blockchain
pub(crate) async fn sync(&mut self) -> Result<(), anyhow::Error> {
tracing::info!("{} full scan sync start", self.name);
@@ -105,6 +133,10 @@ impl EsploraWallet {
);
self.client.broadcast(tx).await
}
pub(crate) fn wallet(&mut self) -> &Wallet {
&self.wallet
}
}
/// Creates a Bitcoin descriptor wallet with the mnemonic in the given user directory.