Skip to content

Commit

Permalink
Expose UTXO spent for anchor and HTLC input descriptors
Browse files Browse the repository at this point in the history
This may be required by some wallets that rely on PSBTs internally to
create/sign transactions.
  • Loading branch information
wpaulino committed Jul 5, 2023
1 parent 30d46a9 commit 04e916f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lightning/src/events/bump_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use core::ops::Deref;
use crate::chain::chaininterface::BroadcasterInterface;
use crate::chain::ClaimId;
use crate::io_extras::sink;
use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI;
use crate::ln::chan_utils;
use crate::ln::chan_utils::{
ANCHOR_INPUT_WITNESS_WEIGHT, HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT,
Expand Down Expand Up @@ -74,6 +75,15 @@ pub struct AnchorDescriptor {
}

impl AnchorDescriptor {
/// Returns the UTXO to be spent by the anchor input, which can be obtained via
/// [`Self::unsigned_tx_input`].
pub fn spending_utxo(&self) -> TxOut {
TxOut {
script_pubkey: self.witness_script().to_v0_p2wsh(),
value: ANCHOR_OUTPUT_VALUE_SATOSHI,
}
}

/// Returns the unsigned transaction input spending the anchor output in the commitment
/// transaction.
pub fn unsigned_tx_input(&self) -> TxIn {
Expand Down Expand Up @@ -134,6 +144,15 @@ pub struct HTLCDescriptor {
}

impl HTLCDescriptor {
/// Returns the UTXO to be spent by the HTLC input, which can be obtained via
/// [`Self::unsigned_tx_input`].
pub fn spending_utxo<C: secp256k1::Signing + secp256k1::Verification>(&self, secp: &Secp256k1<C>) -> TxOut {
TxOut {
script_pubkey: self.witness_script(secp).to_v0_p2wsh(),
value: self.htlc.amount_msat / 1000,
}
}

/// Returns the unsigned transaction input spending the HTLC output in the commitment
/// transaction.
pub fn unsigned_tx_input(&self) -> TxIn {
Expand Down

0 comments on commit 04e916f

Please sign in to comment.