Skip to content

Commit 9aeb2bd

Browse files
committed
Add ChannelSigner::spend_holder_anchor_input
1 parent 687d07c commit 9aeb2bd

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lightning/src/events/bump_transaction.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,7 @@ where
687687
anchor_tx = self.utxo_source.sign_psbt(anchor_psbt)?;
688688

689689
let signer = anchor_descriptor.derive_channel_signer(&self.signer_provider);
690-
let anchor_sig = signer.sign_holder_anchor_input(&anchor_tx, 0, &self.secp)?;
691-
anchor_tx.input[0].witness = anchor_descriptor.tx_input_witness(&anchor_sig);
690+
anchor_tx = signer.spend_holder_anchor_input(&anchor_tx, 0, &self.secp)?;
692691

693692
#[cfg(debug_assertions)] {
694693
let signed_tx_weight = anchor_tx.weight().to_wu();

lightning/src/sign/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,11 @@ pub trait ChannelSigner {
959959

960960
/// Get the anchor output of a commit tx
961961
fn get_anchor_txout(&self, is_holder_tx: bool, is_broadcaster_anchor: bool) -> Option<TxOut>;
962+
963+
/// Spend the holder anchor input
964+
fn spend_holder_anchor_input(
965+
&self, anchor_tx: &Transaction, input_idx: usize, secp_ctx: &Secp256k1<secp256k1::All>,
966+
) -> Result<Transaction, ()>;
962967
}
963968

964969
/// Specifies the recipient of an invoice.
@@ -1834,6 +1839,18 @@ impl ChannelSigner for InMemorySigner {
18341839
None
18351840
}
18361841
}
1842+
1843+
fn spend_holder_anchor_input(
1844+
&self, anchor_tx: &Transaction, input_idx: usize, secp_ctx: &Secp256k1<secp256k1::All>,
1845+
) -> Result<Transaction, ()> {
1846+
let anchor_sig =
1847+
EcdsaChannelSigner::sign_holder_anchor_input(self, anchor_tx, input_idx, secp_ctx)?;
1848+
let mut tx = anchor_tx.clone();
1849+
let funding_pubkey = self.pubkeys().funding_pubkey;
1850+
let witness = chan_utils::build_anchor_input_witness(&funding_pubkey, &anchor_sig);
1851+
tx.input[input_idx].witness = witness;
1852+
Ok(tx)
1853+
}
18371854
}
18381855

18391856
const MISSING_PARAMS_ERR: &'static str =

lightning/src/util/test_channel_signer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,12 @@ impl ChannelSigner for TestChannelSigner {
347347
fn get_anchor_txout(&self, is_holder_tx: bool, is_broadcaster_anchor: bool) -> Option<TxOut> {
348348
self.inner.get_anchor_txout(is_holder_tx, is_broadcaster_anchor)
349349
}
350+
351+
fn spend_holder_anchor_input(
352+
&self, anchor_tx: &Transaction, input_idx: usize, secp_ctx: &Secp256k1<secp256k1::All>,
353+
) -> Result<Transaction, ()> {
354+
self.inner.spend_holder_anchor_input(anchor_tx, input_idx, secp_ctx)
355+
}
350356
}
351357

352358
impl EcdsaChannelSigner for TestChannelSigner {

0 commit comments

Comments
 (0)