From abe85a1f44ee7a08e645445c823cbaef56e6ef41 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Tue, 11 Oct 2022 14:46:24 -0400 Subject: [PATCH] Add public helper to build anchor input witnesses --- lightning/src/ln/chan_utils.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index 13b632e7b..15bc0d0e2 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -736,6 +736,14 @@ pub(crate) fn get_anchor_output<'a>(commitment_tx: &'a Transaction, funding_pubk .map(|(idx, txout)| (idx as u32, txout)) } +/// Returns the witness required to satisfy and spend an anchor input. +pub fn build_anchor_input_witness(funding_key: &PublicKey, funding_sig: &Signature) -> Witness { + let anchor_redeem_script = chan_utils::get_anchor_redeemscript(funding_key); + let mut funding_sig = funding_sig.serialize_der().to_vec(); + funding_sig.push(EcdsaSighashType::All as u8); + Witness::from_vec(vec![funding_sig, anchor_redeem_script.to_bytes()]) +} + /// Per-channel data used to build transactions in conjunction with the per-commitment data (CommitmentTransaction). /// The fields are organized by holder/counterparty. /// -- 2.39.5