{-# LANGUAGE UndecidableInstances #-}

module Hydra.Network.Message where

import Hydra.Prelude

import Cardano.Binary (serialize')
import Cardano.Crypto.Util (SignableRepresentation, getSignableRepresentation)
import Hydra.Network (Host, NodeId)
import Hydra.Tx (
  IsTx (TxIdType),
  Party,
  Snapshot,
  SnapshotNumber,
  SnapshotVersion,
  UTxOType,
 )
import Hydra.Tx.Crypto (Signature)
import Hydra.Tx.IsTx (ArbitraryIsTx)

data NetworkEvent msg
  = ConnectivityEvent Connectivity
  | ReceivedMessage {forall msg. NetworkEvent msg -> Party
sender :: Party, forall msg. NetworkEvent msg -> msg
msg :: msg}
  deriving stock (NetworkEvent msg -> NetworkEvent msg -> Bool
(NetworkEvent msg -> NetworkEvent msg -> Bool)
-> (NetworkEvent msg -> NetworkEvent msg -> Bool)
-> Eq (NetworkEvent msg)
forall msg. Eq msg => NetworkEvent msg -> NetworkEvent msg -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall msg. Eq msg => NetworkEvent msg -> NetworkEvent msg -> Bool
== :: NetworkEvent msg -> NetworkEvent msg -> Bool
$c/= :: forall msg. Eq msg => NetworkEvent msg -> NetworkEvent msg -> Bool
/= :: NetworkEvent msg -> NetworkEvent msg -> Bool
Eq, Int -> NetworkEvent msg -> ShowS
[NetworkEvent msg] -> ShowS
NetworkEvent msg -> String
(Int -> NetworkEvent msg -> ShowS)
-> (NetworkEvent msg -> String)
-> ([NetworkEvent msg] -> ShowS)
-> Show (NetworkEvent msg)
forall msg. Show msg => Int -> NetworkEvent msg -> ShowS
forall msg. Show msg => [NetworkEvent msg] -> ShowS
forall msg. Show msg => NetworkEvent msg -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall msg. Show msg => Int -> NetworkEvent msg -> ShowS
showsPrec :: Int -> NetworkEvent msg -> ShowS
$cshow :: forall msg. Show msg => NetworkEvent msg -> String
show :: NetworkEvent msg -> String
$cshowList :: forall msg. Show msg => [NetworkEvent msg] -> ShowS
showList :: [NetworkEvent msg] -> ShowS
Show, (forall x. NetworkEvent msg -> Rep (NetworkEvent msg) x)
-> (forall x. Rep (NetworkEvent msg) x -> NetworkEvent msg)
-> Generic (NetworkEvent msg)
forall x. Rep (NetworkEvent msg) x -> NetworkEvent msg
forall x. NetworkEvent msg -> Rep (NetworkEvent msg) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall msg x. Rep (NetworkEvent msg) x -> NetworkEvent msg
forall msg x. NetworkEvent msg -> Rep (NetworkEvent msg) x
$cfrom :: forall msg x. NetworkEvent msg -> Rep (NetworkEvent msg) x
from :: forall x. NetworkEvent msg -> Rep (NetworkEvent msg) x
$cto :: forall msg x. Rep (NetworkEvent msg) x -> NetworkEvent msg
to :: forall x. Rep (NetworkEvent msg) x -> NetworkEvent msg
Generic)
  deriving anyclass ([NetworkEvent msg] -> Value
[NetworkEvent msg] -> Encoding
NetworkEvent msg -> Bool
NetworkEvent msg -> Value
NetworkEvent msg -> Encoding
(NetworkEvent msg -> Value)
-> (NetworkEvent msg -> Encoding)
-> ([NetworkEvent msg] -> Value)
-> ([NetworkEvent msg] -> Encoding)
-> (NetworkEvent msg -> Bool)
-> ToJSON (NetworkEvent msg)
forall msg. ToJSON msg => [NetworkEvent msg] -> Value
forall msg. ToJSON msg => [NetworkEvent msg] -> Encoding
forall msg. ToJSON msg => NetworkEvent msg -> Bool
forall msg. ToJSON msg => NetworkEvent msg -> Value
forall msg. ToJSON msg => NetworkEvent msg -> Encoding
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: forall msg. ToJSON msg => NetworkEvent msg -> Value
toJSON :: NetworkEvent msg -> Value
$ctoEncoding :: forall msg. ToJSON msg => NetworkEvent msg -> Encoding
toEncoding :: NetworkEvent msg -> Encoding
$ctoJSONList :: forall msg. ToJSON msg => [NetworkEvent msg] -> Value
toJSONList :: [NetworkEvent msg] -> Value
$ctoEncodingList :: forall msg. ToJSON msg => [NetworkEvent msg] -> Encoding
toEncodingList :: [NetworkEvent msg] -> Encoding
$comitField :: forall msg. ToJSON msg => NetworkEvent msg -> Bool
omitField :: NetworkEvent msg -> Bool
ToJSON, Maybe (NetworkEvent msg)
Value -> Parser [NetworkEvent msg]
Value -> Parser (NetworkEvent msg)
(Value -> Parser (NetworkEvent msg))
-> (Value -> Parser [NetworkEvent msg])
-> Maybe (NetworkEvent msg)
-> FromJSON (NetworkEvent msg)
forall msg. FromJSON msg => Maybe (NetworkEvent msg)
forall msg. FromJSON msg => Value -> Parser [NetworkEvent msg]
forall msg. FromJSON msg => Value -> Parser (NetworkEvent msg)
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: forall msg. FromJSON msg => Value -> Parser (NetworkEvent msg)
parseJSON :: Value -> Parser (NetworkEvent msg)
$cparseJSONList :: forall msg. FromJSON msg => Value -> Parser [NetworkEvent msg]
parseJSONList :: Value -> Parser [NetworkEvent msg]
$comittedField :: forall msg. FromJSON msg => Maybe (NetworkEvent msg)
omittedField :: Maybe (NetworkEvent msg)
FromJSON)

instance Arbitrary msg => Arbitrary (NetworkEvent msg) where
  arbitrary :: Gen (NetworkEvent msg)
arbitrary = Gen (NetworkEvent msg)
forall a.
(Generic a, GA UnsizedOpts (Rep a),
 UniformWeight (Weights_ (Rep a))) =>
Gen a
genericArbitrary

type HydraVersionedProtocolNumber :: Type
newtype HydraVersionedProtocolNumber = MkHydraVersionedProtocolNumber {HydraVersionedProtocolNumber -> Nat
hydraVersionedProtocolNumber :: Natural}
  deriving stock (HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Bool
(HydraVersionedProtocolNumber
 -> HydraVersionedProtocolNumber -> Bool)
-> (HydraVersionedProtocolNumber
    -> HydraVersionedProtocolNumber -> Bool)
-> Eq HydraVersionedProtocolNumber
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Bool
== :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Bool
$c/= :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Bool
/= :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Bool
Eq, Int -> HydraVersionedProtocolNumber -> ShowS
[HydraVersionedProtocolNumber] -> ShowS
HydraVersionedProtocolNumber -> String
(Int -> HydraVersionedProtocolNumber -> ShowS)
-> (HydraVersionedProtocolNumber -> String)
-> ([HydraVersionedProtocolNumber] -> ShowS)
-> Show HydraVersionedProtocolNumber
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HydraVersionedProtocolNumber -> ShowS
showsPrec :: Int -> HydraVersionedProtocolNumber -> ShowS
$cshow :: HydraVersionedProtocolNumber -> String
show :: HydraVersionedProtocolNumber -> String
$cshowList :: [HydraVersionedProtocolNumber] -> ShowS
showList :: [HydraVersionedProtocolNumber] -> ShowS
Show, (forall x.
 HydraVersionedProtocolNumber -> Rep HydraVersionedProtocolNumber x)
-> (forall x.
    Rep HydraVersionedProtocolNumber x -> HydraVersionedProtocolNumber)
-> Generic HydraVersionedProtocolNumber
forall x.
Rep HydraVersionedProtocolNumber x -> HydraVersionedProtocolNumber
forall x.
HydraVersionedProtocolNumber -> Rep HydraVersionedProtocolNumber x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x.
HydraVersionedProtocolNumber -> Rep HydraVersionedProtocolNumber x
from :: forall x.
HydraVersionedProtocolNumber -> Rep HydraVersionedProtocolNumber x
$cto :: forall x.
Rep HydraVersionedProtocolNumber x -> HydraVersionedProtocolNumber
to :: forall x.
Rep HydraVersionedProtocolNumber x -> HydraVersionedProtocolNumber
Generic, Eq HydraVersionedProtocolNumber
Eq HydraVersionedProtocolNumber =>
(HydraVersionedProtocolNumber
 -> HydraVersionedProtocolNumber -> Ordering)
-> (HydraVersionedProtocolNumber
    -> HydraVersionedProtocolNumber -> Bool)
-> (HydraVersionedProtocolNumber
    -> HydraVersionedProtocolNumber -> Bool)
-> (HydraVersionedProtocolNumber
    -> HydraVersionedProtocolNumber -> Bool)
-> (HydraVersionedProtocolNumber
    -> HydraVersionedProtocolNumber -> Bool)
-> (HydraVersionedProtocolNumber
    -> HydraVersionedProtocolNumber -> HydraVersionedProtocolNumber)
-> (HydraVersionedProtocolNumber
    -> HydraVersionedProtocolNumber -> HydraVersionedProtocolNumber)
-> Ord HydraVersionedProtocolNumber
HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Bool
HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Ordering
HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> HydraVersionedProtocolNumber
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Ordering
compare :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Ordering
$c< :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Bool
< :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Bool
$c<= :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Bool
<= :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Bool
$c> :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Bool
> :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Bool
$c>= :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Bool
>= :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> Bool
$cmax :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> HydraVersionedProtocolNumber
max :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> HydraVersionedProtocolNumber
$cmin :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> HydraVersionedProtocolNumber
min :: HydraVersionedProtocolNumber
-> HydraVersionedProtocolNumber -> HydraVersionedProtocolNumber
Ord)
  deriving anyclass ([HydraVersionedProtocolNumber] -> Value
[HydraVersionedProtocolNumber] -> Encoding
HydraVersionedProtocolNumber -> Bool
HydraVersionedProtocolNumber -> Value
HydraVersionedProtocolNumber -> Encoding
(HydraVersionedProtocolNumber -> Value)
-> (HydraVersionedProtocolNumber -> Encoding)
-> ([HydraVersionedProtocolNumber] -> Value)
-> ([HydraVersionedProtocolNumber] -> Encoding)
-> (HydraVersionedProtocolNumber -> Bool)
-> ToJSON HydraVersionedProtocolNumber
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: HydraVersionedProtocolNumber -> Value
toJSON :: HydraVersionedProtocolNumber -> Value
$ctoEncoding :: HydraVersionedProtocolNumber -> Encoding
toEncoding :: HydraVersionedProtocolNumber -> Encoding
$ctoJSONList :: [HydraVersionedProtocolNumber] -> Value
toJSONList :: [HydraVersionedProtocolNumber] -> Value
$ctoEncodingList :: [HydraVersionedProtocolNumber] -> Encoding
toEncodingList :: [HydraVersionedProtocolNumber] -> Encoding
$comitField :: HydraVersionedProtocolNumber -> Bool
omitField :: HydraVersionedProtocolNumber -> Bool
ToJSON, Maybe HydraVersionedProtocolNumber
Value -> Parser [HydraVersionedProtocolNumber]
Value -> Parser HydraVersionedProtocolNumber
(Value -> Parser HydraVersionedProtocolNumber)
-> (Value -> Parser [HydraVersionedProtocolNumber])
-> Maybe HydraVersionedProtocolNumber
-> FromJSON HydraVersionedProtocolNumber
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser HydraVersionedProtocolNumber
parseJSON :: Value -> Parser HydraVersionedProtocolNumber
$cparseJSONList :: Value -> Parser [HydraVersionedProtocolNumber]
parseJSONList :: Value -> Parser [HydraVersionedProtocolNumber]
$comittedField :: Maybe HydraVersionedProtocolNumber
omittedField :: Maybe HydraVersionedProtocolNumber
FromJSON)

instance Arbitrary HydraVersionedProtocolNumber where
  arbitrary :: Gen HydraVersionedProtocolNumber
arbitrary = Gen HydraVersionedProtocolNumber
forall a.
(Generic a, GA UnsizedOpts (Rep a),
 UniformWeight (Weights_ (Rep a))) =>
Gen a
genericArbitrary

type KnownHydraVersions :: Type
data KnownHydraVersions
  = KnownHydraVersions {KnownHydraVersions -> [HydraVersionedProtocolNumber]
fromKnownHydraVersions :: [HydraVersionedProtocolNumber]}
  | NoKnownHydraVersions
  deriving stock (KnownHydraVersions -> KnownHydraVersions -> Bool
(KnownHydraVersions -> KnownHydraVersions -> Bool)
-> (KnownHydraVersions -> KnownHydraVersions -> Bool)
-> Eq KnownHydraVersions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: KnownHydraVersions -> KnownHydraVersions -> Bool
== :: KnownHydraVersions -> KnownHydraVersions -> Bool
$c/= :: KnownHydraVersions -> KnownHydraVersions -> Bool
/= :: KnownHydraVersions -> KnownHydraVersions -> Bool
Eq, Int -> KnownHydraVersions -> ShowS
[KnownHydraVersions] -> ShowS
KnownHydraVersions -> String
(Int -> KnownHydraVersions -> ShowS)
-> (KnownHydraVersions -> String)
-> ([KnownHydraVersions] -> ShowS)
-> Show KnownHydraVersions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> KnownHydraVersions -> ShowS
showsPrec :: Int -> KnownHydraVersions -> ShowS
$cshow :: KnownHydraVersions -> String
show :: KnownHydraVersions -> String
$cshowList :: [KnownHydraVersions] -> ShowS
showList :: [KnownHydraVersions] -> ShowS
Show, (forall x. KnownHydraVersions -> Rep KnownHydraVersions x)
-> (forall x. Rep KnownHydraVersions x -> KnownHydraVersions)
-> Generic KnownHydraVersions
forall x. Rep KnownHydraVersions x -> KnownHydraVersions
forall x. KnownHydraVersions -> Rep KnownHydraVersions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. KnownHydraVersions -> Rep KnownHydraVersions x
from :: forall x. KnownHydraVersions -> Rep KnownHydraVersions x
$cto :: forall x. Rep KnownHydraVersions x -> KnownHydraVersions
to :: forall x. Rep KnownHydraVersions x -> KnownHydraVersions
Generic)
  deriving anyclass ([KnownHydraVersions] -> Value
[KnownHydraVersions] -> Encoding
KnownHydraVersions -> Bool
KnownHydraVersions -> Value
KnownHydraVersions -> Encoding
(KnownHydraVersions -> Value)
-> (KnownHydraVersions -> Encoding)
-> ([KnownHydraVersions] -> Value)
-> ([KnownHydraVersions] -> Encoding)
-> (KnownHydraVersions -> Bool)
-> ToJSON KnownHydraVersions
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: KnownHydraVersions -> Value
toJSON :: KnownHydraVersions -> Value
$ctoEncoding :: KnownHydraVersions -> Encoding
toEncoding :: KnownHydraVersions -> Encoding
$ctoJSONList :: [KnownHydraVersions] -> Value
toJSONList :: [KnownHydraVersions] -> Value
$ctoEncodingList :: [KnownHydraVersions] -> Encoding
toEncodingList :: [KnownHydraVersions] -> Encoding
$comitField :: KnownHydraVersions -> Bool
omitField :: KnownHydraVersions -> Bool
ToJSON, Maybe KnownHydraVersions
Value -> Parser [KnownHydraVersions]
Value -> Parser KnownHydraVersions
(Value -> Parser KnownHydraVersions)
-> (Value -> Parser [KnownHydraVersions])
-> Maybe KnownHydraVersions
-> FromJSON KnownHydraVersions
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser KnownHydraVersions
parseJSON :: Value -> Parser KnownHydraVersions
$cparseJSONList :: Value -> Parser [KnownHydraVersions]
parseJSONList :: Value -> Parser [KnownHydraVersions]
$comittedField :: Maybe KnownHydraVersions
omittedField :: Maybe KnownHydraVersions
FromJSON)

instance Arbitrary KnownHydraVersions where
  arbitrary :: Gen KnownHydraVersions
arbitrary = Gen KnownHydraVersions
forall a.
(Generic a, GA UnsizedOpts (Rep a),
 UniformWeight (Weights_ (Rep a))) =>
Gen a
genericArbitrary

type HydraHandshakeRefused :: Type
data HydraHandshakeRefused = HydraHandshakeRefused
  { HydraHandshakeRefused -> Host
remoteHost :: Host
  , HydraHandshakeRefused -> HydraVersionedProtocolNumber
ourVersion :: HydraVersionedProtocolNumber
  , HydraHandshakeRefused -> KnownHydraVersions
theirVersions :: KnownHydraVersions
  }
  deriving stock (HydraHandshakeRefused -> HydraHandshakeRefused -> Bool
(HydraHandshakeRefused -> HydraHandshakeRefused -> Bool)
-> (HydraHandshakeRefused -> HydraHandshakeRefused -> Bool)
-> Eq HydraHandshakeRefused
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HydraHandshakeRefused -> HydraHandshakeRefused -> Bool
== :: HydraHandshakeRefused -> HydraHandshakeRefused -> Bool
$c/= :: HydraHandshakeRefused -> HydraHandshakeRefused -> Bool
/= :: HydraHandshakeRefused -> HydraHandshakeRefused -> Bool
Eq, Int -> HydraHandshakeRefused -> ShowS
[HydraHandshakeRefused] -> ShowS
HydraHandshakeRefused -> String
(Int -> HydraHandshakeRefused -> ShowS)
-> (HydraHandshakeRefused -> String)
-> ([HydraHandshakeRefused] -> ShowS)
-> Show HydraHandshakeRefused
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HydraHandshakeRefused -> ShowS
showsPrec :: Int -> HydraHandshakeRefused -> ShowS
$cshow :: HydraHandshakeRefused -> String
show :: HydraHandshakeRefused -> String
$cshowList :: [HydraHandshakeRefused] -> ShowS
showList :: [HydraHandshakeRefused] -> ShowS
Show, (forall x. HydraHandshakeRefused -> Rep HydraHandshakeRefused x)
-> (forall x. Rep HydraHandshakeRefused x -> HydraHandshakeRefused)
-> Generic HydraHandshakeRefused
forall x. Rep HydraHandshakeRefused x -> HydraHandshakeRefused
forall x. HydraHandshakeRefused -> Rep HydraHandshakeRefused x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HydraHandshakeRefused -> Rep HydraHandshakeRefused x
from :: forall x. HydraHandshakeRefused -> Rep HydraHandshakeRefused x
$cto :: forall x. Rep HydraHandshakeRefused x -> HydraHandshakeRefused
to :: forall x. Rep HydraHandshakeRefused x -> HydraHandshakeRefused
Generic)
  deriving anyclass ([HydraHandshakeRefused] -> Value
[HydraHandshakeRefused] -> Encoding
HydraHandshakeRefused -> Bool
HydraHandshakeRefused -> Value
HydraHandshakeRefused -> Encoding
(HydraHandshakeRefused -> Value)
-> (HydraHandshakeRefused -> Encoding)
-> ([HydraHandshakeRefused] -> Value)
-> ([HydraHandshakeRefused] -> Encoding)
-> (HydraHandshakeRefused -> Bool)
-> ToJSON HydraHandshakeRefused
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: HydraHandshakeRefused -> Value
toJSON :: HydraHandshakeRefused -> Value
$ctoEncoding :: HydraHandshakeRefused -> Encoding
toEncoding :: HydraHandshakeRefused -> Encoding
$ctoJSONList :: [HydraHandshakeRefused] -> Value
toJSONList :: [HydraHandshakeRefused] -> Value
$ctoEncodingList :: [HydraHandshakeRefused] -> Encoding
toEncodingList :: [HydraHandshakeRefused] -> Encoding
$comitField :: HydraHandshakeRefused -> Bool
omitField :: HydraHandshakeRefused -> Bool
ToJSON, Maybe HydraHandshakeRefused
Value -> Parser [HydraHandshakeRefused]
Value -> Parser HydraHandshakeRefused
(Value -> Parser HydraHandshakeRefused)
-> (Value -> Parser [HydraHandshakeRefused])
-> Maybe HydraHandshakeRefused
-> FromJSON HydraHandshakeRefused
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser HydraHandshakeRefused
parseJSON :: Value -> Parser HydraHandshakeRefused
$cparseJSONList :: Value -> Parser [HydraHandshakeRefused]
parseJSONList :: Value -> Parser [HydraHandshakeRefused]
$comittedField :: Maybe HydraHandshakeRefused
omittedField :: Maybe HydraHandshakeRefused
FromJSON)

instance Arbitrary HydraHandshakeRefused where
  arbitrary :: Gen HydraHandshakeRefused
arbitrary = Gen HydraHandshakeRefused
forall a.
(Generic a, GA UnsizedOpts (Rep a),
 UniformWeight (Weights_ (Rep a))) =>
Gen a
genericArbitrary

data Connectivity
  = Connected {Connectivity -> NodeId
nodeId :: NodeId}
  | Disconnected {nodeId :: NodeId}
  | HandshakeFailure
      { Connectivity -> Host
remoteHost :: Host
      , Connectivity -> HydraVersionedProtocolNumber
ourVersion :: HydraVersionedProtocolNumber
      , Connectivity -> KnownHydraVersions
theirVersions :: KnownHydraVersions
      }
  deriving stock ((forall x. Connectivity -> Rep Connectivity x)
-> (forall x. Rep Connectivity x -> Connectivity)
-> Generic Connectivity
forall x. Rep Connectivity x -> Connectivity
forall x. Connectivity -> Rep Connectivity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Connectivity -> Rep Connectivity x
from :: forall x. Connectivity -> Rep Connectivity x
$cto :: forall x. Rep Connectivity x -> Connectivity
to :: forall x. Rep Connectivity x -> Connectivity
Generic, Connectivity -> Connectivity -> Bool
(Connectivity -> Connectivity -> Bool)
-> (Connectivity -> Connectivity -> Bool) -> Eq Connectivity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Connectivity -> Connectivity -> Bool
== :: Connectivity -> Connectivity -> Bool
$c/= :: Connectivity -> Connectivity -> Bool
/= :: Connectivity -> Connectivity -> Bool
Eq, Int -> Connectivity -> ShowS
[Connectivity] -> ShowS
Connectivity -> String
(Int -> Connectivity -> ShowS)
-> (Connectivity -> String)
-> ([Connectivity] -> ShowS)
-> Show Connectivity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Connectivity -> ShowS
showsPrec :: Int -> Connectivity -> ShowS
$cshow :: Connectivity -> String
show :: Connectivity -> String
$cshowList :: [Connectivity] -> ShowS
showList :: [Connectivity] -> ShowS
Show)
  deriving anyclass ([Connectivity] -> Value
[Connectivity] -> Encoding
Connectivity -> Bool
Connectivity -> Value
Connectivity -> Encoding
(Connectivity -> Value)
-> (Connectivity -> Encoding)
-> ([Connectivity] -> Value)
-> ([Connectivity] -> Encoding)
-> (Connectivity -> Bool)
-> ToJSON Connectivity
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Connectivity -> Value
toJSON :: Connectivity -> Value
$ctoEncoding :: Connectivity -> Encoding
toEncoding :: Connectivity -> Encoding
$ctoJSONList :: [Connectivity] -> Value
toJSONList :: [Connectivity] -> Value
$ctoEncodingList :: [Connectivity] -> Encoding
toEncodingList :: [Connectivity] -> Encoding
$comitField :: Connectivity -> Bool
omitField :: Connectivity -> Bool
ToJSON, Maybe Connectivity
Value -> Parser [Connectivity]
Value -> Parser Connectivity
(Value -> Parser Connectivity)
-> (Value -> Parser [Connectivity])
-> Maybe Connectivity
-> FromJSON Connectivity
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Connectivity
parseJSON :: Value -> Parser Connectivity
$cparseJSONList :: Value -> Parser [Connectivity]
parseJSONList :: Value -> Parser [Connectivity]
$comittedField :: Maybe Connectivity
omittedField :: Maybe Connectivity
FromJSON)

instance Arbitrary Connectivity where
  arbitrary :: Gen Connectivity
arbitrary = Gen Connectivity
forall a.
(Generic a, GA UnsizedOpts (Rep a),
 UniformWeight (Weights_ (Rep a))) =>
Gen a
genericArbitrary

data Message tx
  = ReqTx {forall tx. Message tx -> tx
transaction :: tx}
  | ReqSn
      { forall tx. Message tx -> SnapshotVersion
snapshotVersion :: SnapshotVersion
      , forall tx. Message tx -> SnapshotNumber
snapshotNumber :: SnapshotNumber
      , forall tx. Message tx -> [TxIdType tx]
transactionIds :: [TxIdType tx]
      , forall tx. Message tx -> Maybe tx
decommitTx :: Maybe tx
      , forall tx. Message tx -> Maybe (UTxOType tx)
incrementUTxO :: Maybe (UTxOType tx)
      }
  | AckSn
      { forall tx. Message tx -> Signature (Snapshot tx)
signed :: Signature (Snapshot tx)
      , snapshotNumber :: SnapshotNumber
      }
  | ReqDec {transaction :: tx}
  deriving stock ((forall x. Message tx -> Rep (Message tx) x)
-> (forall x. Rep (Message tx) x -> Message tx)
-> Generic (Message tx)
forall x. Rep (Message tx) x -> Message tx
forall x. Message tx -> Rep (Message tx) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall tx x. Rep (Message tx) x -> Message tx
forall tx x. Message tx -> Rep (Message tx) x
$cfrom :: forall tx x. Message tx -> Rep (Message tx) x
from :: forall x. Message tx -> Rep (Message tx) x
$cto :: forall tx x. Rep (Message tx) x -> Message tx
to :: forall x. Rep (Message tx) x -> Message tx
Generic)

deriving stock instance IsTx tx => Eq (Message tx)
deriving stock instance IsTx tx => Show (Message tx)
deriving anyclass instance IsTx tx => ToJSON (Message tx)
deriving anyclass instance IsTx tx => FromJSON (Message tx)

instance ArbitraryIsTx tx => Arbitrary (Message tx) where
  arbitrary :: Gen (Message tx)
arbitrary = Gen (Message tx)
forall a.
(Generic a, GA UnsizedOpts (Rep a),
 UniformWeight (Weights_ (Rep a))) =>
Gen a
genericArbitrary

instance (ToCBOR tx, ToCBOR (UTxOType tx), ToCBOR (TxIdType tx)) => ToCBOR (Message tx) where
  toCBOR :: Message tx -> Encoding
toCBOR = \case
    ReqTx tx
tx -> Text -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Text
"ReqTx" :: Text) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> tx -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR tx
tx
    ReqSn SnapshotVersion
sv SnapshotNumber
sn [TxIdType tx]
txs Maybe tx
decommitTx Maybe (UTxOType tx)
incrementUTxO -> Text -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Text
"ReqSn" :: Text) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> SnapshotVersion -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR SnapshotVersion
sv Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> SnapshotNumber -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR SnapshotNumber
sn Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> [TxIdType tx] -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR [TxIdType tx]
txs Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Maybe tx -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Maybe tx
decommitTx Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Maybe (UTxOType tx) -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Maybe (UTxOType tx)
incrementUTxO
    AckSn Signature (Snapshot tx)
