Skip to content

Commit 4c7883c

Browse files
committed
Expose previous UTXO for anchor and HTLC inputs
This may be required by some wallets that rely on PSBTs internally to create/sign transactions.
1 parent 0dbfe24 commit 4c7883c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lightning/src/events/bump_transaction.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use core::ops::Deref;
1818
use crate::chain::chaininterface::BroadcasterInterface;
1919
use crate::chain::ClaimId;
2020
use crate::io_extras::sink;
21+
use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI;
2122
use crate::ln::chan_utils;
2223
use crate::ln::chan_utils::{
2324
ANCHOR_INPUT_WITNESS_WEIGHT, HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT,
@@ -76,6 +77,15 @@ pub struct AnchorDescriptor {
7677
}
7778

7879
impl AnchorDescriptor {
80+
/// Returns the UTXO to be spent by the anchor input, which can be obtained via
81+
/// [`Self::unsigned_tx_input`].
82+
pub fn previous_utxo(&self) -> TxOut {
83+
TxOut {
84+
script_pubkey: self.witness_script().to_v0_p2wsh(),
85+
value: ANCHOR_OUTPUT_VALUE_SATOSHI,
86+
}
87+
}
88+
7989
/// Returns the unsigned transaction input spending the anchor output in the commitment
8090
/// transaction.
8191
pub fn unsigned_tx_input(&self) -> TxIn {
@@ -139,6 +149,15 @@ pub struct HTLCDescriptor {
139149
}
140150

141151
impl HTLCDescriptor {
152+
/// Returns the UTXO to be spent by the HTLC input, which can be obtained via
153+
/// [`Self::unsigned_tx_input`].
154+
pub fn previous_utxo<C: secp256k1::Signing + secp256k1::Verification>(&self, secp: &Secp256k1<C>) -> TxOut {
155+
TxOut {
156+
script_pubkey: self.witness_script(secp).to_v0_p2wsh(),
157+
value: self.htlc.amount_msat / 1000,
158+
}
159+
}
160+
142161
/// Returns the unsigned transaction input spending the HTLC output in the commitment
143162
/// transaction.
144163
pub fn unsigned_tx_input(&self) -> TxIn {
@@ -325,6 +344,8 @@ pub enum BumpTransactionEvent {
325344
pub struct Input {
326345
/// The unique identifier of the input.
327346
pub outpoint: OutPoint,
347+
/// The UTXO being spent by the input.
348+
pub previous_utxo: TxOut,
328349
/// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and
329350
/// [`TxIn::witness`], each with their lengths included, required to satisfy the output's
330351
/// script.
@@ -664,6 +685,7 @@ where
664685
) -> Result<Transaction, ()> {
665686
let must_spend = vec![Input {
666687
outpoint: anchor_descriptor.outpoint,
688+
previous_utxo: anchor_descriptor.previous_utxo(),
667689
satisfaction_weight: commitment_tx.weight() as u64 + ANCHOR_INPUT_WITNESS_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT,
668690
}];
669691
let coin_selection = self.utxo_source.select_confirmed_utxos(
@@ -730,6 +752,7 @@ where
730752
let htlc_input = htlc_descriptor.unsigned_tx_input();
731753
must_spend.push(Input {
732754
outpoint: htlc_input.previous_output.clone(),
755+
previous_utxo: htlc_descriptor.previous_utxo(&self.secp),
733756
satisfaction_weight: EMPTY_SCRIPT_SIG_WEIGHT + if htlc_descriptor.preimage.is_some() {
734757
HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT
735758
} else {

0 commit comments

Comments
 (0)