ppad-bolt1-0.1.0: Base protocol per BOLT #1
Copyright(c) 2025 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@ppad.tech>
Safe HaskellNone
LanguageHaskell2010

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

Messages

data Message Source #

A BOLT #1 message.

Instances

Instances details
NFData Message Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: Message -> () #

Generic Message Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

from :: Message -> Rep Message x #

to :: Rep Message x -> Message #

Show Message Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Eq Message Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

(==) :: Message -> Message -> Bool #

(/=) :: Message -> Message -> Bool #

type Rep Message Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

message_type :: Message -> Word16 Source #

The wire type of a Message.

>>> message_type (MsgPong (Pong "" empty_tlv_stream))
19

data Init Source #

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

Instances details
NFData Init Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: Init -> () #

Generic Init Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep Init 
Instance details

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)))))

Methods

from :: Init -> Rep Init x #

to :: Rep Init x -> Init #

Show Init Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

showsPrec :: Int -> Init -> ShowS #

show :: Init -> String #

showList :: [Init] -> ShowS #

Eq Init Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

(==) :: Init -> Init -> Bool #

(/=) :: Init -> Init -> Bool #

type Rep Init Source # 
Instance details

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)))))

data Error Source #

The error message (type 17).

Constructors

Error 

Fields

Instances

Instances details
NFData Error Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: Error -> () #

Generic Error Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep Error 
Instance details

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))))

Methods

from :: Error -> Rep Error x #

to :: Rep Error x -> Error #

Show Error Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

showsPrec :: Int -> Error -> ShowS #

show :: Error -> String #

showList :: [Error] -> ShowS #

Eq Error Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

(==) :: Error -> Error -> Bool #

(/=) :: Error -> Error -> Bool #

type Rep Error Source # 
Instance details

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))))

data Warning Source #

The warning message (type 1).

Constructors

Warning 

Fields

Instances

Instances details
NFData Warning Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: Warning -> () #

Generic Warning Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep Warning 
Instance details

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))))

Methods

from :: Warning -> Rep Warning x #

to :: Rep Warning x -> Warning #

Show Warning Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Eq Warning Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

(==) :: Warning -> Warning -> Bool #

(/=) :: Warning -> Warning -> Bool #

type Rep Warning Source # 
Instance details

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))))

data Ping Source #

The ping message (type 18).

Constructors

Ping 

Fields

Instances

Instances details
NFData Ping Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: Ping -> () #

Generic Ping Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep Ping 
Instance details

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))))

Methods

from :: Ping -> Rep Ping x #

to :: Rep Ping x -> Ping #

Show Ping Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

showsPrec :: Int -> Ping -> ShowS #

show :: Ping -> String #

showList :: [Ping] -> ShowS #

Eq Ping Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

(==) :: Ping -> Ping -> Bool #

(/=) :: Ping -> Ping -> Bool #

type Rep Ping Source # 
Instance details

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))))

data Pong Source #

The pong message (type 19).

Constructors

Pong 

Fields

Instances

Instances details
NFData Pong Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: Pong -> () #

Generic Pong Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep Pong 
Instance details

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)))

Methods

from :: Pong -> Rep Pong x #

to :: Rep Pong x -> Pong #

Show Pong Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

showsPrec :: Int -> Pong -> ShowS #

show :: Pong -> String #

showList :: [Pong] -> ShowS #

Eq Pong Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

(==) :: Pong -> Pong -> Bool #

(/=) :: Pong -> Pong -> Bool #

type Rep Pong Source # 
Instance details

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)))

ping_response :: Ping -> Maybe Pong Source #

The Pong a node must send in reply to a Ping, if any. Per BOLT #1, a ping requesting 65532 or more bytes is ignored.

>>> ping_response (Ping 4 "" empty_tlv_stream)
Just (Pong {pong_ignored = "\NUL\NUL\NUL\NUL", pong_tlvs = TlvStream []})
>>> ping_response (Ping 65532 "" empty_tlv_stream)
Nothing

data PeerStorage Source #

The peer_storage message (type 7).

