{-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE DeriveGeneric #-}
module Lightning.Protocol.BOLT1.Message (
Init(..)
, Error(..)
, Warning(..)
, Ping(..)
, Pong(..)
, PeerStorage(..)
, PeerStorageRetrieval(..)
, Message(..)
, message_type
) where
import Control.DeepSeq (NFData)
import qualified Data.ByteString as BS
import Data.Word (Word16)
import GHC.Generics (Generic)
import Lightning.Protocol.BOLT1.Prim
import Lightning.Protocol.BOLT1.TLV
import qualified Lightning.Protocol.BOLT9 as BOLT9
data Init = Init
{ Init -> FeatureVector
init_global_features :: !BOLT9.FeatureVector
, Init -> FeatureVector
init_features :: !BOLT9.FeatureVector
, Init -> Maybe [ChainHash]
init_networks :: !(Maybe [ChainHash])
, Init -> Maybe ByteString
init_remote_addr :: !(Maybe BS.ByteString)
, Init -> TlvStream
init_tlvs :: !TlvStream
} deriving (Init -> Init -> Bool
(Init -> Init -> Bool) -> (Init -> Init -> Bool) -> Eq Init
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Init -> Init -> Bool
== :: Init -> Init -> Bool
$c/= :: Init -> Init -> Bool
/= :: Init -> Init -> Bool
Eq, Int -> Init -> ShowS
[Init] -> ShowS
Init -> String
(Int -> Init -> ShowS)
-> (Init -> String) -> ([Init] -> ShowS) -> Show Init
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Init -> ShowS
showsPrec :: Int -> Init -> ShowS
$cshow :: Init -> String
show :: Init -> String
$cshowList :: [Init] -> ShowS
showList :: [Init] -> ShowS
Show, (forall x. Init -> Rep Init x)
-> (forall x. Rep Init x -> Init) -> Generic Init
forall x. Rep Init x -> Init
forall x. Init -> Rep Init x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Init -> Rep Init x
from :: forall x. Init -> Rep Init x
$cto :: forall x. Rep Init x -> Init
to :: forall x. Rep Init x -> Init
Generic)
instance NFData Init
data Error = Error
{ Error -> ChannelId
error_channel_id :: !ChannelId
, Error -> ByteString
error_data :: !BS.ByteString
, Error -> TlvStream
error_tlvs :: !TlvStream
} deriving (Error -> Error -> Bool
(Error -> Error -> Bool) -> (Error -> Error -> Bool) -> Eq Error
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Error -> Error -> Bool
== :: Error -> Error -> Bool
$c/= :: Error -> Error -> Bool
/= :: Error -> Error -> Bool
Eq, Int -> Error -> ShowS
[Error] -> ShowS
Error -> String
(Int -> Error -> ShowS)
-> (Error -> String) -> ([Error] -> ShowS) -> Show Error
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Error -> ShowS
showsPrec :: Int -> Error -> ShowS
$cshow :: Error -> String
show :: Error -> String
$cshowList :: [Error] -> ShowS
showList :: [Error] -> ShowS
Show, (forall x. Error -> Rep Error x)
-> (forall x. Rep Error x -> Error) -> Generic Error
forall x. Rep Error x -> Error
forall x. Error -> Rep Error x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Error -> Rep Error x
from :: forall x. Error -> Rep Error x
$cto :: forall x. Rep Error x -> Error
to :: forall x. Rep Error x -> Error
Generic)
instance NFData Error
data Warning = Warning
{ Warning -> ChannelId
warning_channel_id :: !ChannelId
, Warning -> ByteString
warning_data :: !BS.ByteString
, Warning -> TlvStream
warning_tlvs :: !TlvStream
} deriving (Warning -> Warning -> Bool
(Warning -> Warning -> Bool)
-> (Warning -> Warning -> Bool) -> Eq Warning
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Warning -> Warning -> Bool
== :: Warning -> Warning -> Bool
$c/= :: Warning -> Warning -> Bool
/= :: Warning -> Warning -> Bool
Eq, Int -> Warning -> ShowS
[Warning] -> ShowS
Warning -> String
(Int -> Warning -> ShowS)
-> (Warning -> String) -> ([Warning] -> ShowS) -> Show Warning
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Warning -> ShowS
showsPrec :: Int -> Warning -> ShowS
$cshow :: Warning -> String
show :: Warning -> String
$cshowList :: [Warning] -> ShowS
showList :: [Warning] -> ShowS
Show, (forall x. Warning -> Rep Warning x)
-> (forall x. Rep Warning x -> Warning) -> Generic Warning
forall x. Rep Warning x -> Warning
forall x. Warning -> Rep Warning x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Warning -> Rep Warning x
from :: forall x. Warning -> Rep Warning x
$cto :: forall x. Rep Warning x -> Warning
to :: forall x. Rep Warning x -> Warning
Generic)
instance NFData Warning
data Ping = Ping
{ Ping -> Word16
ping_num_pong_bytes :: {-# UNPACK #-} !Word16
, Ping -> ByteString
ping_ignored :: !BS.ByteString
, Ping -> TlvStream
ping_tlvs :: !TlvStream
} deriving (Ping -> Ping -> Bool
(Ping -> Ping -> Bool) -> (Ping -> Ping -> Bool) -> Eq Ping
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Ping -> Ping -> Bool
== :: Ping -> Ping -> Bool
$c/= :: Ping -> Ping -> Bool
/= :: Ping -> Ping -> Bool
Eq, Int -> Ping -> ShowS
[Ping] -> ShowS
Ping -> String
(Int -> Ping -> ShowS)
-> (Ping -> String) -> ([Ping] -> ShowS) -> Show Ping
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Ping -> ShowS
showsPrec :: Int -> Ping -> ShowS
$cshow :: Ping -> String
show :: Ping -> String
$cshowList :: [Ping] -> ShowS
showList :: [Ping] -> ShowS
Show, (forall x. Ping -> Rep Ping x)
-> (forall x. Rep Ping x -> Ping) -> Generic Ping
forall x. Rep Ping x -> Ping
forall x. Ping -> Rep Ping x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Ping -> Rep Ping x
from :: forall x. Ping -> Rep Ping x
$cto :: forall x. Rep Ping x -> Ping
to :: forall x. Rep Ping x -> Ping
Generic)
instance NFData Ping
data Pong = Pong
{ Pong -> ByteString
pong_ignored :: !BS.ByteString
, Pong -> TlvStream
pong_tlvs :: !TlvStream
} deriving (Pong -> Pong -> Bool
(Pong -> Pong -> Bool) -> (Pong -> Pong -> Bool) -> Eq Pong
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Pong -> Pong -> Bool
== :: Pong -> Pong -> Bool
$c/= :: Pong -> Pong -> Bool
/= :: Pong -> Pong -> Bool
Eq, Int -> Pong -> ShowS
[Pong] -> ShowS
Pong -> String
(Int -> Pong -> ShowS)
-> (Pong -> String) -> ([Pong] -> ShowS) -> Show Pong
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Pong -> ShowS
showsPrec :: Int -> Pong -> ShowS
$cshow :: Pong -> String
show :: Pong -> String
$cshowList :: [Pong] -> ShowS
showList :: [Pong] -> ShowS
Show, (forall x. Pong -> Rep Pong x)
-> (forall x. Rep Pong x -> Pong) -> Generic Pong
forall x. Rep Pong x -> Pong
forall x. Pong -> Rep Pong x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Pong -> Rep Pong x
from :: forall x. Pong -> Rep Pong x
$cto :: forall x. Rep Pong x -> Pong
to :: forall x. Rep Pong x -> Pong
Generic)
instance NFData Pong
data PeerStorage = PeerStorage
{ PeerStorage -> ByteString
peer_storage_blob :: !BS.ByteString
, PeerStorage -> TlvStream
peer_storage_tlvs :: !TlvStream
} deriving (PeerStorage -> PeerStorage -> Bool
(PeerStorage -> PeerStorage -> Bool)
-> (PeerStorage -> PeerStorage -> Bool) -> Eq PeerStorage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PeerStorage -> PeerStorage -> Bool
== :: PeerStorage -> PeerStorage -> Bool
$c/= :: PeerStorage -> PeerStorage -> Bool
/= :: PeerStorage -> PeerStorage -> Bool
Eq, Int -> PeerStorage -> ShowS
[PeerStorage] -> ShowS
PeerStorage -> String
(Int -> PeerStorage -> ShowS)
-> (PeerStorage -> String)
-> ([PeerStorage] -> ShowS)
-> Show PeerStorage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PeerStorage -> ShowS
showsPrec :: Int -> PeerStorage -> ShowS
$cshow :: PeerStorage -> String
show :: PeerStorage -> String
$cshowList :: [PeerStorage] -> ShowS
showList :: [PeerStorage] -> ShowS
Show, (forall x. PeerStorage -> Rep PeerStorage x)
-> (forall x. Rep PeerStorage x -> PeerStorage)
-> Generic PeerStorage
forall x. Rep PeerStorage x -> PeerStorage
forall x. PeerStorage -> Rep PeerStorage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PeerStorage -> Rep PeerStorage x
from :: forall x. PeerStorage -> Rep PeerStorage x
$cto :: forall x. Rep PeerStorage x -> PeerStorage
to :: forall x. Rep PeerStorage x -> PeerStorage
Generic)
instance NFData PeerStorage
data PeerStorageRetrieval = PeerStorageRetrieval
{ PeerStorageRetrieval -> ByteString
peer_storage_retrieval_blob :: !BS.ByteString
, PeerStorageRetrieval -> TlvStream
peer_storage_retrieval_tlvs :: !TlvStream
} deriving (PeerStorageRetrieval -> PeerStorageRetrieval -> Bool
(PeerStorageRetrieval -> PeerStorageRetrieval -> Bool)
-> (PeerStorageRetrieval -> PeerStorageRetrieval -> Bool)
-> Eq PeerStorageRetrieval
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PeerStorageRetrieval -> PeerStorageRetrieval -> Bool
== :: PeerStorageRetrieval -> PeerStorageRetrieval -> Bool
$c/= :: PeerStorageRetrieval -> PeerStorageRetrieval -> Bool
/= :: PeerStorageRetrieval -> PeerStorageRetrieval -> Bool
Eq, Int -> PeerStorageRetrieval -> ShowS
[PeerStorageRetrieval] -> ShowS
PeerStorageRetrieval -> String
(Int -> PeerStorageRetrieval -> ShowS)
-> (PeerStorageRetrieval -> String)
-> ([PeerStorageRetrieval] -> ShowS)
-> Show PeerStorageRetrieval
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PeerStorageRetrieval -> ShowS
showsPrec :: Int -> PeerStorageRetrieval -> ShowS
$cshow :: PeerStorageRetrieval -> String
show :: PeerStorageRetrieval -> String
$cshowList :: [PeerStorageRetrieval] -> ShowS
showList :: [PeerStorageRetrieval] -> ShowS
Show, (forall x. PeerStorageRetrieval -> Rep PeerStorageRetrieval x)
-> (forall x. Rep PeerStorageRetrieval x -> PeerStorageRetrieval)
-> Generic PeerStorageRetrieval
forall x. Rep PeerStorageRetrieval x -> PeerStorageRetrieval
forall x. PeerStorageRetrieval -> Rep PeerStorageRetrieval x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PeerStorageRetrieval -> Rep PeerStorageRetrieval x
from :: forall x. PeerStorageRetrieval -> Rep PeerStorageRetrieval x
$cto :: forall x. Rep PeerStorageRetrieval x -> PeerStorageRetrieval
to :: forall x. Rep PeerStorageRetrieval x -> PeerStorageRetrieval
Generic)
instance NFData PeerStorageRetrieval
data Message
= MsgInit !Init
| MsgError !Error
| MsgWarning !Warning
| MsgPing !Ping
| MsgPong !Pong
| MsgPeerStorage !PeerStorage
| MsgPeerStorageRetrieval !PeerStorageRetrieval
deriving (Message -> Message -> Bool
(Message -> Message -> Bool)
-> (Message -> Message -> Bool) -> Eq Message
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Message -> Message -> Bool
== :: Message -> Message -> Bool
$c/= :: Message -> Message -> Bool
/= :: Message -> Message -> Bool
Eq, Int -> Message -> ShowS
[Message] -> ShowS
Message -> String
(Int -> Message -> ShowS)
-> (Message -> String) -> ([Message] -> ShowS) -> Show Message
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Message -> ShowS
showsPrec :: Int -> Message -> ShowS
$cshow :: Message -> String
show :: Message -> String
$cshowList :: [Message] -> ShowS
showList :: [Message] -> ShowS
Show, (forall x. Message -> Rep Message x)
-> (forall x. Rep Message x -> Message) -> Generic Message
forall x. Rep Message x -> Message
forall x. Message -> Rep Message x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Message -> Rep Message x
from :: forall x. Message -> Rep Message x
$cto :: forall x. Rep Message x -> Message
to :: forall x. Rep Message x -> Message
Generic)
instance NFData Message
message_type :: Message -> Word16
message_type :: Message -> Word16
message_type Message
m = case Message
m of
MsgInit {} -> Word16
16
MsgError {} -> Word16
17
MsgWarning {} -> Word16
1
MsgPing {} -> Word16
18
MsgPong {} -> Word16
19
MsgPeerStorage {} -> Word16
7
MsgPeerStorageRetrieval {} -> Word16
9