sig SnapshotNumber
sn -> Text -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Text
"AckSn" :: Text) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Signature (Snapshot tx) -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Signature (Snapshot tx)
sig Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> SnapshotNumber -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR SnapshotNumber
sn
    ReqDec tx
utxo -> Text -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Text
"ReqDec" :: Text) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> tx -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR tx
utxo

instance (FromCBOR tx, FromCBOR (UTxOType tx), FromCBOR (TxIdType tx)) => FromCBOR (Message tx) where
  fromCBOR :: forall s. Decoder s (Message tx)
fromCBOR =
    Decoder s Text
forall s. Decoder s Text
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s Text
-> (Text -> Decoder s (Message tx)) -> Decoder s (Message tx)
forall a b. Decoder s a -> (a -> Decoder s b) -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
      (Text
"ReqTx" :: Text) -> tx -> Message tx
forall tx. tx -> Message tx
ReqTx (tx -> Message tx) -> Decoder s tx -> Decoder s (Message tx)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s tx
forall s. Decoder s tx
forall a s. FromCBOR a => Decoder s a
fromCBOR
      Text
"ReqSn" -> SnapshotVersion
-> SnapshotNumber
-> [TxIdType tx]
-> Maybe tx
-> Maybe (UTxOType tx)
-> Message tx
forall tx.
SnapshotVersion
-> SnapshotNumber
-> [TxIdType tx]
-> Maybe tx
-> Maybe (UTxOType tx)
-> Message tx
ReqSn (SnapshotVersion
 -> SnapshotNumber
 -> [TxIdType tx]
 -> Maybe tx
 -> Maybe (UTxOType tx)
 -> Message tx)