Constructors

PeerStorage 

Fields

Instances

Instances details
NFData PeerStorage Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: PeerStorage -> () #

Generic PeerStorage Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep PeerStorage 
Instance details

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)))
Show PeerStorage Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Eq PeerStorage Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep PeerStorage Source # 
Instance details

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

Instances details
NFData PeerStorageRetrieval Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Methods

rnf :: PeerStorageRetrieval -> () #

Generic PeerStorageRetrieval Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Associated Types

type Rep PeerStorageRetrieval 
Instance details

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)))
Show PeerStorageRetrieval Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

Eq PeerStorageRetrieval Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Message

type Rep PeerStorageRetrieval Source # 
Instance details

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 _tlvs field duplicates a typed field

Instances

Instances details
NFData EncodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

Methods

rnf :: EncodeError -> () #

Generic EncodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

Associated Types

type Rep EncodeError 
Instance details

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)))
Show EncodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

Eq EncodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

type Rep EncodeError Source # 
Instance details

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

Instances details
NFData DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

Methods

rnf :: DecodeError -> () #

Generic DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

Associated Types

type Rep DecodeError 
Instance details

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)))))
Show DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

Eq DecodeError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Codec

type Rep DecodeError Source # 
Instance details

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

TLV

data TlvRecord Source #

A single TLV record.

Constructors

TlvRecord 

Instances

Instances details
NFData TlvRecord Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Methods

rnf :: TlvRecord -> () #

Generic TlvRecord Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Associated Types

type Rep TlvRecord 
Instance details

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)))
Show TlvRecord Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Eq TlvRecord Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep TlvRecord Source # 
Instance details

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)))

data TlvStream Source #

A TLV stream: records in strictly increasing type order.

Instances

Instances details
NFData TlvStream Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Methods

rnf :: TlvStream -> () #

Generic TlvStream Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Associated Types

type Rep TlvStream 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep TlvStream = D1 ('MetaData "TlvStream" "Lightning.Protocol.BOLT1.TLV" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'True) (C1 ('MetaCons "TlvStream" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TlvRecord])))
Show TlvStream Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Eq TlvStream Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep TlvStream Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep TlvStream = D1 ('MetaData "TlvStream" "Lightning.Protocol.BOLT1.TLV" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'True) (C1 ('MetaCons "TlvStream" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TlvRecord])))

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.

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_tlv_stream Source #

Arguments

:: (Word64 -> Bool)

is this type known?

-> ByteString 
-> Either TlvError TlvStream 

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)

data TlvError Source #

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

Instances details
NFData TlvError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Methods

rnf :: TlvError -> () #

Generic TlvError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Associated Types

type Rep TlvError 
Instance details

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))))

Methods

from :: TlvError -> Rep TlvError x #

to :: Rep TlvError x -> TlvError #

Show TlvError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

Eq TlvError Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.TLV

type Rep TlvError Source # 
Instance details

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

data ChainHash Source #

A 32-byte chain hash, identifying the chain a channel or message belongs to.

Instances

Instances details
NFData ChainHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Methods

rnf :: ChainHash -> () #

Generic ChainHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Associated Types

type Rep ChainHash 
Instance details

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)))
Show ChainHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Eq ChainHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Ord ChainHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

type Rep ChainHash Source # 
Instance details

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

data ChannelId Source #

A 32-byte channel identifier.

Instances

Instances details
NFData ChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Methods

rnf :: ChannelId -> () #

Generic ChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Associated Types

type Rep ChannelId 
Instance details

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)))
Show ChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Eq ChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Ord ChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

type Rep ChannelId Source # 
Instance details

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

all_channels :: ChannelId Source #

The all-zero channel identifier, which refers to all channels (e.g. in connection-level error and warning messages).

data Signature Source #

A 64-byte compact ECDSA signature.

Instances

Instances details
NFData Signature Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Methods

rnf :: Signature -> () #

Generic Signature Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Associated Types

type Rep Signature 
Instance details

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)))
Show Signature Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Eq Signature Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Ord Signature Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

