HTLC broadcast working

This commit is contained in:
Dave Hrycyszyn
2024-07-29 10:03:02 +01:00
parent 918544a76b
commit e4eedbd206
4 changed files with 52 additions and 16 deletions

View File

@@ -1,15 +1,33 @@
use crate::bitcoin::driver;
use bdk::wallet::AddressIndex;
use crate::bitcoin::{self, driver};
use bdk::wallet::AddressIndex::New;
use bdk::SignOptions;
pub(crate) async fn run() -> anyhow::Result<()> {
tracing::info!("starting htlc flow");
let (dave, sammy) = driver::setup().await?;
tracing::info!("syncing dave wallet");
let _ = dave.sync();
tracing::info!("syncing samy wallet");
let _ = sammy.sync();
// 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();
let recipient = sammy.wallet.get_address(New)?.script_pubkey();
// Feed it 500 sats, a redeem identity, a hashlock, a refund timelock, and a refund identity
//
let htlc = bitcoin::htlc::Htlc::new(
amount,
dave.external_public_key,
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".to_string(),
100,
sammy.external_public_key,
);
let htlc_descriptor = htlc.to_miniscript_descriptor();
tracing::info!("descriptor: {}", htlc_descriptor);
commitment_builder.add_recipient(recipient, amount);
commitment_builder.enable_rbf();
let (psbt, _) = commitment_builder