-> Decoder s SnapshotVersion
-> Decoder
     s
     (SnapshotNumber
      -> [TxIdType tx] -> Maybe tx -> Maybe (UTxOType tx) -> Message tx)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s SnapshotVersion
forall s. Decoder s SnapshotVersion
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder
  s
  (SnapshotNumber
   -> [TxIdType tx] -> Maybe tx -> Maybe (UTxOType tx) -> Message tx)
-> Decoder s SnapshotNumber
-> Decoder
     s ([TxIdType tx] -> Maybe tx -> Maybe (UTxOType tx) -> Message tx)
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s SnapshotNumber
forall s. Decoder s SnapshotNumber
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder
  s ([TxIdType tx] -> Maybe tx -> Maybe (UTxOType tx) -> Message tx)
-> Decoder s [TxIdType tx]
-> Decoder s (Maybe tx -> Maybe (UTxOType tx) -> Message tx)
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s [TxIdType tx]
forall s. Decoder s [TxIdType tx]
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s (Maybe tx -> Maybe (UTxOType tx) -> Message tx)
-> Decoder s (Maybe tx)
-> Decoder s (Maybe (UTxOType tx) -> Message tx)
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s (Maybe tx)
forall s. Decoder s (Maybe tx)
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s (Maybe (UTxOType tx) -> Message tx)
-> Decoder s (Maybe (UTxOType tx)) -> Decoder s (Message tx)
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s (Maybe (UTxOType tx))
forall s. Decoder s (Maybe (UTxOType tx))
forall a s. FromCBOR a => Decoder s a
fromCBOR
      Text
