| Copyright | (c) 2025 Jared Tobin |
|---|---|
| License | MIT |
| Maintainer | Jared Tobin <jared@ppad.tech> |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Lightning.Protocol.BOLT9.Types
Description
Baseline types for BOLT #9 feature flags.
Synopsis
- data Context
- = Init
- | NodeAnn
- | ChanAnn
- | ChanAnnOdd
- | ChanAnnEven
- | Invoice
- | Blinded
- | ChanType
- isChannelContext :: Context -> Bool
- channelParity :: Context -> Maybe Bool
- data BitIndex
- bitIndex :: Word16 -> BitIndex
- data FeatureLevel
- data RequiredBit
- requiredBit :: Word16 -> Maybe RequiredBit
- requiredFromBitIndex :: BitIndex -> Maybe RequiredBit
- data OptionalBit
- optionalBit :: Word16 -> Maybe OptionalBit
- optionalFromBitIndex :: BitIndex -> Maybe OptionalBit
- data FeatureVector
- empty :: FeatureVector
- fromByteString :: ByteString -> FeatureVector
- set :: BitIndex -> FeatureVector -> FeatureVector
- clear :: BitIndex -> FeatureVector -> FeatureVector
- member :: BitIndex -> FeatureVector -> Bool
Context
Presentation context for feature flags.
Per BOLT #9, features are presented in different message contexts:
Init- theinitmessageNodeAnn-node_announcementmessagesChanAnn-channel_announcementmessages (normal)ChanAnnOdd-channel_announcement, always odd (optional)ChanAnnEven-channel_announcement, always even (required)Invoice- BOLT 11 invoicesBlinded-allowed_featuresfield of a blinded pathChanType-channel_typefield when opening channels
Constructors
| Init | I: presented in the |
| NodeAnn | N: presented in |
| ChanAnn | C: presented in |
| ChanAnnOdd | C-: |
| ChanAnnEven | C+: |
| Invoice | 9: presented in BOLT 11 invoices |
| Blinded | B: |
| ChanType | T: |
Instances
isChannelContext :: Context -> Bool Source #
Check if a context is a channel announcement context (C, C-, or C+).
Bit indices
A bit index into a feature vector. Bit 0 is the least significant bit.
Valid range: 0-65535 (sufficient for any practical feature flag).
Instances
| NFData BitIndex Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types | |||||
| Generic BitIndex Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Associated Types
| |||||
| Show BitIndex Source # | |||||
| Eq BitIndex Source # | |||||
| Ord BitIndex Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types | |||||
| type Rep BitIndex Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types | |||||
bitIndex :: Word16 -> BitIndex Source #
Smart constructor for BitIndex. Always succeeds since all Word16
values are valid.
Required/optional level
data FeatureLevel Source #
Whether a feature is set as required or optional.
Per BOLT #9, each feature has a pair of bits: the even bit indicates required (compulsory) support, the odd bit indicates optional support.
Constructors
| Required | The feature is required (even bit set) |
| Optional | The feature is optional (odd bit set) |
Instances
| NFData FeatureLevel Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Methods rnf :: FeatureLevel -> () # | |||||
| Generic FeatureLevel Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Associated Types
| |||||
| Show FeatureLevel Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Methods showsPrec :: Int -> FeatureLevel -> ShowS # show :: FeatureLevel -> String # showList :: [FeatureLevel] -> ShowS # | |||||
| Eq FeatureLevel Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types | |||||
| Ord FeatureLevel Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Methods compare :: FeatureLevel -> FeatureLevel -> Ordering # (<) :: FeatureLevel -> FeatureLevel -> Bool # (<=) :: FeatureLevel -> FeatureLevel -> Bool # (>) :: FeatureLevel -> FeatureLevel -> Bool # (>=) :: FeatureLevel -> FeatureLevel -> Bool # max :: FeatureLevel -> FeatureLevel -> FeatureLevel # min :: FeatureLevel -> FeatureLevel -> FeatureLevel # | |||||
| type Rep FeatureLevel Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types | |||||
Required/optional bits
data RequiredBit Source #
A required (compulsory) feature bit. Required bits are always even.
Instances
| NFData RequiredBit Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Methods rnf :: RequiredBit -> () # | |||||
| Generic RequiredBit Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Associated Types
| |||||
| Show RequiredBit Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Methods showsPrec :: Int -> RequiredBit -> ShowS # show :: RequiredBit -> String # showList :: [RequiredBit] -> ShowS # | |||||
| Eq RequiredBit Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types | |||||
| Ord RequiredBit Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Methods compare :: RequiredBit -> RequiredBit -> Ordering # (<) :: RequiredBit -> RequiredBit -> Bool # (<=) :: RequiredBit -> RequiredBit -> Bool # (>) :: RequiredBit -> RequiredBit -> Bool # (>=) :: RequiredBit -> RequiredBit -> Bool # max :: RequiredBit -> RequiredBit -> RequiredBit # min :: RequiredBit -> RequiredBit -> RequiredBit # | |||||
| type Rep RequiredBit Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types type Rep RequiredBit = D1 ('MetaData "RequiredBit" "Lightning.Protocol.BOLT9.Types" "ppad-bolt9-0.0.1-SCTy7SY2nBJMXEGG76XgS" 'True) (C1 ('MetaCons "RequiredBit" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRequiredBit") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word16))) | |||||
requiredBit :: Word16 -> Maybe RequiredBit Source #
Smart constructor for RequiredBit. Returns Nothing if the bit
index is odd.
>>>requiredBit 16Just (RequiredBit {unRequiredBit = 16})>>>requiredBit 17Nothing
requiredFromBitIndex :: BitIndex -> Maybe RequiredBit Source #
Convert a BitIndex to a RequiredBit. Returns Nothing if odd.
data OptionalBit Source #
An optional feature bit. Optional bits are always odd.
Instances
| NFData OptionalBit Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Methods rnf :: OptionalBit -> () # | |||||
| Generic OptionalBit Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Associated Types
| |||||
| Show OptionalBit Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Methods showsPrec :: Int -> OptionalBit -> ShowS # show :: OptionalBit -> String # showList :: [OptionalBit] -> ShowS # | |||||
| Eq OptionalBit Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types | |||||
| Ord OptionalBit Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Methods compare :: OptionalBit -> OptionalBit -> Ordering # (<) :: OptionalBit -> OptionalBit -> Bool # (<=) :: OptionalBit -> OptionalBit -> Bool # (>) :: OptionalBit -> OptionalBit -> Bool # (>=) :: OptionalBit -> OptionalBit -> Bool # max :: OptionalBit -> OptionalBit -> OptionalBit # min :: OptionalBit -> OptionalBit -> OptionalBit # | |||||
| type Rep OptionalBit Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types type Rep OptionalBit = D1 ('MetaData "OptionalBit" "Lightning.Protocol.BOLT9.Types" "ppad-bolt9-0.0.1-SCTy7SY2nBJMXEGG76XgS" 'True) (C1 ('MetaCons "OptionalBit" 'PrefixI 'True) (S1 ('MetaSel ('Just "unOptionalBit") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word16))) | |||||
optionalBit :: Word16 -> Maybe OptionalBit Source #
Smart constructor for OptionalBit. Returns Nothing if the bit
index is even.
>>>optionalBit 17Just (OptionalBit {unOptionalBit = 17})>>>optionalBit 16Nothing
optionalFromBitIndex :: BitIndex -> Maybe OptionalBit Source #
Convert a BitIndex to an OptionalBit. Returns Nothing if even.
Feature vectors
data FeatureVector Source #
A feature vector represented as a strict ByteString.
The vector is stored in big-endian byte order (most significant byte first), with bits numbered from the least significant bit of the last byte. Bit 0 is at position 0 of the last byte.
Instances
| NFData FeatureVector Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Methods rnf :: FeatureVector -> () # | |||||
| Generic FeatureVector Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Associated Types
| |||||
| Show FeatureVector Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Methods showsPrec :: Int -> FeatureVector -> ShowS # show :: FeatureVector -> String # showList :: [FeatureVector] -> ShowS # | |||||
| Eq FeatureVector Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Methods (==) :: FeatureVector -> FeatureVector -> Bool # (/=) :: FeatureVector -> FeatureVector -> Bool # | |||||
| Ord FeatureVector Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types Methods compare :: FeatureVector -> FeatureVector -> Ordering # (<) :: FeatureVector -> FeatureVector -> Bool # (<=) :: FeatureVector -> FeatureVector -> Bool # (>) :: FeatureVector -> FeatureVector -> Bool # (>=) :: FeatureVector -> FeatureVector -> Bool # max :: FeatureVector -> FeatureVector -> FeatureVector # min :: FeatureVector -> FeatureVector -> FeatureVector # | |||||
| type Rep FeatureVector Source # | |||||
Defined in Lightning.Protocol.BOLT9.Types type Rep FeatureVector = D1 ('MetaData "FeatureVector" "Lightning.Protocol.BOLT9.Types" "ppad-bolt9-0.0.1-SCTy7SY2nBJMXEGG76XgS" 'True) (C1 ('MetaCons "FeatureVector" 'PrefixI 'True) (S1 ('MetaSel ('Just "unFeatureVector") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |||||
empty :: FeatureVector Source #
The empty feature vector (no features set).
>>>emptyFeatureVector {unFeatureVector = ""}
fromByteString :: ByteString -> FeatureVector Source #
Wrap a ByteString as a FeatureVector.
set :: BitIndex -> FeatureVector -> FeatureVector Source #
Set a bit in the feature vector.
>>>set (bitIndex 0) emptyFeatureVector {unFeatureVector = "\SOH"}>>>set (bitIndex 8) emptyFeatureVector {unFeatureVector = "\SOH\NUL"}
clear :: BitIndex -> FeatureVector -> FeatureVector Source #
Clear a bit in the feature vector.