]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add public helper to build anchor input witnesses
authorWilmer Paulino <wilmer.paulino@gmail.com>
Tue, 11 Oct 2022 18:46:24 +0000 (14:46 -0400)
committerWilmer Paulino <wilmer.paulino@gmail.com>
Tue, 18 Oct 2022 19:23:29 +0000 (12:23 -0700)
lightning/src/ln/chan_utils.rs

index 13b632e7b4685f04ae2aef9800a68347dea286d0..15bc0d0e23e08079751972f32d751a76dc4706d7 100644 (file)
@@ -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.
 ///