| Copyright | (c) 2025 Jared Tobin |
|---|---|
| License | MIT |
| Maintainer | Jared Tobin <jared@ppad.tech> |
| Safe Haskell | None |
| Language | Haskell2010 |
Lightning.Protocol.BOLT1
Description
The base protocol of the Lightning Network, per
BOLT #1:
fundamental types and their encodings, the TLV format, and the
init, error, warning, ping, pong, peer_storage and
peer_storage_retrieval messages.
The fundamental types and TLV machinery here are shared by the other ppad BOLT libraries.
Synopsis
- data Message
- message_type :: Message -> Word16
- data Init = Init {}
- data Error = Error {}
- data Warning = Warning {}
- data Ping = Ping {}
- data Pong = Pong {
- pong_ignored :: !ByteString
- pong_tlvs :: !TlvStream
- ping_response :: Ping -> Maybe Pong
- data PeerStorage = PeerStorage {}
- data PeerStorageRetrieval = PeerStorageRetrieval {}
- encode_message :: Message -> Either EncodeError ByteString
- decode_message :: ByteString -> Either DecodeError Message
- encode_envelope :: Word16 -> ByteString -> Either EncodeError ByteString
- decode_envelope :: ByteString -> Either DecodeError (Word16, ByteString)
- data EncodeError
- data DecodeError
- encode_init :: Init -> Either EncodeError ByteString
- decode_init :: ByteString -> Either DecodeError Init
- encode_error :: Error -> Either EncodeError ByteString
- decode_error :: ByteString -> Either DecodeError Error
- encode_warning :: Warning -> Either EncodeError ByteString
- decode_warning :: ByteString -> Either DecodeError Warning
- encode_ping :: Ping -> Either EncodeError ByteString
- decode_ping :: ByteString -> Either DecodeError Ping
- encode_pong :: Pong -> Either EncodeError ByteString
- decode_pong :: ByteString -> Either DecodeError Pong
- encode_peer_storage :: PeerStorage -> Either EncodeError ByteString
- decode_peer_storage :: ByteString -> Either DecodeError PeerStorage
- encode_peer_storage_retrieval :: PeerStorageRetrieval -> Either EncodeError ByteString
- decode_peer_storage_retrieval :: ByteString -> Either DecodeError PeerStorageRetrieval
- data TlvRecord = TlvRecord {
- tlv_type :: !Word64
- tlv_value :: !ByteString
- data TlvStream
- tlv_stream :: [TlvRecord] -> Maybe TlvStream
- un_tlv_stream :: TlvStream -> [TlvRecord]
- empty_tlv_stream :: TlvStream
- lookup_tlv :: Word64 -> TlvStream -> Maybe ByteString
- filter_tlv_stream :: (Word64 -> Bool) -> TlvStream -> TlvStream
- encode_tlv_stream :: TlvStream -> ByteString
- decode_tlv_stream :: (Word64 -> Bool) -> ByteString -> Either TlvError TlvStream
- data TlvError
- data ChainHash
- chain_hash :: ByteString -> Maybe ChainHash
- un_chain_hash :: ChainHash -> ByteString
- data ChannelId
- channel_id :: ByteString -> Maybe ChannelId
- un_channel_id :: ChannelId -> ByteString
- all_channels :: ChannelId
- data Signature
- signature :: ByteString -> Maybe Signature
- un_signature :: Signature -> ByteString
- data Point
- point :: ByteString -> Maybe Point
- un_point :: Point -> ByteString
- data PaymentHash
- payment_hash :: ByteString -> Maybe PaymentHash
- un_payment_hash :: PaymentHash -> ByteString
- data PaymentPreimage
- payment_preimage :: ByteString -> Maybe PaymentPreimage
- un_payment_preimage :: PaymentPreimage -> ByteString
- data PerCommitmentSecret
- per_commitment_secret :: ByteString -> Maybe PerCommitmentSecret
- un_per_commitment_secret :: PerCommitmentSecret -> ByteString
- newtype ShortChannelId = ShortChannelId Word64
- short_channel_id :: Word32 -> Word32 -> Word16 -> Maybe ShortChannelId
- scid_block_height :: ShortChannelId -> Word32
- scid_tx_index :: ShortChannelId -> Word32
- scid_output_index :: ShortChannelId -> Word16
- data Satoshi
- satoshi :: Word64 -> Maybe Satoshi
- un_satoshi :: Satoshi -> Word64
- max_satoshi :: Satoshi
- data MilliSatoshi
- milli_satoshi :: Word64 -> Maybe MilliSatoshi
- un_milli_satoshi :: MilliSatoshi -> Word64
- max_milli_satoshi :: MilliSatoshi
- sat_to_msat :: Satoshi -> MilliSatoshi
- msat_to_sat :: MilliSatoshi -> Satoshi
- add_sat :: Satoshi -> Satoshi -> Maybe Satoshi
- sub_sat :: Satoshi -> Satoshi -> Maybe Satoshi
- add_msat :: MilliSatoshi -> MilliSatoshi -> Maybe MilliSatoshi
- sub_msat :: MilliSatoshi -> MilliSatoshi -> Maybe MilliSatoshi
- encode_u16 :: Word16 -> ByteString
- encode_u32 :: Word32 -> ByteString
- encode_u64 :: Word64 -> ByteString
- decode_u16 :: ByteString -> Maybe (Word16, ByteString)
- decode_u32 :: ByteString -> Maybe (Word32, ByteString)
- decode_u64 :: ByteString -> Maybe (Word64, ByteString)
- encode_s8 :: Int8 -> ByteString
- encode_s16 :: Int16 -> ByteString
- encode_s32 :: Int32 -> ByteString
- encode_s64 :: Int64 -> ByteString
- decode_s8 :: ByteString -> Maybe (Int8, ByteString)
- decode_s16 :: ByteString -> Maybe (Int16, ByteString)
- decode_s32 :: ByteString -> Maybe (Int32, ByteString)
- decode_s64 :: ByteString -> Maybe (Int64, ByteString)
- encode_tu16 :: Word16 -> ByteString
- encode_tu32 :: Word32 -> ByteString
- encode_tu64 :: Word64 -> ByteString
- decode_tu16 :: ByteString -> Maybe Word16
- decode_tu32 :: ByteString -> Maybe Word32
- decode_tu64 :: ByteString -> Maybe Word64
- encode_bigsize :: Word64 -> ByteString
- decode_bigsize :: ByteString -> Maybe (Word64, ByteString)
- encode_u16_prefixed :: ByteString -> Maybe ByteString
- decode_u16_prefixed :: ByteString -> Maybe (ByteString, ByteString)
- decode_chain_hash :: ByteString -> Maybe (ChainHash, ByteString)
- decode_channel_id :: ByteString -> Maybe (ChannelId, ByteString)
- decode_signature :: ByteString -> Maybe (Signature, ByteString)
- decode_point :: ByteString -> Maybe (Point, ByteString)
- decode_payment_hash :: ByteString -> Maybe (PaymentHash, ByteString)
- decode_payment_preimage :: ByteString -> Maybe (PaymentPreimage, ByteString)
- decode_per_commitment_secret :: ByteString -> Maybe (PerCommitmentSecret, ByteString)
- encode_short_channel_id :: ShortChannelId -> ByteString
- decode_short_channel_id :: ByteString -> Maybe (ShortChannelId, ByteString)
- encode_satoshi :: Satoshi -> ByteString
- decode_satoshi :: ByteString -> Maybe (Satoshi, ByteString)
- encode_milli_satoshi :: MilliSatoshi -> ByteString
- decode_milli_satoshi :: ByteString -> Maybe (MilliSatoshi, ByteString)
Messages
A BOLT #1 message.
Constructors
| MsgInit !Init | |
| MsgError !Error | |
| MsgWarning !Warning | |
| MsgPing !Ping | |
| MsgPong !Pong | |
| MsgPeerStorage !PeerStorage | |
| MsgPeerStorageRetrieval !PeerStorageRetrieval |
Instances
message_type :: Message -> Word16 Source #
The wire type of a Message.
>>>message_type (MsgPong (Pong "" empty_tlv_stream))19
The init message (type 16).
The two feature vectors are kept as received. Per BOLT #1, a
receiver treats their union (union) as the peer's
features.
Constructors
| Init | |
Fields
| |
Instances
| NFData Init Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message | |||||
| Generic Init Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
| |||||
| Show Init Source # | |||||
| Eq Init Source # | |||||
| type Rep Init Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message type Rep Init = D1 ('MetaData "Init" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'False) (C1 ('MetaCons "Init" 'PrefixI 'True) ((S1 ('MetaSel ('Just "init_global_features") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FeatureVector) :*: S1 ('MetaSel ('Just "init_features") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FeatureVector)) :*: (S1 ('MetaSel ('Just "init_networks") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe [ChainHash])) :*: (S1 ('MetaSel ('Just "init_remote_addr") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe ByteString)) :*: S1 ('MetaSel ('Just "init_tlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvStream))))) | |||||
The error message (type 17).
Constructors
| Error | |
Fields
| |
Instances
| NFData Error Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message | |||||
| Generic Error Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
| |||||
| Show Error Source # | |||||
| Eq Error Source # | |||||
| type Rep Error Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message type Rep Error = D1 ('MetaData "Error" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'False) (C1 ('MetaCons "Error" 'PrefixI 'True) (S1 ('MetaSel ('Just "error_channel_id") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelId) :*: (S1 ('MetaSel ('Just "error_data") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "error_tlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvStream)))) | |||||
The warning message (type 1).
Constructors
| Warning | |
Fields
| |
Instances
| NFData Warning Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message | |||||
| Generic Warning Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
| |||||
| Show Warning Source # | |||||
| Eq Warning Source # | |||||
| type Rep Warning Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message type Rep Warning = D1 ('MetaData "Warning" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'False) (C1 ('MetaCons "Warning" 'PrefixI 'True) (S1 ('MetaSel ('Just "warning_channel_id") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelId) :*: (S1 ('MetaSel ('Just "warning_data") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "warning_tlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvStream)))) | |||||
The ping message (type 18).
Constructors
| Ping | |
Fields
| |
Instances
| NFData Ping Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message | |||||
| Generic Ping Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
| |||||
| Show Ping Source # | |||||
| Eq Ping Source # | |||||
| type Rep Ping Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message type Rep Ping = D1 ('MetaData "Ping" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'False) (C1 ('MetaCons "Ping" 'PrefixI 'True) (S1 ('MetaSel ('Just "ping_num_pong_bytes") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word16) :*: (S1 ('MetaSel ('Just "ping_ignored") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "ping_tlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvStream)))) | |||||
The pong message (type 19).
Constructors
| Pong | |
Fields
| |
Instances
| NFData Pong Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message | |||||
| Generic Pong Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
| |||||
| Show Pong Source # | |||||
| Eq Pong Source # | |||||
| type Rep Pong Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message type Rep Pong = D1 ('MetaData "Pong" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'False) (C1 ('MetaCons "Pong" 'PrefixI 'True) (S1 ('MetaSel ('Just "pong_ignored") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "pong_tlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvStream))) | |||||
data PeerStorage Source #
The peer_storage message (type 7).
Constructors
| PeerStorage | |
Fields
| |
Instances
| NFData PeerStorage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Methods rnf :: PeerStorage -> () # | |||||
| Generic PeerStorage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
| |||||
| Show PeerStorage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Methods showsPrec :: Int -> PeerStorage -> ShowS # show :: PeerStorage -> String # showList :: [PeerStorage] -> ShowS # | |||||
| Eq PeerStorage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message | |||||
| type Rep PeerStorage Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message type Rep PeerStorage = D1 ('MetaData "PeerStorage" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'False) (C1 ('MetaCons "PeerStorage" 'PrefixI 'True) (S1 ('MetaSel ('Just "peer_storage_blob") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "peer_storage_tlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvStream))) | |||||
data PeerStorageRetrieval Source #
The peer_storage_retrieval message (type 9).
Constructors
| PeerStorageRetrieval | |
Fields
| |
Instances
| NFData PeerStorageRetrieval Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Methods rnf :: PeerStorageRetrieval -> () # | |||||
| Generic PeerStorageRetrieval Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Associated Types
Methods from :: PeerStorageRetrieval -> Rep PeerStorageRetrieval x # to :: Rep PeerStorageRetrieval x -> PeerStorageRetrieval # | |||||
| Show PeerStorageRetrieval Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Methods showsPrec :: Int -> PeerStorageRetrieval -> ShowS # show :: PeerStorageRetrieval -> String # showList :: [PeerStorageRetrieval] -> ShowS # | |||||
| Eq PeerStorageRetrieval Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message Methods (==) :: PeerStorageRetrieval -> PeerStorageRetrieval -> Bool # (/=) :: PeerStorageRetrieval -> PeerStorageRetrieval -> Bool # | |||||
| type Rep PeerStorageRetrieval Source # | |||||
Defined in Lightning.Protocol.BOLT1.Message type Rep PeerStorageRetrieval = D1 ('MetaData "PeerStorageRetrieval" "Lightning.Protocol.BOLT1.Message" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'False) (C1 ('MetaCons "PeerStorageRetrieval" 'PrefixI 'True) (S1 ('MetaSel ('Just "peer_storage_retrieval_blob") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "peer_storage_retrieval_tlvs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvStream))) | |||||
Encoding and decoding messages
encode_message :: Message -> Either EncodeError ByteString Source #
Encode a BOLT #1 message, including its type.
>>>encode_message (MsgPong (Pong "" empty_tlv_stream))Right "\NUL\DC3\NUL\NUL"
decode_message :: ByteString -> Either DecodeError Message Source #
Decode a BOLT #1 message, including its type.
A type that BOLT #1 doesn't define yields DecodeUnknownEvenType
or DecodeUnknownOddType; callers dispatching messages from other
BOLTs should use decode_envelope first.
>>>decode_message "\NUL\DC3\NUL\NUL"Right (MsgPong (Pong {pong_ignored = "", pong_tlvs = TlvStream []}))>>>decode_message "\NUL\DC4\NUL\NUL"Left (DecodeUnknownEvenType 20)
encode_envelope :: Word16 -> ByteString -> Either EncodeError ByteString Source #
Prefix a payload with its message type. Fails if the result exceeds the 65535-byte message limit.
>>>encode_envelope 19 "\NUL\NUL"Right "\NUL\DC3\NUL\NUL"
decode_envelope :: ByteString -> Either DecodeError (Word16, ByteString) Source #
Split a message into its type and payload.
>>>decode_envelope "\NUL\DC3\NUL\NUL"Right (19,"\NUL\NUL")
data EncodeError Source #
Why a message failed to encode.
Constructors
| EncodeLengthOverflow | a length-prefixed field exceeds 65535 bytes |
| EncodeMessageTooLarge | the message (type and payload) exceeds 65535 bytes |
| EncodeInvalidTlvs | a record in a |
Instances
| NFData EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec Methods rnf :: EncodeError -> () # | |||||
| Generic EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec Associated Types
| |||||
| Show EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec Methods showsPrec :: Int -> EncodeError -> ShowS # show :: EncodeError -> String # showList :: [EncodeError] -> ShowS # | |||||
| Eq EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec | |||||
| type Rep EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec type Rep EncodeError = D1 ('MetaData "EncodeError" "Lightning.Protocol.BOLT1.Codec" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'False) (C1 ('MetaCons "EncodeLengthOverflow" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "EncodeMessageTooLarge" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "EncodeInvalidTlvs" 'PrefixI 'False) (U1 :: Type -> Type))) | |||||
data DecodeError Source #
Why a message failed to decode.
Constructors
| DecodeInsufficientBytes | the input ended before a field did |
| DecodeTlvError !TlvError | the message's TLV stream is malformed |
| DecodeInvalidTlvValue !Word64 | a known TLV record (of the given type) has a malformed value |
| DecodeUnknownEvenType !Word16 | an unknown even message type; the connection must be closed |
| DecodeUnknownOddType !Word16 | an unknown odd message type; the message must be ignored |
Instances
| NFData DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec Methods rnf :: DecodeError -> () # | |||||
| Generic DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec Associated Types
| |||||
| Show DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec Methods showsPrec :: Int -> DecodeError -> ShowS # show :: DecodeError -> String # showList :: [DecodeError] -> ShowS # | |||||
| Eq DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec | |||||
| type Rep DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT1.Codec type Rep DecodeError = D1 ('MetaData "DecodeError" "Lightning.Protocol.BOLT1.Codec" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'False) ((C1 ('MetaCons "DecodeInsufficientBytes" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DecodeTlvError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvError))) :+: (C1 ('MetaCons "DecodeInvalidTlvValue" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word64)) :+: (C1 ('MetaCons "DecodeUnknownEvenType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word16)) :+: C1 ('MetaCons "DecodeUnknownOddType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word16))))) | |||||
Payloads
encode_init :: Init -> Either EncodeError ByteString Source #
Encode an Init payload.
decode_init :: ByteString -> Either DecodeError Init Source #
Decode an Init payload.
encode_error :: Error -> Either EncodeError ByteString Source #
Encode an Error payload.
decode_error :: ByteString -> Either DecodeError Error Source #
Decode an Error payload.
encode_warning :: Warning -> Either EncodeError ByteString Source #
Encode a Warning payload.
decode_warning :: ByteString -> Either DecodeError Warning Source #
Decode a Warning payload.
encode_ping :: Ping -> Either EncodeError ByteString Source #
Encode a Ping payload.
decode_ping :: ByteString -> Either DecodeError Ping Source #
Decode a Ping payload.
encode_pong :: Pong -> Either EncodeError ByteString Source #
Encode a Pong payload.
decode_pong :: ByteString -> Either DecodeError Pong Source #
Decode a Pong payload.
encode_peer_storage :: PeerStorage -> Either EncodeError ByteString Source #
Encode a PeerStorage payload.
decode_peer_storage :: ByteString -> Either DecodeError PeerStorage Source #
Decode a PeerStorage payload.
encode_peer_storage_retrieval :: PeerStorageRetrieval -> Either EncodeError ByteString Source #
Encode a PeerStorageRetrieval payload.
decode_peer_storage_retrieval :: ByteString -> Either DecodeError PeerStorageRetrieval Source #
Decode a PeerStorageRetrieval payload.
TLV
A single TLV record.
Constructors
| TlvRecord | |
Fields
| |
Instances
| NFData TlvRecord Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV | |||||
| Generic TlvRecord Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV Associated Types
| |||||
| Show TlvRecord Source # | |||||
| Eq TlvRecord Source # | |||||
| type Rep TlvRecord Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV type Rep TlvRecord = D1 ('MetaData "TlvRecord" "Lightning.Protocol.BOLT1.TLV" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'False) (C1 ('MetaCons "TlvRecord" 'PrefixI 'True) (S1 ('MetaSel ('Just "tlv_type") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word64) :*: S1 ('MetaSel ('Just "tlv_value") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString))) | |||||
A TLV stream: records in strictly increasing type order.
Instances
| NFData TlvStream Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV | |||||
| Generic TlvStream Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV Associated Types
| |||||
| Show TlvStream Source # | |||||
| Eq TlvStream Source # | |||||
| type Rep TlvStream Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV | |||||
tlv_stream :: [TlvRecord] -> Maybe TlvStream Source #
Construct a TlvStream from records in any order. Fails if two
records share a type.
>>>let Just s = tlv_stream [TlvRecord 3 "b", TlvRecord 1 "a"]>>>map tlv_type (un_tlv_stream s)[1,3]>>>tlv_stream [TlvRecord 1 "a", TlvRecord 1 "b"]Nothing
un_tlv_stream :: TlvStream -> [TlvRecord] Source #
The records of a TlvStream, in increasing type order.
empty_tlv_stream :: TlvStream Source #
The empty TlvStream.
lookup_tlv :: Word64 -> TlvStream -> Maybe ByteString Source #
The value of the record with the given type, if present.
>>>lookup_tlv 3 =<< tlv_stream [TlvRecord 1 "a", TlvRecord 3 "b"]Just "b"
filter_tlv_stream :: (Word64 -> Bool) -> TlvStream -> TlvStream Source #
Keep the records whose types satisfy the predicate.
>>>let Just s = tlv_stream [TlvRecord 1 "", TlvRecord 2 ""]>>>map tlv_type (un_tlv_stream (filter_tlv_stream odd s))[1]
encode_tlv_stream :: TlvStream -> ByteString Source #
Encode a TlvStream.
>>>fmap encode_tlv_stream (tlv_stream [TlvRecord 1 "a"])Just "\SOH\SOHa"
Decode a TLV stream occupying the whole input, given a predicate identifying the types known in the stream's context.
Per BOLT #1, decoding fails on truncation, non-minimal BigSize encodings, types that are not strictly increasing, and unknown even types. Every record is kept, including unknown odd ones, so re-encoding reproduces the input.
>>>let Right s = decode_tlv_stream (== 1) "\SOH\SOHa\ETX\NUL">>>map tlv_type (un_tlv_stream s)[1,3]>>>decode_tlv_stream (== 1) "\STX\NUL"Left (TlvUnknownEvenType 2)
Why a TLV stream failed to decode.
Constructors
| TlvTruncated | a type, length or value was cut off |
| TlvNonMinimalBigSize | a type or length wasn't minimal |
| TlvNotStrictlyIncreasing | types out of order or repeated |
| TlvUnknownEvenType !Word64 | an even type the context doesn't know |
Instances
| NFData TlvError Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV | |||||
| Generic TlvError Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV Associated Types
| |||||
| Show TlvError Source # | |||||
| Eq TlvError Source # | |||||
| type Rep TlvError Source # | |||||
Defined in Lightning.Protocol.BOLT1.TLV type Rep TlvError = D1 ('MetaData "TlvError" "Lightning.Protocol.BOLT1.TLV" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'False) ((C1 ('MetaCons "TlvTruncated" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TlvNonMinimalBigSize" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "TlvNotStrictlyIncreasing" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TlvUnknownEvenType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word64)))) | |||||
Fundamental types
A 32-byte chain hash, identifying the chain a channel or message belongs to.
Instances
| NFData ChainHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Generic ChainHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
| |||||
| Show ChainHash Source # | |||||
| Eq ChainHash Source # | |||||
| Ord ChainHash Source # | |||||
| type Rep ChainHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep ChainHash = D1 ('MetaData "ChainHash" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'True) (C1 ('MetaCons "ChainHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |||||
chain_hash :: ByteString -> Maybe ChainHash Source #
Construct a ChainHash from exactly 32 bytes.
>>>fmap (BS.length . un_chain_hash) (chain_hash (BS.replicate 32 0))Just 32>>>chain_hash "too short"Nothing
un_chain_hash :: ChainHash -> ByteString Source #
The bytes of a ChainHash.
A 32-byte channel identifier.
Instances
| NFData ChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Generic ChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
| |||||
| Show ChannelId Source # | |||||
| Eq ChannelId Source # | |||||
| Ord ChannelId Source # | |||||
| type Rep ChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep ChannelId = D1 ('MetaData "ChannelId" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'True) (C1 ('MetaCons "ChannelId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |||||
channel_id :: ByteString -> Maybe ChannelId Source #
Construct a ChannelId from exactly 32 bytes.
>>>fmap (BS.length . un_channel_id) (channel_id (BS.replicate 32 1))Just 32
un_channel_id :: ChannelId -> ByteString Source #
The bytes of a ChannelId.
all_channels :: ChannelId Source #
The all-zero channel identifier, which refers to all channels
(e.g. in connection-level error and warning messages).
A 64-byte compact ECDSA signature.
Instances
| NFData Signature Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Generic Signature Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
| |||||
| Show Signature Source # | |||||
| Eq Signature Source # | |||||
| Ord Signature Source # | |||||
| type Rep Signature Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep Signature = D1 ('MetaData "Signature" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'True) (C1 ('MetaCons "Signature" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |||||
signature :: ByteString -> Maybe Signature Source #
Construct a Signature from exactly 64 bytes.
>>>signature (BS.replicate 63 0x00)Nothing
un_signature :: Signature -> ByteString Source #
The bytes of a Signature.
A 33-byte compressed secp256k1 point.
Instances
| NFData Point Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Generic Point Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
| |||||
| Show Point Source # | |||||
| Eq Point Source # | |||||
| Ord Point Source # | |||||
| type Rep Point Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep Point = D1 ('MetaData "Point" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'True) (C1 ('MetaCons "Point" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |||||
point :: ByteString -> Maybe Point Source #
Construct a Point from 33 bytes with a compressed-encoding
prefix (0x02 or 0x03). The curve equation is not checked; use
ppad-secp256k1 to parse the point if it must be on the curve.
>>>point (BS.cons 0x04 (BS.replicate 32 0x01))Nothing
data PaymentHash Source #
A 32-byte SHA256 payment hash.
Instances
| NFData PaymentHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods rnf :: PaymentHash -> () # | |||||
| Generic PaymentHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
| |||||
| Show PaymentHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods showsPrec :: Int -> PaymentHash -> ShowS # show :: PaymentHash -> String # showList :: [PaymentHash] -> ShowS # | |||||
| Eq PaymentHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Ord PaymentHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods compare :: PaymentHash -> PaymentHash -> Ordering # (<) :: PaymentHash -> PaymentHash -> Bool # (<=) :: PaymentHash -> PaymentHash -> Bool # (>) :: PaymentHash -> PaymentHash -> Bool # (>=) :: PaymentHash -> PaymentHash -> Bool # max :: PaymentHash -> PaymentHash -> PaymentHash # min :: PaymentHash -> PaymentHash -> PaymentHash # | |||||
| type Rep PaymentHash Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep PaymentHash = D1 ('MetaData "PaymentHash" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'True) (C1 ('MetaCons "PaymentHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |||||
payment_hash :: ByteString -> Maybe PaymentHash Source #
Construct a PaymentHash from exactly 32 bytes.
un_payment_hash :: PaymentHash -> ByteString Source #
The bytes of a PaymentHash.
data PaymentPreimage Source #
A 32-byte payment preimage.
This is secret material: its Show instance is redacted and its
Eq instance runs in constant time.
Instances
| NFData PaymentPreimage Source # | |
Defined in Lightning.Protocol.BOLT1.Prim Methods rnf :: PaymentPreimage -> () # | |
| Show PaymentPreimage Source # | |
Defined in Lightning.Protocol.BOLT1.Prim Methods showsPrec :: Int -> PaymentPreimage -> ShowS # show :: PaymentPreimage -> String # showList :: [PaymentPreimage] -> ShowS # | |
| Eq PaymentPreimage Source # | |
Defined in Lightning.Protocol.BOLT1.Prim Methods (==) :: PaymentPreimage -> PaymentPreimage -> Bool # (/=) :: PaymentPreimage -> PaymentPreimage -> Bool # | |
payment_preimage :: ByteString -> Maybe PaymentPreimage Source #
Construct a PaymentPreimage from exactly 32 bytes.
un_payment_preimage :: PaymentPreimage -> ByteString Source #
The bytes of a PaymentPreimage.
data PerCommitmentSecret Source #
A 32-byte per-commitment secret.
This is secret material: its Show instance is redacted and its
Eq instance runs in constant time.
Instances
| NFData PerCommitmentSecret Source # | |
Defined in Lightning.Protocol.BOLT1.Prim Methods rnf :: PerCommitmentSecret -> () # | |
| Show PerCommitmentSecret Source # | |
Defined in Lightning.Protocol.BOLT1.Prim Methods showsPrec :: Int -> PerCommitmentSecret -> ShowS # show :: PerCommitmentSecret -> String # showList :: [PerCommitmentSecret] -> ShowS # | |
| Eq PerCommitmentSecret Source # | |
Defined in Lightning.Protocol.BOLT1.Prim Methods (==) :: PerCommitmentSecret -> PerCommitmentSecret -> Bool # (/=) :: PerCommitmentSecret -> PerCommitmentSecret -> Bool # | |
per_commitment_secret :: ByteString -> Maybe PerCommitmentSecret Source #
Construct a PerCommitmentSecret from exactly 32 bytes.
un_per_commitment_secret :: PerCommitmentSecret -> ByteString Source #
The bytes of a PerCommitmentSecret.
newtype ShortChannelId Source #
A short channel identifier: block height (3 bytes), transaction
index (3 bytes) and output index (2 bytes), packed big-endian into
a Word64. Every Word64 is a valid packing.
Constructors
| ShortChannelId Word64 |
Instances
| NFData ShortChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods rnf :: ShortChannelId -> () # | |||||
| Generic ShortChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
Methods from :: ShortChannelId -> Rep ShortChannelId x # to :: Rep ShortChannelId x -> ShortChannelId # | |||||
| Show ShortChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods showsPrec :: Int -> ShortChannelId -> ShowS # show :: ShortChannelId -> String # showList :: [ShortChannelId] -> ShowS # | |||||
| Eq ShortChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods (==) :: ShortChannelId -> ShortChannelId -> Bool # (/=) :: ShortChannelId -> ShortChannelId -> Bool # | |||||
| Ord ShortChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods compare :: ShortChannelId -> ShortChannelId -> Ordering # (<) :: ShortChannelId -> ShortChannelId -> Bool # (<=) :: ShortChannelId -> ShortChannelId -> Bool # (>) :: ShortChannelId -> ShortChannelId -> Bool # (>=) :: ShortChannelId -> ShortChannelId -> Bool # max :: ShortChannelId -> ShortChannelId -> ShortChannelId # min :: ShortChannelId -> ShortChannelId -> ShortChannelId # | |||||
| type Rep ShortChannelId Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep ShortChannelId = D1 ('MetaData "ShortChannelId" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'True) (C1 ('MetaCons "ShortChannelId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64))) | |||||
Arguments
| :: Word32 | block height |
| -> Word32 | transaction index |
| -> Word16 | output index |
| -> Maybe ShortChannelId |
Construct a ShortChannelId from its components. Fails if the
block height or transaction index exceed 24 bits.
>>>short_channel_id 539268 845 1Just (ShortChannelId 592931436542885889)
scid_block_height :: ShortChannelId -> Word32 Source #
The block height of a ShortChannelId.
scid_tx_index :: ShortChannelId -> Word32 Source #
The transaction index of a ShortChannelId.
scid_output_index :: ShortChannelId -> Word16 Source #
The output index of a ShortChannelId.
Amounts
An amount in satoshis, at most 21 million BTC (max_satoshi).
Instances
| NFData Satoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Generic Satoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
| |||||
| Show Satoshi Source # | |||||
| Eq Satoshi Source # | |||||
| Ord Satoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| type Rep Satoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
satoshi :: Word64 -> Maybe Satoshi Source #
Construct a Satoshi amount, failing above 21 million BTC.
>>>satoshi 1000Just (Satoshi 1000)>>>satoshi 0xffffffffffffffffNothing
un_satoshi :: Satoshi -> Word64 Source #
The number of satoshis.
max_satoshi :: Satoshi Source #
21 million BTC, in satoshis (0x000775f05a074000).
data MilliSatoshi Source #
An amount in millisatoshis, at most 21 million BTC
(max_milli_satoshi).
Instances
| NFData MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods rnf :: MilliSatoshi -> () # | |||||
| Generic MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Associated Types
| |||||
| Show MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods showsPrec :: Int -> MilliSatoshi -> ShowS # show :: MilliSatoshi -> String # showList :: [MilliSatoshi] -> ShowS # | |||||
| Eq MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim | |||||
| Ord MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim Methods compare :: MilliSatoshi -> MilliSatoshi -> Ordering # (<) :: MilliSatoshi -> MilliSatoshi -> Bool # (<=) :: MilliSatoshi -> MilliSatoshi -> Bool # (>) :: MilliSatoshi -> MilliSatoshi -> Bool # (>=) :: MilliSatoshi -> MilliSatoshi -> Bool # max :: MilliSatoshi -> MilliSatoshi -> MilliSatoshi # min :: MilliSatoshi -> MilliSatoshi -> MilliSatoshi # | |||||
| type Rep MilliSatoshi Source # | |||||
Defined in Lightning.Protocol.BOLT1.Prim type Rep MilliSatoshi = D1 ('MetaData "MilliSatoshi" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'True) (C1 ('MetaCons "MilliSatoshi" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64))) | |||||
milli_satoshi :: Word64 -> Maybe MilliSatoshi Source #
Construct a MilliSatoshi amount, failing above 21 million BTC.
un_milli_satoshi :: MilliSatoshi -> Word64 Source #
The number of millisatoshis.
max_milli_satoshi :: MilliSatoshi Source #
21 million BTC, in millisatoshis (0x1d24b2dfac520000).
sat_to_msat :: Satoshi -> MilliSatoshi Source #
Convert satoshis to millisatoshis. Total, since the bounds correspond.
>>>fmap sat_to_msat (satoshi 5)Just (MilliSatoshi 5000)
msat_to_sat :: MilliSatoshi -> Satoshi Source #
Convert millisatoshis to satoshis, rounding down.
add_sat :: Satoshi -> Satoshi -> Maybe Satoshi Source #
Add two amounts, failing above 21 million BTC. (Amounts are bounded well below 2^63, so the sum can't wrap.)
sub_sat :: Satoshi -> Satoshi -> Maybe Satoshi Source #
Subtract the second amount from the first, failing if the result would be negative.
add_msat :: MilliSatoshi -> MilliSatoshi -> Maybe MilliSatoshi Source #
Add two amounts, failing above 21 million BTC.
sub_msat :: MilliSatoshi -> MilliSatoshi -> Maybe MilliSatoshi Source #
Subtract the second amount from the first, failing if the result would be negative.
Primitive encodings
Decoders return the decoded value and the remaining input, except for the truncated integers, which occupy their whole input.
encode_u16 :: Word16 -> ByteString Source #
Encode a Word16 as 2 big-endian bytes.
>>>encode_u16 0x0102"\SOH\STX"
encode_u32 :: Word32 -> ByteString Source #
Encode a Word32 as 4 big-endian bytes.
encode_u64 :: Word64 -> ByteString Source #
Encode a Word64 as 8 big-endian bytes.
decode_u16 :: ByteString -> Maybe (Word16, ByteString) Source #
Decode 2 big-endian bytes, returning the remaining input.
>>>decode_u16 "\SOH\STXrest"Just (258,"rest")
decode_u32 :: ByteString -> Maybe (Word32, ByteString) Source #
Decode 4 big-endian bytes, returning the remaining input.
decode_u64 :: ByteString -> Maybe (Word64, ByteString) Source #
Decode 8 big-endian bytes, returning the remaining input.
encode_s8 :: Int8 -> ByteString Source #
Encode an Int8 as 1 byte (two's complement).
>>>encode_s8 (-42)"\214"
encode_s16 :: Int16 -> ByteString Source #
Encode an Int16 as 2 big-endian bytes (two's complement).
encode_s32 :: Int32 -> ByteString Source #
Encode an Int32 as 4 big-endian bytes (two's complement).
encode_s64 :: Int64 -> ByteString Source #
Encode an Int64 as 8 big-endian bytes (two's complement).
decode_s8 :: ByteString -> Maybe (Int8, ByteString) Source #
Decode 1 byte (two's complement), returning the remaining input.
decode_s16 :: ByteString -> Maybe (Int16, ByteString) Source #
Decode 2 big-endian bytes (two's complement).
decode_s32 :: ByteString -> Maybe (Int32, ByteString) Source #
Decode 4 big-endian bytes (two's complement).
decode_s64 :: ByteString -> Maybe (Int64, ByteString) Source #
Decode 8 big-endian bytes (two's complement).
encode_tu16 :: Word16 -> ByteString Source #
Encode a Word16 as a truncated integer (no leading zero bytes).
>>>encode_tu16 0"">>>encode_tu16 0x0100"\SOH\NUL"
encode_tu32 :: Word32 -> ByteString Source #
Encode a Word32 as a truncated integer (no leading zero bytes).
encode_tu64 :: Word64 -> ByteString Source #
Encode a Word64 as a truncated integer (no leading zero bytes).
decode_tu16 :: ByteString -> Maybe Word16 Source #
Decode a truncated 16-bit integer occupying the whole input. Fails on more than 2 bytes or a non-minimal encoding.
>>>decode_tu16 "\SOH\NUL"Just 256>>>decode_tu16 "\NUL\SOH"Nothing
decode_tu32 :: ByteString -> Maybe Word32 Source #
Decode a truncated 32-bit integer occupying the whole input. Fails on more than 4 bytes or a non-minimal encoding.
decode_tu64 :: ByteString -> Maybe Word64 Source #
Decode a truncated 64-bit integer occupying the whole input. Fails on more than 8 bytes or a non-minimal encoding.
encode_bigsize :: Word64 -> ByteString Source #
Encode a Word64 in the minimal BigSize format.
>>>encode_bigsize 252"\252">>>encode_bigsize 253"\253\NUL\253"
decode_bigsize :: ByteString -> Maybe (Word64, ByteString) Source #
Decode a minimally-encoded BigSize, returning the remaining input.
>>>decode_bigsize "\253\NUL\253rest"Just (253,"rest")>>>decode_bigsize "\253\NUL\252"Nothing
encode_u16_prefixed :: ByteString -> Maybe ByteString Source #
Prefix bytes with their length as a u16. Fails if the input exceeds 65535 bytes.
>>>encode_u16_prefixed "abc"Just "\NUL\ETXabc"
decode_u16_prefixed :: ByteString -> Maybe (ByteString, ByteString) Source #
Decode u16-length-prefixed bytes, returning the remaining input.
>>>decode_u16_prefixed "\NUL\ETXabcrest"Just ("abc","rest")
decode_chain_hash :: ByteString -> Maybe (ChainHash, ByteString) Source #
Decode a 32-byte ChainHash, returning the remaining input.
decode_channel_id :: ByteString -> Maybe (ChannelId, ByteString) Source #
Decode a 32-byte ChannelId, returning the remaining input.
decode_signature :: ByteString -> Maybe (Signature, ByteString) Source #
Decode a 64-byte Signature, returning the remaining input.
decode_point :: ByteString -> Maybe (Point, ByteString) Source #
Decode a 33-byte Point, returning the remaining input. Fails if
the prefix byte is not 0x02 or 0x03.
decode_payment_hash :: ByteString -> Maybe (PaymentHash, ByteString) Source #
Decode a 32-byte PaymentHash, returning the remaining input.
decode_payment_preimage :: ByteString -> Maybe (PaymentPreimage, ByteString) Source #
Decode a 32-byte PaymentPreimage, returning the remaining input.
decode_per_commitment_secret :: ByteString -> Maybe (PerCommitmentSecret, ByteString) Source #
Decode a 32-byte PerCommitmentSecret, returning the remaining
input.
encode_short_channel_id :: ShortChannelId -> ByteString Source #
Encode a ShortChannelId as 8 big-endian bytes.
decode_short_channel_id :: ByteString -> Maybe (ShortChannelId, ByteString) Source #
Decode an 8-byte ShortChannelId, returning the remaining input.
encode_satoshi :: Satoshi -> ByteString Source #
Encode a Satoshi amount as a u64.
decode_satoshi :: ByteString -> Maybe (Satoshi, ByteString) Source #
Decode a u64 Satoshi amount, returning the remaining input. Fails
above 21 million BTC.
encode_milli_satoshi :: MilliSatoshi -> ByteString Source #
Encode a MilliSatoshi amount as a u64.
decode_milli_satoshi :: ByteString -> Maybe (MilliSatoshi, ByteString) Source #
Decode a u64 MilliSatoshi amount, returning the remaining input.
Fails above 21 million BTC.