type Rep Signature Source # 
Instance details

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

data Point Source #

A 33-byte compressed secp256k1 point.

Instances

Instances details
NFData Point Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Methods

rnf :: Point -> () #

Generic Point Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Associated Types

type Rep Point 
Instance details

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)))

Methods

from :: Point -> Rep Point x #

to :: Rep Point x -> Point #

Show Point Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Methods

showsPrec :: Int -> Point -> ShowS #

show :: Point -> String #

showList :: [Point] -> ShowS #

Eq Point Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Methods

(==) :: Point -> Point -> Bool #

(/=) :: Point -> Point -> Bool #

Ord Point Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Methods

compare :: Point -> Point -> Ordering #

(<) :: Point -> Point -> Bool #

(<=) :: Point -> Point -> Bool #

(>) :: Point -> Point -> Bool #

(>=) :: Point -> Point -> Bool #

max :: Point -> Point -> Point #

min :: Point -> Point -> Point #

type Rep Point Source # 
Instance details

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

un_point :: Point -> ByteString Source #

The bytes of a Point.

data PaymentHash Source #

A 32-byte SHA256 payment hash.

Instances

Instances details
NFData PaymentHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Methods

rnf :: PaymentHash -> () #

Generic PaymentHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Associated Types

type Rep PaymentHash 
Instance details

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)))
Show PaymentHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Eq PaymentHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Ord PaymentHash Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

type Rep PaymentHash Source # 
Instance details

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.

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.

payment_preimage :: ByteString -> Maybe PaymentPreimage Source #

Construct a PaymentPreimage from exactly 32 bytes.

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.

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

Instances details
NFData ShortChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Methods

rnf :: ShortChannelId -> () #

Generic ShortChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Associated Types

type Rep ShortChannelId 
Instance details

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)))
Show ShortChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Eq ShortChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Ord ShortChannelId Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

type Rep ShortChannelId Source # 
Instance details

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)))

short_channel_id Source #

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 1
Just (ShortChannelId 592931436542885889)

scid_tx_index :: ShortChannelId -> Word32 Source #

The transaction index of a ShortChannelId.

Amounts

data Satoshi Source #

An amount in satoshis, at most 21 million BTC (max_satoshi).

Instances

Instances details
NFData Satoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Methods

rnf :: Satoshi -> () #

Generic Satoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Associated Types

type Rep Satoshi 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

type Rep Satoshi = D1 ('MetaData "Satoshi" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'True) (C1 ('MetaCons "Satoshi" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))

Methods

from :: Satoshi -> Rep Satoshi x #

to :: Rep Satoshi x -> Satoshi #

Show Satoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Eq Satoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Methods

(==) :: Satoshi -> Satoshi -> Bool #

(/=) :: Satoshi -> Satoshi -> Bool #

Ord Satoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

type Rep Satoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

type Rep Satoshi = D1 ('MetaData "Satoshi" "Lightning.Protocol.BOLT1.Prim" "ppad-bolt1-0.1.0-DFeKxZAwFttB3XUhlbwxvP" 'True) (C1 ('MetaCons "Satoshi" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))

satoshi :: Word64 -> Maybe Satoshi Source #

Construct a Satoshi amount, failing above 21 million BTC.

>>> satoshi 1000
Just (Satoshi 1000)
>>> satoshi 0xffffffffffffffff
Nothing

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

Instances details
NFData MilliSatoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Methods

rnf :: MilliSatoshi -> () #

Generic MilliSatoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Associated Types

type Rep MilliSatoshi 
Instance details

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)))
Show MilliSatoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Eq MilliSatoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

Ord MilliSatoshi Source # 
Instance details

Defined in Lightning.Protocol.BOLT1.Prim

type Rep MilliSatoshi Source # 
Instance details

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_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.

decode_milli_satoshi :: ByteString -> Maybe (MilliSatoshi, ByteString) Source #

Decode a u64 MilliSatoshi amount, returning the remaining input. Fails above 21 million BTC.