| Copyright | (c) 2025 Jared Tobin |
|---|---|
| License | MIT |
| Maintainer | Jared Tobin <jared@ppad.tech> |
| Safe Haskell | None |
| Language | Haskell2010 |
Lightning.Protocol.BOLT5.Spend
Description
Spending transaction construction for BOLT #5 on-chain transaction handling.
All functions produce unsigned SpendingTx values. The caller
is responsible for signing (using the sighash metadata
provided) and assembling final witnesses via bolt3 witness
constructors.
Synopsis
- spend_to_local :: OutPoint -> Satoshi -> RevocationPubkey -> ToSelfDelay -> LocalDelayedPubkey -> Script -> FeeratePerKw -> Maybe SpendingTx
- spend_htlc_timeout :: HTLCContext -> CommitmentKeys -> SpendingTx
- spend_htlc_success :: HTLCContext -> CommitmentKeys -> SpendingTx
- spend_htlc_output :: OutPoint -> Satoshi -> RevocationPubkey -> ToSelfDelay -> LocalDelayedPubkey -> Script -> FeeratePerKw -> Maybe SpendingTx
- spend_remote_htlc_timeout :: OutPoint -> Satoshi -> HTLC -> CommitmentKeys -> ChannelFeatures -> Script -> FeeratePerKw -> Maybe SpendingTx
- spend_remote_htlc_preimage :: OutPoint -> Satoshi -> HTLC -> CommitmentKeys -> ChannelFeatures -> Script -> FeeratePerKw -> Maybe SpendingTx
- spend_revoked_to_local :: OutPoint -> Satoshi -> RevocationPubkey -> ToSelfDelay -> LocalDelayedPubkey -> Script -> FeeratePerKw -> Maybe SpendingTx
- spend_revoked_htlc :: OutPoint -> Satoshi -> OutputType -> RevocationPubkey -> CommitmentKeys -> ChannelFeatures -> PaymentHash -> Script -> FeeratePerKw -> Maybe SpendingTx
- spend_revoked_htlc_output :: OutPoint -> Satoshi -> RevocationPubkey -> ToSelfDelay -> LocalDelayedPubkey -> Script -> FeeratePerKw -> Maybe SpendingTx
- spend_revoked_batch :: PenaltyContext -> Maybe SpendingTx
- spend_anchor_owner :: OutPoint -> Satoshi -> FundingPubkey -> Script -> SpendingTx
- spend_anchor_anyone :: OutPoint -> Satoshi -> FundingPubkey -> Script -> SpendingTx
Local commitment spends
Arguments
| :: OutPoint | Outpoint of the to_local output. |
| -> Satoshi | Value of the to_local output. |
| -> RevocationPubkey | |
| -> ToSelfDelay | |
| -> LocalDelayedPubkey | |
| -> Script | Destination scriptPubKey. |
| -> FeeratePerKw | |
| -> Maybe SpendingTx |
Spend the to_local output of our local commitment tx.
Requires waiting for the CSV delay (to_self_delay) before
broadcasting. The caller signs with the local delayed privkey
and uses to_local_witness_spend from bolt3.
Returns Nothing if the fee would exceed the output value.
The input nSequence is set to the to_self_delay value.
Arguments
| :: HTLCContext | |
| -> CommitmentKeys | Full commitment keys (needed for witness script). |
| -> SpendingTx |
Construct an HTLC-timeout second-stage transaction.
Used when we offered an HTLC on our local commitment and it
has timed out. The bolt3 build_htlc_timeout_tx function
constructs the HTLC-timeout tx; this wraps it as a
SpendingTx with the witness script and sighash metadata.
Arguments
| :: HTLCContext | |
| -> CommitmentKeys | Full commitment keys (needed for witness script). |
| -> SpendingTx |
Construct an HTLC-success second-stage transaction.
Used when we received an HTLC on our local commitment and
have the preimage. The bolt3 build_htlc_success_tx function
constructs the HTLC-success tx; this wraps it as a
SpendingTx.
Arguments
| :: OutPoint | Outpoint of the second-stage output. |
| -> Satoshi | Value of the second-stage output. |
| -> RevocationPubkey | |
| -> ToSelfDelay | |
| -> LocalDelayedPubkey | |
| -> Script | Destination scriptPubKey. |
| -> FeeratePerKw | |
| -> Maybe SpendingTx |
Spend a second-stage HTLC output (HTLC-timeout or HTLC-success output) after the CSV delay.
The output of an HTLC-timeout or HTLC-success tx uses the
same to_local script. The caller signs with the local
delayed privkey and uses htlc_output_witness_spend.
Returns Nothing if the fee would exceed the output value.
Remote commitment spends
spend_remote_htlc_timeout Source #
Arguments
| :: OutPoint | Outpoint of the HTLC output. |
| -> Satoshi | Value of the HTLC output. |
| -> HTLC | The HTLC being spent. |
| -> CommitmentKeys | Keys for the remote commitment. |
| -> ChannelFeatures | |
| -> Script | Destination scriptPubKey. |
| -> FeeratePerKw | |
| -> Maybe SpendingTx |
Spend an offered HTLC directly after timeout on the remote commitment.
On the remote commitment, their received HTLCs (our offered) have timed out and we can sweep them directly.
Returns Nothing if the fee would exceed the output value.
spend_remote_htlc_preimage Source #
Arguments
| :: OutPoint | Outpoint of the HTLC output. |
| -> Satoshi | Value of the HTLC output. |
| -> HTLC | The HTLC being spent. |
| -> CommitmentKeys | Keys for the remote commitment. |
| -> ChannelFeatures | |
| -> Script | Destination scriptPubKey. |
| -> FeeratePerKw | |
| -> Maybe SpendingTx |
Spend a received HTLC directly with preimage on the remote commitment.
On the remote commitment, their offered HTLCs (our received) can be claimed with the payment preimage.
Returns Nothing if the fee would exceed the output value.
Revoked commitment spends
spend_revoked_to_local Source #
Arguments
| :: OutPoint | Outpoint of the to_local output. |
| -> Satoshi | Value of the to_local output. |
| -> RevocationPubkey | |
| -> ToSelfDelay | |
| -> LocalDelayedPubkey | |
| -> Script | Destination scriptPubKey. |
| -> FeeratePerKw | |
| -> Maybe SpendingTx |
Spend a revoked to_local output using the revocation key.
The caller signs with the revocation privkey and uses
to_local_witness_revoke from bolt3.
Returns Nothing if the fee would exceed the output value.
Arguments
| :: OutPoint | Outpoint of the HTLC output. |
| -> Satoshi | Value of the HTLC output. |
| -> OutputType | Whether offered or received HTLC. |
| -> RevocationPubkey | |
| -> CommitmentKeys | |
| -> ChannelFeatures | |
| -> PaymentHash | |
| -> Script | Destination scriptPubKey. |
| -> FeeratePerKw | |
| -> Maybe SpendingTx |
Spend a revoked HTLC output using the revocation key.
The caller signs with the revocation privkey and uses
offered_htlc_witness_revoke or
received_htlc_witness_revoke from bolt3, depending on
the output type.
Returns Nothing if the output type is not an HTLC, or
if the fee would exceed the output value.
spend_revoked_htlc_output Source #
Arguments
| :: OutPoint | Outpoint of the second-stage output. |
| -> Satoshi | Value of the second-stage output. |
| -> RevocationPubkey | |
| -> ToSelfDelay | |
| -> LocalDelayedPubkey | |
| -> Script | Destination scriptPubKey. |
| -> FeeratePerKw | |
| -> Maybe SpendingTx |
Spend a revoked second-stage HTLC output (HTLC-timeout or HTLC-success output) using the revocation key.
The output of a revoked HTLC-timeout/success tx uses the
to_local script. The caller signs with the revocation privkey
and uses htlc_output_witness_revoke.
Returns Nothing if the fee would exceed the output value.
spend_revoked_batch :: PenaltyContext -> Maybe SpendingTx Source #
Construct a batched penalty transaction spending multiple revoked outputs.
Per BOLT #5, up to 483 bidirectional HTLCs plus to_local can
be resolved in a single penalty transaction (within the
400,000 weight limit). The caller signs each input with the
revocation privkey.
| Returns Nothing if the total fee would exceed the
total input value.
Anchor spends
Arguments
| :: OutPoint | Outpoint of the anchor output. |
| -> Satoshi | Value of the anchor output (330 sats). |
| -> FundingPubkey | |
| -> Script | Destination scriptPubKey. |
| -> SpendingTx |
Spend an anchor output as the owner (immediately).
The caller signs with the funding privkey and uses
anchor_witness_owner from bolt3.
Arguments
| :: OutPoint | Outpoint of the anchor output. |
| -> Satoshi | Value of the anchor output (330 sats). |
| -> FundingPubkey | |
| -> Script | Destination scriptPubKey. |
| -> SpendingTx |
Spend an anchor output as anyone (after 16 blocks).
Uses anchor_witness_anyone from bolt3 (empty signature).