Skip to content

Commit 30d46a9

Browse files
committed
Add transaction-related helpers to AnchorDescriptor
1 parent 458bde0 commit 30d46a9

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

lightning/src/events/bump_transaction.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,30 @@ pub struct AnchorDescriptor {
7474
}
7575

7676
impl AnchorDescriptor {
77+
/// Returns the unsigned transaction input spending the anchor output in the commitment
78+
/// transaction.
79+
pub fn unsigned_tx_input(&self) -> TxIn {
80+
TxIn {
81+
previous_output: self.outpoint.clone(),
82+
script_sig: Script::new(),
83+
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
84+
witness: Witness::new(),
85+
}
86+
}
87+
88+
/// Returns the witness script of the anchor output in the commitment transaction.
89+
pub fn witness_script(&self) -> Script {
90+
let channel_params = self.channel_derivation_parameters.transaction_parameters.as_holder_broadcastable();
91+
chan_utils::get_anchor_redeemscript(&channel_params.broadcaster_pubkeys().funding_pubkey)
92+
}
93+
94+
/// Returns the fully signed witness required to spend the anchor output in the commitment
95+
/// transaction.
96+
pub fn tx_input_witness(&self, signature: &Signature) -> Witness {
97+
let channel_params = self.channel_derivation_parameters.transaction_parameters.as_holder_broadcastable();
98+
chan_utils::build_anchor_input_witness(&channel_params.broadcaster_pubkeys().funding_pubkey, signature)
99+
}
100+
77101
/// Derives the channel signer required to sign the anchor input.
78102
pub fn derive_channel_signer<SP: Deref>(&self, signer_provider: &SP) -> <SP::Target as SignerProvider>::Signer
79103
where
@@ -643,12 +667,7 @@ where
643667
let mut tx = Transaction {
644668
version: 2,
645669
lock_time: PackedLockTime::ZERO, // TODO: Use next best height.
646-
input: vec![TxIn {
647-
previous_output: anchor_descriptor.outpoint,
648-
script_sig: Script::new(),
649-
sequence: Sequence::ZERO,
650-
witness: Witness::new(),
651-
}],
670+
input: vec![anchor_descriptor.unsigned_tx_input()],
652671
output: vec![],
653672
};
654673
self.process_coin_selection(&mut tx, coin_selection);
@@ -682,8 +701,7 @@ where
682701
self.utxo_source.sign_tx(&mut anchor_tx)?;
683702
let signer = anchor_descriptor.derive_channel_signer(&self.signer_provider);
684703
let anchor_sig = signer.sign_holder_anchor_input(&anchor_tx, 0, &self.secp)?;
685-
anchor_tx.input[0].witness =
686-
chan_utils::build_anchor_input_witness(&signer.pubkeys().funding_pubkey, &anchor_sig);
704+
anchor_tx.input[0].witness = anchor_descriptor.tx_input_witness(&anchor_sig);
687705

688706
self.broadcaster.broadcast_transactions(&[&commitment_tx, &anchor_tx]);
689707
Ok(())

0 commit comments

Comments
 (0)