Skip to content

Commit c53ccf1

Browse files
Antoine Riarddevrandom
Antoine Riard
authored andcommitted
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 2ced708 commit c53ccf1

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
@@ -564,6 +564,23 @@ pub fn build_htlc_transaction(commitment_txid: &Txid, feerate_per_kw: u32, conte
564564
}
565565
}
566566

567+
/// Gets the witnessScript for an anchor output from the funding public key.
568+
/// The witness in the spending input must be:
569+
/// <BIP 143 funding_signature>
570+
/// After 10 blocks of confirmation, an alternative satisfying witness could be:
571+
/// <>
572+
#[inline]
573+
pub(crate) fn get_anchor_redeemscript(funding_pubkey: &PublicKey) -> Script {
574+
Builder::new().push_slice(&funding_pubkey.serialize()[..])
575+
.push_opcode(opcodes::all::OP_CHECKSIG)
576+
.push_opcode(opcodes::all::OP_IFDUP)
577+
.push_opcode(opcodes::all::OP_NOTIF)
578+
.push_int(16)
579+
.push_opcode(opcodes::all::OP_CSV)
580+
.push_opcode(opcodes::all::OP_ENDIF)
581+
.into_script()
582+
}
583+
567584
/// Per-channel data used to build transactions in conjunction with the per-commitment data (CommitmentTransaction).
568585
/// The fields are organized by holder/counterparty.
569586
///

0 commit comments

Comments
 (0)