| Copyright | (c) 2025 Jared Tobin |
|---|---|
| License | MIT |
| Maintainer | Jared Tobin <jared@ppad.tech> |
| Safe Haskell | None |
| Language | Haskell2010 |
Lightning.Protocol.BOLT5
Contents
Description
On-chain transaction handling for the Lightning Network, per BOLT #5.
This module implements the logic for handling channel closures:
- Mutual close - cooperative closure agreed by both parties
- Unilateral close - one party publishes their commitment transaction
- Revoked transaction close - penalty for publishing old state
Design
This is a stateless toolkit of pure functions. The caller
manages channel state (which outputs are resolved, current
block height, etc.) and provides explicit inputs. Functions
produce unsigned SpendingTx values; the caller signs and
assembles witnesses using bolt3 constructors.
Usage
import Lightning.Protocol.BOLT3
import Lightning.Protocol.BOLT5
-- Classify outputs of our local commitment
let outputs = classify_local_commit_outputs
commitTx keys delay features htlcs
-- For each unresolved output, construct spending tx
case uo_type output of
SpendToLocal delay revpk delayedpk ->
spend_to_local (uo_outpoint output)
(uo_value output) revpk delay delayedpk
destScript feerate
...
Synopsis
- data CloseType
- data UnresolvedOutput = UnresolvedOutput {
- uo_outpoint :: !OutPoint
- uo_value :: !Satoshi
- uo_type :: !OutputResolution
- data OutputResolution
- = Resolved
- | SpendToLocal !ToSelfDelay !RevocationPubkey !LocalDelayedPubkey
- | SpendHTLCTimeout !HTLC !CommitmentKeys !ChannelFeatures
- | SpendHTLCSuccess !HTLC !CommitmentKeys !ChannelFeatures
- | SpendHTLCTimeoutDirect !HTLC
- | SpendHTLCPreimageDirect !HTLC
- | Revoke !RevocationPubkey
- | RevokeHTLC !RevocationPubkey !OutputType
- | AnchorSpend !FundingPubkey
- data SpendingTx = SpendingTx {
- stx_tx :: !Tx
- stx_input_script :: !Script
- stx_input_value :: !Satoshi
- stx_sighash_type :: !SighashType
- data PenaltyContext = PenaltyContext {}
- to_local_penalty_witness_weight :: Word64
- offered_htlc_penalty_witness_weight :: Word64
- accepted_htlc_penalty_witness_weight :: Word64
- to_local_penalty_input_weight :: Word64
- offered_htlc_penalty_input_weight :: Word64
- accepted_htlc_penalty_input_weight :: Word64
- to_remote_input_weight :: Word64
- penalty_tx_base_weight :: Word64
- max_standard_weight :: Word64
- spending_fee :: FeeratePerKw -> Word64 -> Satoshi
- identify_close :: CommitmentTx -> CommitmentTx -> ByteString -> Maybe CloseType
- classify_local_commit_outputs :: CommitmentTx -> CommitmentKeys -> ToSelfDelay -> ChannelFeatures -> [HTLC] -> [UnresolvedOutput]
- classify_remote_commit_outputs :: CommitmentTx -> CommitmentKeys -> ChannelFeatures -> [HTLC] -> [UnresolvedOutput]
- classify_revoked_commit_outputs :: CommitmentTx -> CommitmentKeys -> RevocationPubkey -> ChannelFeatures -> [HTLC] -> [UnresolvedOutput]
- extract_preimage_offered :: Witness -> Maybe PaymentPreimage
- extract_preimage_htlc_success :: Witness -> Maybe PaymentPreimage
- htlc_timed_out :: Word32 -> HTLC -> Bool
- 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
Types
Close identification
What kind of close was detected on chain.
Constructors
| MutualClose | Cooperative closure agreed by both parties. |
| LocalCommitClose | Our commitment transaction was broadcast. |
| RemoteCommitClose | The remote party's commitment transaction was broadcast. |
| RevokedCommitClose | A revoked (outdated) commitment transaction was broadcast. |
Instances
| Generic CloseType Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Associated Types
| |||||
| Show CloseType Source # | |||||
| Eq CloseType Source # | |||||
| type Rep CloseType Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types type Rep CloseType = D1 ('MetaData "CloseType" "Lightning.Protocol.BOLT5.Types" "ppad-bolt5-0.0.1-5N7Wen1sZDiBgqKJHrpe1Z" 'False) ((C1 ('MetaCons "MutualClose" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "LocalCommitClose" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "RemoteCommitClose" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "RevokedCommitClose" 'PrefixI 'False) (U1 :: Type -> Type))) | |||||
Output classification
data UnresolvedOutput Source #
An unresolved commitment transaction output.
Constructors
| UnresolvedOutput | |
Fields
| |
Instances
data OutputResolution Source #
How to resolve an output, per BOLT #5 rules.
Constructors
| Resolved | Already resolved (e.g. to_remote on local commit). |
| SpendToLocal !ToSelfDelay !RevocationPubkey !LocalDelayedPubkey | Spend to_local after CSV delay. |
| SpendHTLCTimeout !HTLC !CommitmentKeys !ChannelFeatures | Spend via HTLC-timeout second-stage tx (local commit, local offer). |
| SpendHTLCSuccess !HTLC !CommitmentKeys !ChannelFeatures | Spend via HTLC-success second-stage tx (local commit, remote offer). |
| SpendHTLCTimeoutDirect !HTLC | Spend HTLC directly after timeout (remote commit, local offer). |
| SpendHTLCPreimageDirect !HTLC | Spend HTLC directly with preimage (remote commit, remote offer). |
| Revoke !RevocationPubkey | Spend revoked to_local with revocation key. |
| RevokeHTLC !RevocationPubkey !OutputType | Spend revoked HTLC output with revocation key. |
| AnchorSpend !FundingPubkey | Spend anchor output. |
Instances
| Generic OutputResolution Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Associated Types
Methods from :: OutputResolution -> Rep OutputResolution x # to :: Rep OutputResolution x -> OutputResolution # | |||||
| Show OutputResolution Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Methods showsPrec :: Int -> OutputResolution -> ShowS # show :: OutputResolution -> String # showList :: [OutputResolution] -> ShowS # | |||||
| Eq OutputResolution Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Methods (==) :: OutputResolution -> OutputResolution -> Bool # (/=) :: OutputResolution -> OutputResolution -> Bool # | |||||
| type Rep OutputResolution Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types type Rep OutputResolution = D1 ('MetaData "OutputResolution" "Lightning.Protocol.BOLT5.Types" "ppad-bolt5-0.0.1-5N7Wen1sZDiBgqKJHrpe1Z" 'False) (((C1 ('MetaCons "Resolved" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "SpendToLocal" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ToSelfDelay) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationPubkey) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalDelayedPubkey)))) :+: (C1 ('MetaCons "SpendHTLCTimeout" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HTLC) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CommitmentKeys) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelFeatures))) :+: C1 ('MetaCons "SpendHTLCSuccess" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HTLC) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CommitmentKeys) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelFeatures))))) :+: ((C1 ('MetaCons "SpendHTLCTimeoutDirect" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HTLC)) :+: C1 ('MetaCons "SpendHTLCPreimageDirect" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HTLC))) :+: (C1 ('MetaCons "Revoke" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationPubkey)) :+: (C1 ('MetaCons "RevokeHTLC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationPubkey) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OutputType)) :+: C1 ('MetaCons "AnchorSpend" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FundingPubkey)))))) | |||||
Spending transactions
data SpendingTx Source #
Unsigned spending transaction, ready for caller to sign.
The caller uses bolt3 witness constructors to assemble the final witness after signing.
Constructors
| SpendingTx | |
Fields
| |
Instances
| Generic SpendingTx Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Associated Types
| |||||
| Show SpendingTx Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Methods showsPrec :: Int -> SpendingTx -> ShowS # show :: SpendingTx -> String # showList :: [SpendingTx] -> ShowS # | |||||
| Eq SpendingTx Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types | |||||
| type Rep SpendingTx Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types type Rep SpendingTx = D1 ('MetaData "SpendingTx" "Lightning.Protocol.BOLT5.Types" "ppad-bolt5-0.0.1-5N7Wen1sZDiBgqKJHrpe1Z" 'False) (C1 ('MetaCons "SpendingTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "stx_tx") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Tx) :*: S1 ('MetaSel ('Just "stx_input_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)) :*: (S1 ('MetaSel ('Just "stx_input_value") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Just "stx_sighash_type") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SighashType)))) | |||||
Penalty batching
data PenaltyContext Source #
Context for constructing batched penalty transactions.
Constructors
| PenaltyContext | |
Fields
| |
Instances
| Generic PenaltyContext Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Associated Types
Methods from :: PenaltyContext -> Rep PenaltyContext x # to :: Rep PenaltyContext x -> PenaltyContext # | |||||
| Show PenaltyContext Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Methods showsPrec :: Int -> PenaltyContext -> ShowS # show :: PenaltyContext -> String # showList :: [PenaltyContext] -> ShowS # | |||||
| Eq PenaltyContext Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Methods (==) :: PenaltyContext -> PenaltyContext -> Bool # (/=) :: PenaltyContext -> PenaltyContext -> Bool # | |||||
| type Rep PenaltyContext Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types type Rep PenaltyContext = D1 ('MetaData "PenaltyContext" "Lightning.Protocol.BOLT5.Types" "ppad-bolt5-0.0.1-5N7Wen1sZDiBgqKJHrpe1Z" 'False) (C1 ('MetaCons "PenaltyContext" 'PrefixI 'True) ((S1 ('MetaSel ('Just "pc_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (NonEmpty UnresolvedOutput)) :*: S1 ('MetaSel ('Just "pc_revocation_key") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationPubkey)) :*: (S1 ('MetaSel ('Just "pc_destination") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "pc_feerate") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FeeratePerKw)))) | |||||
Weight constants (Appendix A)
to_local_penalty_witness_weight :: Word64 Source #
Expected weight of the to_local penalty transaction witness (160 bytes).
offered_htlc_penalty_witness_weight :: Word64 Source #
Expected weight of the offered_htlc penalty transaction witness (243 bytes).
accepted_htlc_penalty_witness_weight :: Word64 Source #
Expected weight of the accepted_htlc penalty transaction witness (249 bytes).
to_local_penalty_input_weight :: Word64 Source #
Weight of a to_local penalty input (164 + 160 = 324 bytes).
offered_htlc_penalty_input_weight :: Word64 Source #
Weight of an offered_htlc penalty input (164 + 243 = 407 bytes).
accepted_htlc_penalty_input_weight :: Word64 Source #
Weight of an accepted_htlc penalty input (164 + 249 = 413 bytes).
to_remote_input_weight :: Word64 Source #
Weight of a to_remote P2WPKH input (108 + 164 = 272 bytes).
penalty_tx_base_weight :: Word64 Source #
Base weight of a penalty transaction (4*53 + 2 = 214 bytes).
Non-witness: version(4) + input_count(1) + output_count(1) + value(8) + script_len(1) + p2wsh_script(34) + locktime(4) = 53 Witness header: 2 bytes.
max_standard_weight :: Word64 Source #
Maximum standard transaction weight (400,000 bytes).
Fee calculation
spending_fee :: FeeratePerKw -> Word64 -> Satoshi Source #
Calculate the fee for a spending transaction given its weight.
fee = feerate_per_kw * weight / 1000
Close identification
Arguments
| :: CommitmentTx | Our local commitment tx. |
| -> CommitmentTx | The remote commitment tx (current). |
| -> ByteString | Raw serialized transaction found on chain. |
| -> Maybe CloseType |
Identify the type of channel close from a transaction that spends the funding output.
Compares the on-chain transaction bytes against the known local and remote commitment transaction serializations (stripped/unsigned) to determine whether it's a local or remote commitment close.
Returns Nothing if the transaction doesn't match either
commitment. Mutual close and revoked commitment detection
require additional checks by the caller (e.g. comparing
closing tx format, checking a secret store for older
commitment numbers).
Output classification
classify_local_commit_outputs Source #
Arguments
| :: CommitmentTx | Our local commitment transaction. |
| -> CommitmentKeys | Derived keys for this commitment. |
| -> ToSelfDelay | Remote's to_self_delay (CSV delay for our outputs). |
| -> ChannelFeatures | Channel feature flags. |
| -> [HTLC] | HTLCs in this commitment. |
| -> [UnresolvedOutput] |
Classify outputs of our local commitment transaction.
Per BOLT #5: when we discover our local commitment on chain, we must resolve each output. to_local requires a CSV-delayed spend, to_remote is resolved by the commitment itself, HTLC outputs need second-stage transactions, and anchors can be spent immediately.
classify_remote_commit_outputs Source #
Arguments
| :: CommitmentTx | The remote commitment transaction. |
| -> CommitmentKeys | Derived keys for this commitment (from remote's perspective, so local/remote are swapped). |
| -> ChannelFeatures | Channel feature flags. |
| -> [HTLC] | HTLCs in this commitment. |
| -> [UnresolvedOutput] |
Classify outputs of the remote commitment transaction.
Per BOLT #5: when we discover the remote commitment on chain, there are no CSV delays on our outputs. We can spend offered HTLCs directly after timeout, and received HTLCs directly with the preimage.
classify_revoked_commit_outputs Source #
Arguments
| :: CommitmentTx | The revoked commitment transaction. |
| -> CommitmentKeys | Derived keys for the revoked commitment. |
| -> RevocationPubkey | Revocation pubkey (derived from the revealed secret). |
| -> ChannelFeatures | Channel feature flags. |
| -> [HTLC] | HTLCs in the revoked commitment. |
| -> [UnresolvedOutput] |
Classify outputs of a revoked commitment transaction.
Per BOLT #5: when we discover a revoked commitment, we can claim everything using the revocation key. to_local is spent via revocation, HTLCs are spent via revocation, and we can also optionally sweep to_remote.
Preimage extraction
extract_preimage_offered :: Witness -> Maybe PaymentPreimage Source #
Extract a payment preimage from an offered HTLC witness.
When the remote party claims an offered HTLC on our local commitment, the witness contains the preimage. The witness stack for a preimage claim is:
<remotehtlcsig> <paymentPreimage>
The preimage is the second item (32 bytes) and must hash to the expected payment hash.
extract_preimage_htlc_success :: Witness -> Maybe PaymentPreimage Source #
Extract a payment preimage from an HTLC-success transaction witness.
When the remote party uses an HTLC-success tx on their commitment to claim a received HTLC, the witness contains the preimage. The witness stack is:
0 <remotehtlcsig> <localhtlcsig> <paymentPreimage>
The preimage is the fourth item (32 bytes).
Timeout check
htlc_timed_out :: Word32 -> HTLC -> Bool Source #
Check if an HTLC has timed out at the given block height.
An HTLC has timed out when the current block height is equal to or greater than the HTLC's CLTV expiry.
Spending transaction construction
Local commitment
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
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
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 outputs
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).