"AckSn" -> Signature (Snapshot tx) -> SnapshotNumber -> Message tx
forall tx. Signature (Snapshot tx) -> SnapshotNumber -> Message tx
AckSn (Signature (Snapshot tx) -> SnapshotNumber -> Message tx)
-> Decoder s (Signature (Snapshot tx))
-> Decoder s (SnapshotNumber -> Message tx)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (Signature (Snapshot tx))
forall s. Decoder s (Signature (Snapshot tx))
forall a s. FromCBOR a => Decoder s a
fromCBOR Decoder s (SnapshotNumber -> Message tx)
-> Decoder s SnapshotNumber -> Decoder s (Message tx)
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s SnapshotNumber
forall s. Decoder s SnapshotNumber
forall a s. FromCBOR a => Decoder s a
fromCBOR
      Text
"ReqDec" -> tx -> Message tx
forall tx. tx -> Message tx
ReqDec (tx -> Message tx) -> Decoder s tx -> Decoder s (Message tx)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s tx
forall s. Decoder s tx
forall a s. FromCBOR a => Decoder s a
fromCBOR
      Text
msg -> String -> Decoder s (Message tx)
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s (Message tx))
-> String -> Decoder s (Message tx)
forall a b. (a -> b) -> a -> b
$ Text -> String
forall b a. (Show a, IsString b) => a -> b
show Text
msg String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" is not a proper CBOR-encoded Message"

instance IsTx tx => SignableRepresentation (Message tx) where
  getSignableRepresentation :: Message tx -> ByteString
getSignableRepresentation = Message tx -> ByteString
forall a. ToCBOR a => a -> ByteString
serialize'