Skip to content

Commit 04e916f

Browse files
committed
Expose UTXO spent for anchor and HTLC input descriptors
This may be required by some wallets that rely on PSBTs internally to create/sign transactions.
1 parent 30d46a9 commit 04e916f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lightning/src/events/bump_transaction.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use core::ops::Deref;
1616
use crate::chain::chaininterface::BroadcasterInterface;
1717
use crate::chain::ClaimId;
1818
use crate::io_extras::sink;
19+
use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI;
1920
use crate::ln::chan_utils;
2021
use crate::ln::chan_utils::{
2122
ANCHOR_INPUT_WITNESS_WEIGHT, HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT,
@@ -74,6 +75,15 @@ pub struct AnchorDescriptor {
7475
}
7576

7677
impl AnchorDescriptor {
78+
/// Returns the UTXO to be spent by the anchor input, which can be obtained via
79+
/// [`Self::unsigned_tx_input`].
80+
pub fn spending_utxo(&self) -> TxOut {
81+
TxOut {
82+
script_pubkey: self.witness_script().to_v0_p2wsh(),
83+
value: ANCHOR_OUTPUT_VALUE_SATOSHI,
84+
}
85+
}
86+
7787
/// Returns the unsigned transaction input spending the anchor output in the commitment
7888
/// transaction.
7989
pub fn unsigned_tx_input(&self) -> TxIn {
@@ -134,6 +144,15 @@ pub struct HTLCDescriptor {
134144
}
135145

136146
impl HTLCDescriptor {
147+
/// Returns the UTXO to be spent by the HTLC input, which can be obtained via
148+
/// [`Self::unsigned_tx_input`].
149+
pub fn spending_utxo<C: secp256k1::Signing + secp256k1::Verification>(&self, secp: &Secp256k1<C>) -> TxOut {
150+
TxOut {
151+
script_pubkey: self.witness_script(secp).to_v0_p2wsh(),
152+
value: self.htlc.amount_msat / 1000,
153+
}
154+
}
155+
137156
/// Returns the unsigned transaction input spending the HTLC output in the commitment
138157
/// transaction.
139158
pub fn unsigned_tx_input(&self) -> TxIn {

0 commit comments

Comments
 (0)