Skip to content

Commit 3db4b95

Browse files
author
Antoine Riard
committed
Add get_anchor_script
This is a script builder to generate anchor output ones. They can be satisfied either by a signature for the committed funding pubkey or anyone after CSV delay expiration. This is used at anchor output addition while generating commitment transaction.
1 parent 8a7f214 commit 3db4b95

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,23 @@ pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u32, contest_del
550550
}
551551
}
552552

553+
/// Gets the witnessScript for an anchor output from the funding public key.
554+
/// The witness in the spending input must be:
555+
/// <BIP 143 funding_signature>
556+
/// After 10 blocks of confirmation, an alternative satisfying witness could be:
557+
/// <>
558+
#[inline]
559+
pub(crate) fn get_anchor_redeemscript(funding_pubkey: &PublicKey) -> Script {
560+
Builder::new().push_slice(&funding_pubkey.serialize()[..])
561+
.push_opcode(opcodes::all::OP_CHECKSIG)
562+
.push_opcode(opcodes::all::OP_IFDUP)
563+
.push_opcode(opcodes::all::OP_NOTIF)
564+
.push_int(16)
565+
.push_opcode(opcodes::all::OP_CSV)
566+
.push_opcode(opcodes::all::OP_ENDIF)
567+
.into_script()
568+
}
569+
553570
#[derive(Clone)]
554571
/// We use this to track holder commitment transactions and put off signing them until we are ready
555572
/// to broadcast. This class can be used inside a signer implementation to generate a signature

0 commit comments

Comments
 (0)