use crate::bitcoin::driver; use bdk::wallet::AddressIndex; use bdk::SignOptions; pub(crate) async fn run() -> anyhow::Result<()> { tracing::info!("starting htlc flow"); let (dave, sammy) = driver::setup().await?; // format a new commitment transaction like in Lightning let mut commitment_builder = dave.wallet.build_tx(); let amount = 500; let recipient = sammy.wallet.get_address(AddressIndex::New)?.script_pubkey(); commitment_builder.add_recipient(recipient, amount); commitment_builder.enable_rbf(); let (psbt, _) = commitment_builder .finish() .expect("unable to build commitment"); // sign the commitment transaction let mut dave_psbt = dave.sign(&mut psbt.clone(), false)?; let sammy_psbt = sammy.sign(&mut psbt.clone(), false)?; dave_psbt .combine(sammy_psbt) .expect("problem combining bitcoin PSBTs"); // these guys love mutability let finalized = dave .wallet .finalize_psbt(&mut dave_psbt, SignOptions::default()) .expect("couldn't finalize"); assert!(finalized); let tx = dave_psbt.extract_tx(); let _ = dave.broadcast(&tx)?; let _ = sammy.sync(); let _ = sammy.wallet.get_balance(); Ok(()) }