| Copyright | (c) 2025 Jared Tobin |
|---|---|
| License | MIT |
| Maintainer | Jared Tobin <jared@ppad.tech> |
| Safe Haskell | None |
| Language | Haskell2010 |
Lightning.Protocol.BOLT5.Types
Description
Types for BOLT #5 on-chain transaction handling.
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 !HTLCOutputType
- | AnchorSpend !FundingPubkey
- data HTLCOutputType
- htlcOutputType :: OutputType -> Maybe HTLCOutputType
- htlcOutputTypeWeight :: HTLCOutputType -> Word64
- data SpendingTx = SpendingTx {
- stx_tx :: !Tx
- stx_input_script :: !Script
- stx_input_value :: !Satoshi
- stx_sighash_type :: !SighashType
- data RevokedOutput = RevokedOutput {
- ro_outpoint :: !OutPoint
- ro_value :: !Satoshi
- ro_type :: !RevokedOutputType
- data RevokedOutputType
- data PenaltyContext = PenaltyContext {}
- revoked_output_weight :: RevokedOutput -> Word64
- 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
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-IGu7gJAK79v1xlbxm4omg6" '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 !HTLCOutputType | 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-IGu7gJAK79v1xlbxm4omg6" '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 HTLCOutputType)) :+: C1 ('MetaCons "AnchorSpend" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FundingPubkey)))))) | |||||
HTLC output type
data HTLCOutputType Source #
Type of HTLC output, restricted to only HTLC variants.
Unlike bolt3's OutputType which includes all six output
types, this ADT makes it impossible to confuse HTLC outputs
with to_local, to_remote, or anchor outputs.
Constructors
| HTLCOfferedOutput !CltvExpiry | Offered HTLC output with CLTV expiry. |
| HTLCReceivedOutput !CltvExpiry | Received HTLC output with CLTV expiry. |
Instances
| Generic HTLCOutputType Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Associated Types
Methods from :: HTLCOutputType -> Rep HTLCOutputType x # to :: Rep HTLCOutputType x -> HTLCOutputType # | |||||
| Show HTLCOutputType Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Methods showsPrec :: Int -> HTLCOutputType -> ShowS # show :: HTLCOutputType -> String # showList :: [HTLCOutputType] -> ShowS # | |||||
| Eq HTLCOutputType Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Methods (==) :: HTLCOutputType -> HTLCOutputType -> Bool # (/=) :: HTLCOutputType -> HTLCOutputType -> Bool # | |||||
| type Rep HTLCOutputType Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types type Rep HTLCOutputType = D1 ('MetaData "HTLCOutputType" "Lightning.Protocol.BOLT5.Types" "ppad-bolt5-0.0.1-IGu7gJAK79v1xlbxm4omg6" 'False) (C1 ('MetaCons "HTLCOfferedOutput" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 CltvExpiry)) :+: C1 ('MetaCons "HTLCReceivedOutput" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 CltvExpiry))) | |||||
htlcOutputType :: OutputType -> Maybe HTLCOutputType Source #
Extract an HTLCOutputType from a bolt3 OutputType.
Returns Nothing for non-HTLC output types.
>>>htlcOutputType (OutputOfferedHTLC (CltvExpiry 500))Just (HTLCOfferedOutput (CltvExpiry ...))>>>htlcOutputType OutputToLocalNothing
htlcOutputTypeWeight :: HTLCOutputType -> Word64 Source #
Penalty input weight for an HTLC output type.
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-IGu7gJAK79v1xlbxm4omg6" '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 RevokedOutput Source #
A revoked output that can be swept with a revocation key.
This type restricts penalty transaction inputs to only valid revocation targets: to_local outputs and HTLC outputs. Other output types (to_remote, anchors) cannot appear in penalty transactions.
Constructors
| RevokedOutput | |
Fields
| |
Instances
| Generic RevokedOutput Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Associated Types
| |||||
| Show RevokedOutput Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Methods showsPrec :: Int -> RevokedOutput -> ShowS # show :: RevokedOutput -> String # showList :: [RevokedOutput] -> ShowS # | |||||
| Eq RevokedOutput Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Methods (==) :: RevokedOutput -> RevokedOutput -> Bool # (/=) :: RevokedOutput -> RevokedOutput -> Bool # | |||||
| type Rep RevokedOutput Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types type Rep RevokedOutput = D1 ('MetaData "RevokedOutput" "Lightning.Protocol.BOLT5.Types" "ppad-bolt5-0.0.1-IGu7gJAK79v1xlbxm4omg6" 'False) (C1 ('MetaCons "RevokedOutput" 'PrefixI 'True) (S1 ('MetaSel ('Just "ro_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OutPoint) :*: (S1 ('MetaSel ('Just "ro_value") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Just "ro_type") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevokedOutputType)))) | |||||
data RevokedOutputType Source #
What kind of revoked output is being swept.
Constructors
| RevokedToLocal | Revoked to_local output. |
| RevokedHTLC !HTLCOutputType | Revoked HTLC output. |
Instances
| Generic RevokedOutputType Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Associated Types
Methods from :: RevokedOutputType -> Rep RevokedOutputType x # to :: Rep RevokedOutputType x -> RevokedOutputType # | |||||
| Show RevokedOutputType Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Methods showsPrec :: Int -> RevokedOutputType -> ShowS # show :: RevokedOutputType -> String # showList :: [RevokedOutputType] -> ShowS # | |||||
| Eq RevokedOutputType Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types Methods (==) :: RevokedOutputType -> RevokedOutputType -> Bool # (/=) :: RevokedOutputType -> RevokedOutputType -> Bool # | |||||
| type Rep RevokedOutputType Source # | |||||
Defined in Lightning.Protocol.BOLT5.Types type Rep RevokedOutputType = D1 ('MetaData "RevokedOutputType" "Lightning.Protocol.BOLT5.Types" "ppad-bolt5-0.0.1-IGu7gJAK79v1xlbxm4omg6" 'False) (C1 ('MetaCons "RevokedToLocal" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "RevokedHTLC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HTLCOutputType))) | |||||
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-IGu7gJAK79v1xlbxm4omg6" 'False) (C1 ('MetaCons "PenaltyContext" 'PrefixI 'True) ((S1 ('MetaSel ('Just "pc_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (NonEmpty RevokedOutput)) :*: 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)))) | |||||
revoked_output_weight :: RevokedOutput -> Word64 Source #
Penalty input weight for a revoked output.
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