Skip to content

Commit 87548dd

Browse files
committed
Add ChannelSigner::spend_holder_anchor_input
1 parent 3ee8429 commit 87548dd

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
@@ -964,6 +964,11 @@ pub trait ChannelSigner {
964964

965965
/// Get the counterparty anchor output of a commit tx
966966
fn get_counterparty_anchor_txout(&self, is_holder_tx: bool) -> Option<TxOut>;
967+
968+
/// Spend the holder anchor input
969+
fn spend_holder_anchor_input(
970+
&self, anchor_tx: &Transaction, input_idx: usize, secp_ctx: &Secp256k1<secp256k1::All>,
971+
) -> Result<Transaction, ()>;
967972
}
968973

969974
/// Specifies the recipient of an invoice.
@@ -1891,6 +1896,18 @@ impl ChannelSigner for InMemorySigner {
18911896
None
18921897
}
18931898
}
1899+
1900+
fn spend_holder_anchor_input(
1901+
&self, anchor_tx: &Transaction, input_idx: usize, secp_ctx: &Secp256k1<secp256k1::All>,
1902+
) -> Result<Transaction, ()> {
1903+
let anchor_sig =
1904+
EcdsaChannelSigner::sign_holder_anchor_input(self, anchor_tx, input_idx, secp_ctx)?;
1905+
let mut tx = anchor_tx.clone();
1906+
let funding_pubkey = self.pubkeys().funding_pubkey;
1907+
let witness = chan_utils::build_anchor_input_witness(&funding_pubkey, &anchor_sig);
1908+
tx.input[0].witness = witness;
1909+
Ok(tx)
1910+
}
18941911
}
18951912

18961913
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
@@ -365,6 +365,12 @@ impl ChannelSigner for TestChannelSigner {
365365
fn get_counterparty_anchor_txout(&self, is_holder_tx: bool) -> Option<TxOut> {
366366
self.inner.get_counterparty_anchor_txout(is_holder_tx)
367367
}
368+
369+
fn spend_holder_anchor_input(
370+
&self, anchor_tx: &Transaction, input_idx: usize, secp_ctx: &Secp256k1<secp256k1::All>,
371+
) -> Result<Transaction, ()> {
372+
self.inner.spend_holder_anchor_input(anchor_tx, input_idx, secp_ctx)
373+
}
368374
}
369375

370376
impl EcdsaChannelSigner for TestChannelSigner {

0 commit comments

Comments
 (0)