{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeFamilies #-}

-- | The LeiosNotify mini-protocol's types and codec.
module Ouroboros.Consensus.MiniProtocol.LeiosNotify.Type
  ( LeiosNotify (..)
  , Message (..)
  , SingLeiosNotify (..)
  , byteLimitsLeiosNotify
  , codecLeiosNotify
  , codecLeiosNotifyId
  , maxLeiosVotesPerMessage
  , maxLeiosNotifyReplyBytes
  , timeLimitsLeiosNotify
  ) where

import Cardano.Ledger.Binary.Plain (decodeRecordSum)
import qualified Codec.CBOR.Decoding as CBOR
import qualified Codec.CBOR.Encoding as CBOR
import qualified Codec.CBOR.Read as CBOR
import Control.DeepSeq (NFData (..))
import Control.Monad.Class.MonadST (MonadST)
import Data.ByteString.Lazy (ByteString)
import Data.Kind (Type)
import Data.List.NonEmpty (NonEmpty (..))
import qualified Data.List.NonEmpty as NE
import Data.Proxy (Proxy (..))
import qualified Data.Text as T
import Data.Word (Word32)
import Network.TypedProtocol.Codec.CBOR
  ( ActiveState
  , AnyMessage (..)
  , Codec
  , CodecF (..)
  , CodecFailure (..)
  , DecodeStep (..)
  , SomeMessage (..)
  , StateTokenI (..)
  , mkCodecCborLazyBS
  , notActiveState
  )
import Network.TypedProtocol.Core
  ( Agency (..)
  , Protocol (..)
  , StateAgency
  )
import Ouroboros.Consensus.Util.CBOR (decodeListUpTo)
import Ouroboros.Network.Protocol.Limits
  ( ProtocolSizeLimits (..)
  , ProtocolTimeLimits (..)
  , longWait
  , smallByteLimit
  , waitForever
  )
import Ouroboros.Network.Util.ShowProxy (ShowProxy (..))

-----

-- | The LeiosNotify mini-protocol's states, as the cardano-blueprint specifies
-- them:
-- <https://cardano-scaling.github.io/cardano-blueprint/network/node-to-node/leios-notify/index.html?leios=on>.
-- CIP-0164 specifies the Leios mini-protocols,
-- <https://cips.cardano.org/cip/CIP-0164>; see also
-- <https://github.com/cardano-foundation/CIPs/pull/1296>.
type LeiosNotify :: Type -> Type -> Type -> Type
data LeiosNotify point announcement vote where
  StIdle :: LeiosNotify point announcement vote
  StBusy :: LeiosNotify point announcement vote
  StQuit :: LeiosNotify point announcement vote
  StDone :: LeiosNotify point announcement vote

instance
  ( ShowProxy point
  , ShowProxy announcement
  , ShowProxy vote
  ) =>
  ShowProxy (LeiosNotify point announcement vote)
  where
  showProxy :: Proxy (LeiosNotify point announcement vote) -> String
showProxy Proxy (LeiosNotify point announcement vote)
_ =
    [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
      [ String
"LeiosNotify "
      , Proxy point -> String
forall {k} (p :: k). ShowProxy p => Proxy p -> String
showProxy (Proxy point
forall {k} (t :: k). Proxy t
Proxy :: Proxy point)
      , String
" "
      , Proxy announcement -> String
forall {k} (p :: k). ShowProxy p => Proxy p -> String
showProxy (Proxy announcement
forall {k} (t :: k). Proxy t
Proxy :: Proxy announcement)
      , String
" "
      , Proxy vote -> String
forall {k} (p :: k). ShowProxy p => Proxy p -> String
showProxy (Proxy vote
forall {k} (t :: k). Proxy t
Proxy :: Proxy vote)
      ]

instance ShowProxy (StIdle :: LeiosNotify point announcement vote) where
  showProxy :: Proxy 'StIdle -> String
showProxy Proxy 'StIdle
_ = String
"StIdle"
instance ShowProxy (StBusy :: LeiosNotify point announcement vote) where
  showProxy :: Proxy 'StBusy -> String
showProxy Proxy 'StBusy
_ = String
"StBusy"
instance ShowProxy (StQuit :: LeiosNotify point announcement vote) where
  showProxy :: Proxy 'StQuit -> String
showProxy Proxy 'StQuit
_ = String
"StQuit"
instance ShowProxy (StDone :: LeiosNotify point announcement vote) where
  showProxy :: Proxy 'StDone -> String
showProxy Proxy 'StDone
_ = String
"StDone"

type SingLeiosNotify ::
  LeiosNotify point announcement vote ->
  Type
data SingLeiosNotify st where
  SingIdle :: SingLeiosNotify StIdle
  SingBusy :: SingLeiosNotify StBusy
  SingQuit :: SingLeiosNotify StQuit
  SingDone :: SingLeiosNotify StDone

deriving instance Show (SingLeiosNotify st)

instance StateTokenI StIdle where stateToken :: StateToken 'StIdle
stateToken = StateToken 'StIdle
SingLeiosNotify 'StIdle
forall {point} {announcement} {vote}. SingLeiosNotify 'StIdle
SingIdle
instance StateTokenI StBusy where stateToken :: StateToken 'StBusy
stateToken = StateToken 'StBusy
SingLeiosNotify 'StBusy
forall {point} {announcement} {vote}. SingLeiosNotify 'StBusy
SingBusy
instance StateTokenI StQuit where stateToken :: StateToken 'StQuit
stateToken = StateToken 'StQuit
SingLeiosNotify 'StQuit
forall {point} {announcement} {vote}. SingLeiosNotify 'StQuit
SingQuit
instance StateTokenI StDone where stateToken :: StateToken 'StDone
stateToken = StateToken 'StDone
SingLeiosNotify 'StDone
forall {point} {announcement} {vote}. SingLeiosNotify 'StDone
SingDone

-----

instance Protocol (LeiosNotify point announcement vote) where
  data Message (LeiosNotify point announcement vote) from to where
    MsgDone ::
      Message (LeiosNotify point announcement vote) StQuit StDone
    MsgQuit ::
      Message (LeiosNotify point announcement vote) StIdle StQuit
    MsgCanceled ::
      Message (LeiosNotify point announcement vote) StBusy StIdle
    MsgLeiosNotificationRequestNext ::
      Message (LeiosNotify point announcement vote) StIdle StBusy
    MsgLeiosBlockAnnouncement ::
      !announcement ->
      Message (LeiosNotify point announcement vote) StBusy StIdle
    MsgLeiosBlockOffer ::
      !point ->
      -- Carry the size so that an upstream can offer an EB as long as they've
      -- sent an announcement of this hash, even if that announcement had the
      -- wrong size. This is cheap to do and makes the LeiosFetch logic simpler
      -- to reason about.
      --
      -- TODO The blueprint carries the size, and
      -- <https://github.com/cardano-foundation/CIPs/pull/1296> updates CIP-0164
      -- to match; confirm once it is merged.
      !Word32 ->
      Message (LeiosNotify point announcement vote) StBusy StIdle
    MsgLeiosBlockTxsOffer ::
      !point ->
      Message (LeiosNotify point announcement vote) StBusy StIdle
    MsgLeiosVotes ::
      -- At most 'maxLeiosVotesPerMessage'; the codec rejects more.
      NonEmpty vote ->
      Message (LeiosNotify point announcement vote) StBusy StIdle

  type StateAgency StIdle = ClientAgency
  type StateAgency StBusy = ServerAgency
  type StateAgency StQuit = ServerAgency
  type StateAgency StDone = NobodyAgency

  type StateToken = SingLeiosNotify

instance NFData (Message (LeiosNotify point announcement vote) from to) where
  rnf :: Message (LeiosNotify point announcement vote) from to -> ()
rnf = \case
    Message (LeiosNotify point announcement vote) from to
R:MessageLeiosNotifyfromto point announcement vote from to
MsgLeiosNotificationRequestNext -> ()
    MsgLeiosBlockAnnouncement{} -> ()
    MsgLeiosBlockOffer{} -> ()
    MsgLeiosBlockTxsOffer{} -> ()
    MsgLeiosVotes{} -> ()
    Message (LeiosNotify point announcement vote) from to
R:MessageLeiosNotifyfromto point announcement vote from to
MsgDone -> ()
    Message (LeiosNotify point announcement vote) from to
R:MessageLeiosNotifyfromto point announcement vote from to
MsgQuit -> ()
    Message (LeiosNotify point announcement vote) from to
R:MessageLeiosNotifyfromto point announcement vote from to
MsgCanceled -> ()

deriving instance
  (Eq point, Eq announcement, Eq vote) =>
  Eq (Message (LeiosNotify point announcement vote) from to)

deriving instance
  (Show point, Show announcement, Show vote) =>
  Show (Message (LeiosNotify point announcement vote) from to)

-----

-- | The most votes one 'MsgLeiosVotes' may carry.
--
-- It keeps every reply within 'maxLeiosNotifyReplyBytes'.
maxLeiosVotesPerMessage :: Int
maxLeiosVotesPerMessage :: Int
maxLeiosVotesPerMessage = Int
16

-- | The most bytes one reply may take, 1.5 KiB.
--
-- A vote encodes to at most 88 bytes, so a 'MsgLeiosVotes' of
-- 'maxLeiosVotesPerMessage' votes takes at most 1411 bytes. An announcing
-- header is bounded by the ledger's maximum header size, 1100 bytes on
-- mainnet; raising that parameter past this would need this raised too. An
-- offer takes tens of bytes.
maxLeiosNotifyReplyBytes :: Word
maxLeiosNotifyReplyBytes :: Word
maxLeiosNotifyReplyBytes = Word
1536

byteLimitsLeiosNotify ::
  (bytes -> Word) ->
  ProtocolSizeLimits (LeiosNotify point announcement vote) bytes
byteLimitsLeiosNotify :: forall bytes point announcement vote.
(bytes -> Word)
-> ProtocolSizeLimits (LeiosNotify point announcement vote) bytes
byteLimitsLeiosNotify = (forall (st :: LeiosNotify point announcement vote).
 ActiveState st =>
 StateToken st -> Word)
-> (bytes -> Word)
-> ProtocolSizeLimits (LeiosNotify point announcement vote) bytes
forall ps bytes.
(forall (st :: ps). ActiveState st => StateToken st -> Word)
-> (bytes -> Word) -> ProtocolSizeLimits ps bytes
ProtocolSizeLimits ((forall (st :: LeiosNotify point announcement vote).
  ActiveState st =>
  StateToken st -> Word)
 -> (bytes -> Word)
 -> ProtocolSizeLimits (LeiosNotify point announcement vote) bytes)
-> (forall (st :: LeiosNotify point announcement vote).
    ActiveState st =>
    StateToken st -> Word)
-> (bytes -> Word)
-> ProtocolSizeLimits (LeiosNotify point announcement vote) bytes
forall a b. (a -> b) -> a -> b
$ \case
  StateToken st
SingLeiosNotify st
SingIdle -> Word
smallByteLimit
  StateToken st
SingLeiosNotify st
SingBusy -> Word
maxLeiosNotifyReplyBytes
  StateToken st
SingLeiosNotify st
SingQuit -> Word
smallByteLimit
  st :: StateToken st
st@StateToken st
SingLeiosNotify st
SingDone -> StateToken 'StDone -> forall a. a
forall ps (st :: ps).
(StateAgency st ~ 'NobodyAgency, ActiveState st) =>
StateToken st -> forall a. a
notActiveState StateToken st
StateToken 'StDone
st

timeLimitsLeiosNotify ::
  ProtocolTimeLimits (LeiosNotify point announcement vote)
timeLimitsLeiosNotify :: forall point announcement vote.
ProtocolTimeLimits (LeiosNotify point announcement vote)
timeLimitsLeiosNotify = (forall (st :: LeiosNotify point announcement vote).
 ActiveState st =>
 StateToken st -> Maybe DiffTime)
-> ProtocolTimeLimits (LeiosNotify point announcement vote)
forall ps.
(forall (st :: ps).
 ActiveState st =>
 StateToken st -> Maybe DiffTime)
-> ProtocolTimeLimits ps
ProtocolTimeLimits ((forall (st :: LeiosNotify point announcement vote).
  ActiveState st =>
  StateToken st -> Maybe DiffTime)
 -> ProtocolTimeLimits (LeiosNotify point announcement vote))
-> (forall (st :: LeiosNotify point announcement vote).
    ActiveState st =>
    StateToken st -> Maybe DiffTime)
-> ProtocolTimeLimits (LeiosNotify point announcement vote)
forall a b. (a -> b) -> a -> b
$ \case
  StateToken st
SingLeiosNotify st
SingIdle -> Maybe DiffTime
waitForever
  StateToken st
SingLeiosNotify st
SingBusy -> Maybe DiffTime
waitForever
  StateToken st
SingLeiosNotify st
SingQuit -> Maybe DiffTime
longWait
  st :: StateToken st
st@StateToken st
SingLeiosNotify st
SingDone -> StateToken 'StDone -> forall a. a
forall ps (st :: ps).
(StateAgency st ~ 'NobodyAgency, ActiveState st) =>
StateToken st -> forall a. a
notActiveState StateToken st
StateToken 'StDone
st

-----

codecLeiosNotify ::
  forall point announcement vote m.
  MonadST m =>
  (point -> CBOR.Encoding) ->
  (forall s. CBOR.Decoder s point) ->
  (announcement -> CBOR.Encoding) ->
  (forall s. CBOR.Decoder s announcement) ->
  (vote -> CBOR.Encoding) ->
  (forall s. CBOR.Decoder s vote) ->
  Codec (LeiosNotify point announcement vote) CBOR.DeserialiseFailure m ByteString
codecLeiosNotify :: forall point announcement vote (m :: * -> *).
MonadST m =>
(point -> Encoding)
-> (forall s. Decoder s point)
-> (announcement -> Encoding)
-> (forall s. Decoder s announcement)
-> (vote -> Encoding)
-> (forall s. Decoder s vote)
-> Codec
     (LeiosNotify point announcement vote)
     DeserialiseFailure
     m
     ByteString
codecLeiosNotify point -> Encoding
encodeP forall s. Decoder s point
decodeP announcement -> Encoding
encodeA forall s. Decoder s announcement
decodeA vote -> Encoding
encodeV forall s. Decoder s vote
decodeV =
  (forall (st :: LeiosNotify point announcement vote)
        (st' :: LeiosNotify point announcement vote).
 (StateTokenI st, ActiveState st) =>
 Message (LeiosNotify point announcement vote) st st' -> Encoding)
-> (forall (st :: LeiosNotify point announcement vote) s.
    ActiveState st =>
    StateToken st -> Decoder s (SomeMessage st))
-> CodecF
     (LeiosNotify point announcement vote)
     DeserialiseFailure
     m
     SomeMessage
     ByteString
forall ps (m :: * -> *) (f :: ps -> *).
MonadST m =>
(forall (st :: ps) (st' :: ps).
 (StateTokenI st, ActiveState st) =>
 Message ps st st' -> Encoding)
-> (forall (st :: ps) s.
    ActiveState st =>
    StateToken st -> Decoder s (f st))
-> CodecF ps DeserialiseFailure m f ByteString
mkCodecCborLazyBS
    ((point -> Encoding)
-> (announcement -> Encoding)
-> (vote -> Encoding)
-> Message (LeiosNotify point announcement vote) st st'
-> Encoding
forall point announcement vote
       (st :: LeiosNotify point announcement vote)
       (st' :: LeiosNotify point announcement vote).
(point -> Encoding)
-> (announcement -> Encoding)
-> (vote -> Encoding)
-> Message (LeiosNotify point announcement vote) st st'
-> Encoding
encodeLeiosNotify point -> Encoding
encodeP announcement -> Encoding
encodeA vote -> Encoding
encodeV)
    StateToken st -> Decoder s (SomeMessage st)
StateToken st -> forall s. Decoder s (SomeMessage st)
forall (st :: LeiosNotify point announcement vote).
ActiveState st =>
StateToken st -> forall s. Decoder s (SomeMessage st)
forall (st :: LeiosNotify point announcement vote) s.
ActiveState st =>
StateToken st -> Decoder s (SomeMessage st)
decode
 where
  decode ::
    forall (st :: LeiosNotify point announcement vote).
    ActiveState st =>
    StateToken st ->
    forall s.
    CBOR.Decoder s (SomeMessage st)
  decode :: forall (st :: LeiosNotify point announcement vote).
ActiveState st =>
StateToken st -> forall s. Decoder s (SomeMessage st)
decode StateToken st
stok =
    Text
-> (Word -> Decoder s (Int, SomeMessage st))
-> Decoder s (SomeMessage st)
forall s a. Text -> (Word -> Decoder s (Int, a)) -> Decoder s a
decodeRecordSum
      (String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ String
"LeiosNotify (" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> SingLeiosNotify st -> String
forall a. Show a => a -> String
show StateToken st
SingLeiosNotify st
stok String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
")")
      ((forall s. Decoder s point)
-> (forall s. Decoder s announcement)
-> (forall s. Decoder s vote)
-> StateToken st
-> Word
-> Decoder s (Int, SomeMessage st)
forall point announcement vote
       (st :: LeiosNotify point announcement vote) s.
ActiveState st =>
(forall s'. Decoder s' point)
-> (forall s'. Decoder s' announcement)
-> (forall s'. Decoder s' vote)
-> StateToken st
-> Word
-> Decoder s (Int, SomeMessage st)
decodeLeiosNotify Decoder s' point
forall s. Decoder s point
decodeP Decoder s' announcement
forall s. Decoder s announcement
decodeA Decoder s' vote
forall s. Decoder s vote
decodeV StateToken st
stok)

encodeLeiosNotify ::
  forall
    point
    announcement
    vote
    (st :: LeiosNotify point announcement vote)
    (st' :: LeiosNotify point announcement vote).
  (point -> CBOR.Encoding) ->
  (announcement -> CBOR.Encoding) ->
  (vote -> CBOR.Encoding) ->
  Message (LeiosNotify point announcement vote) st st' ->
  CBOR.Encoding
encodeLeiosNotify :: forall point announcement vote
       (st :: LeiosNotify point announcement vote)
       (st' :: LeiosNotify point announcement vote).
(point -> Encoding)
-> (announcement -> Encoding)
-> (vote -> Encoding)
-> Message (LeiosNotify point announcement vote) st st'
-> Encoding
encodeLeiosNotify point -> Encoding
encodeP announcement -> Encoding
encodeA vote -> Encoding
encodeV = Message (LeiosNotify point announcement vote) st st' -> Encoding
forall (st0 :: LeiosNotify point announcement vote)
       (st1 :: LeiosNotify point announcement vote).
Message (LeiosNotify point announcement vote) st0 st1 -> Encoding
encode
 where
  encode ::
    forall st0 st1.
    Message (LeiosNotify point announcement vote) st0 st1 ->
    CBOR.Encoding
  encode :: forall (st0 :: LeiosNotify point announcement vote)
       (st1 :: LeiosNotify point announcement vote).
Message (LeiosNotify point announcement vote) st0 st1 -> Encoding
encode = \case
    Message (LeiosNotify point announcement vote) st0 st1
R:MessageLeiosNotifyfromto point announcement vote st0 st1
MsgDone ->
      Word -> Encoding
CBOR.encodeListLen Word
1
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
0
    Message (LeiosNotify point announcement vote) st0 st1
R:MessageLeiosNotifyfromto point announcement vote st0 st1
MsgQuit ->
      Word -> Encoding
CBOR.encodeListLen Word
1
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
1
    Message (LeiosNotify point announcement vote) st0 st1
R:MessageLeiosNotifyfromto point announcement vote st0 st1
MsgCanceled ->
      Word -> Encoding
CBOR.encodeListLen Word
1
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
2
    Message (LeiosNotify point announcement vote) st0 st1
R:MessageLeiosNotifyfromto point announcement vote st0 st1
MsgLeiosNotificationRequestNext ->
      Word -> Encoding
CBOR.encodeListLen Word
1
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
3
    MsgLeiosBlockAnnouncement announcement
x ->
      Word -> Encoding
CBOR.encodeListLen Word
2
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
4
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> announcement -> Encoding
encodeA announcement
x
    MsgLeiosBlockOffer point
p Word32
sz ->
      Word -> Encoding
CBOR.encodeListLen Word
3
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
5
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> point -> Encoding
encodeP point
p
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word32 -> Encoding
CBOR.encodeWord32 Word32
sz
    MsgLeiosBlockTxsOffer point
p ->
      Word -> Encoding
CBOR.encodeListLen Word
2
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
6
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> point -> Encoding
encodeP point
p
    MsgLeiosVotes NonEmpty vote
vs ->
      Word -> Encoding
CBOR.encodeListLen Word
2
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
7
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Encoding
encodeVotes
     where
      encodeVotes :: Encoding
encodeVotes =
        Word -> Encoding
CBOR.encodeListLen (Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word) -> Int -> Word
forall a b. (a -> b) -> a -> b
$ NonEmpty vote -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty vote
vs)
          Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (vote -> Encoding) -> NonEmpty vote -> Encoding
forall m a. Monoid m => (a -> m) -> NonEmpty a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap vote -> Encoding
encodeV NonEmpty vote
vs

decodeLeiosNotify ::
  forall
    point
    announcement
    vote
    (st :: LeiosNotify point announcement vote)
    s.
  ActiveState st =>
  (forall s'. CBOR.Decoder s' point) ->
  (forall s'. CBOR.Decoder s' announcement) ->
  (forall s'. CBOR.Decoder s' vote) ->
  StateToken st ->
  Word ->
  CBOR.Decoder s (Int, SomeMessage st)
decodeLeiosNotify :: forall point announcement vote
       (st :: LeiosNotify point announcement vote) s.
ActiveState st =>
(forall s'. Decoder s' point)
-> (forall s'. Decoder s' announcement)
-> (forall s'. Decoder s' vote)
-> StateToken st
-> Word
-> Decoder s (Int, SomeMessage st)
decodeLeiosNotify forall s'. Decoder s' point
decodeP forall s'. Decoder s' announcement
decodeA forall s'. Decoder s' vote
decodeV = StateToken st -> Word -> Decoder s (Int, SomeMessage st)
forall (st' :: LeiosNotify point announcement vote).
ActiveState st' =>
StateToken st' -> Word -> Decoder s (Int, SomeMessage st')
decode
 where
  decode ::
    forall (st' :: LeiosNotify point announcement vote).
    ActiveState st' =>
    StateToken st' ->
    Word ->
    CBOR.Decoder s (Int, SomeMessage st')
  decode :: forall (st' :: LeiosNotify point announcement vote).
ActiveState st' =>
StateToken st' -> Word -> Decoder s (Int, SomeMessage st')
decode StateToken st'
stok Word
key = do
    case (StateToken st'
SingLeiosNotify st'
stok, Word
key) of
      (SingLeiosNotify st'
SingQuit, Word
0) -> Int
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
fields Int
1 (Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st'))
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
forall a b. (a -> b) -> a -> b
$ SomeMessage st' -> Decoder s (SomeMessage st')
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Message (LeiosNotify point announcement vote) st' 'StDone
-> SomeMessage st'
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (LeiosNotify point announcement vote) st' 'StDone
Message (LeiosNotify point announcement vote) 'StQuit 'StDone
forall point announcement vote.
Message (LeiosNotify point announcement vote) 'StQuit 'StDone
MsgDone)
      (SingLeiosNotify st'
SingIdle, Word
1) -> Int
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
fields Int
1 (Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st'))
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
forall a b. (a -> b) -> a -> b
$ SomeMessage st' -> Decoder s (SomeMessage st')
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Message (LeiosNotify point announcement vote) st' 'StQuit
-> SomeMessage st'
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (LeiosNotify point announcement vote) st' 'StQuit
Message (LeiosNotify point announcement vote) 'StIdle 'StQuit
forall point announcement vote.
Message (LeiosNotify point announcement vote) 'StIdle 'StQuit
MsgQuit)
      (SingLeiosNotify st'
SingBusy, Word
2) -> Int
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
fields Int
1 (Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st'))
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
forall a b. (a -> b) -> a -> b
$ SomeMessage st' -> Decoder s (SomeMessage st')
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Message (LeiosNotify point announcement vote) st' 'StIdle
-> SomeMessage st'
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (LeiosNotify point announcement vote) st' 'StIdle
Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
forall point announcement vote.
Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
MsgCanceled)
      (SingLeiosNotify st'
SingIdle, Word
3) ->
        Int
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
fields Int
1 (Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st'))
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
forall a b. (a -> b) -> a -> b
$ SomeMessage st' -> Decoder s (SomeMessage st')
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Message (LeiosNotify point announcement vote) st' 'StBusy
-> SomeMessage st'
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (LeiosNotify point announcement vote) st' 'StBusy
Message (LeiosNotify point announcement vote) 'StIdle 'StBusy
forall point announcement vote.
Message (LeiosNotify point announcement vote) 'StIdle 'StBusy
MsgLeiosNotificationRequestNext)
      (SingLeiosNotify st'
SingBusy, Word
4) -> Int
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
fields Int
2 (Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st'))
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
forall a b. (a -> b) -> a -> b
$ do
        x <- Decoder s announcement
forall s'. Decoder s' announcement
decodeA
        return $ SomeMessage $ MsgLeiosBlockAnnouncement x
      (SingLeiosNotify st'
SingBusy, Word
5) -> Int
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
fields Int
3 (Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st'))
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
forall a b. (a -> b) -> a -> b
$ do
        p <- Decoder s point
forall s'. Decoder s' point
decodeP
        sz <- CBOR.decodeWord32
        return $ SomeMessage $ MsgLeiosBlockOffer p sz
      (SingLeiosNotify st'
SingBusy, Word
6) -> Int
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
fields Int
2 (Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st'))
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
forall a b. (a -> b) -> a -> b
$ do
        p <- Decoder s point
forall s'. Decoder s' point
decodeP
        return $ SomeMessage $ MsgLeiosBlockTxsOffer p
      (SingLeiosNotify st'
SingBusy, Word
7) -> Int
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
fields Int
2 (Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st'))
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
forall a b. (a -> b) -> a -> b
$ do
        vs <- String -> Int -> Decoder s vote -> Decoder s [vote]
forall s a. String -> Int -> Decoder s a -> Decoder s [a]
decodeListUpTo String
"MsgLeiosVotes" Int
maxLeiosVotesPerMessage Decoder s vote
forall s'. Decoder s' vote
decodeV
        case NE.nonEmpty vs of
          Maybe (NonEmpty vote)
Nothing -> String -> Decoder s (SomeMessage st')
forall a. HasCallStack => String -> Decoder s a
forall (m :: * -> *) a.
(MonadFail m, HasCallStack) =>
String -> m a
fail String
"MsgLeiosVotes: no votes"
          Just NonEmpty vote
vs' -> SomeMessage st' -> Decoder s (SomeMessage st')
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (SomeMessage st' -> Decoder s (SomeMessage st'))
-> SomeMessage st' -> Decoder s (SomeMessage st')
forall a b. (a -> b) -> a -> b
$ Message (LeiosNotify point announcement vote) st' 'StIdle
-> SomeMessage st'
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage (Message (LeiosNotify point announcement vote) st' 'StIdle
 -> SomeMessage st')
-> Message (LeiosNotify point announcement vote) st' 'StIdle
-> SomeMessage st'
forall a b. (a -> b) -> a -> b
$ NonEmpty vote
-> Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
forall vote point announcement.
NonEmpty vote
-> Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
MsgLeiosVotes NonEmpty vote
vs'
      (SingLeiosNotify st'
SingDone, Word
_) -> StateToken 'StDone -> forall a. a
forall ps (st :: ps).
(StateAgency st ~ 'NobodyAgency, ActiveState st) =>
StateToken st -> forall a. a
notActiveState StateToken st'
StateToken 'StDone
stok
      -- failures per protocol state
      (SingLeiosNotify st'
SingIdle, Word
_) -> Decoder s (Int, SomeMessage st')
forall a. Decoder s a
unexpected
      (SingLeiosNotify st'
SingBusy, Word
_) -> Decoder s (Int, SomeMessage st')
forall a. Decoder s a
unexpected
      (SingLeiosNotify st'
SingQuit, Word
_) -> Decoder s (Int, SomeMessage st')
forall a. Decoder s a
unexpected
   where
    fields :: Int -> CBOR.Decoder s (SomeMessage st') -> CBOR.Decoder s (Int, SomeMessage st')
    fields :: Int
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
fields Int
n = (SomeMessage st' -> (Int, SomeMessage st'))
-> Decoder s (SomeMessage st') -> Decoder s (Int, SomeMessage st')
forall a b. (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((,) Int
n)

    unexpected :: forall a. CBOR.Decoder s a
    unexpected :: forall a. Decoder s a
unexpected =
      String -> Decoder s a
forall a. HasCallStack => String -> Decoder s a
forall (m :: * -> *) a.
(MonadFail m, HasCallStack) =>
String -> m a
fail (String -> Decoder s a) -> String -> Decoder s a
forall a b. (a -> b) -> a -> b
$ String
"codecLeiosNotify (" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> SingLeiosNotify st' -> String
forall a. Show a => a -> String
show StateToken st'
SingLeiosNotify st'
stok String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
") unexpected key " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Word -> String
forall a. Show a => a -> String
show Word
key

codecLeiosNotifyId ::
  forall point announcement vote m.
  Monad m =>
  Codec
    (LeiosNotify point announcement vote)
    CodecFailure
    m
    (AnyMessage (LeiosNotify point announcement vote))
codecLeiosNotifyId :: forall point announcement vote (m :: * -> *).
Monad m =>
Codec
  (LeiosNotify point announcement vote)
  CodecFailure
  m
  (AnyMessage (LeiosNotify point announcement vote))
codecLeiosNotifyId = Codec{Message (LeiosNotify point announcement vote) st st'
-> AnyMessage (LeiosNotify point announcement vote)
forall (st :: LeiosNotify point announcement vote)
       (st' :: LeiosNotify point announcement vote).
(ActiveState st, StateTokenI st) =>
Message (LeiosNotify point announcement vote) st st'
-> AnyMessage (LeiosNotify point announcement vote)
forall (st :: LeiosNotify point announcement vote)
       (st' :: LeiosNotify point announcement vote).
(StateTokenI st, ActiveState st) =>
Message (LeiosNotify point announcement vote) st st'
-> AnyMessage (LeiosNotify point announcement vote)
encode :: forall (st :: LeiosNotify point announcement vote)
       (st' :: LeiosNotify point announcement vote).
(ActiveState st, StateTokenI st) =>
Message (LeiosNotify point announcement vote) st st'
-> AnyMessage (LeiosNotify point announcement vote)
encode :: forall (st :: LeiosNotify point announcement vote)
       (st' :: LeiosNotify point announcement vote).
(StateTokenI st, ActiveState st) =>
Message (LeiosNotify point announcement vote) st st'
-> AnyMessage (LeiosNotify point announcement vote)
encode, StateToken st
-> m (DecodeStep
        (AnyMessage (LeiosNotify point announcement vote))
        CodecFailure
        m
        (SomeMessage st))
forall (st :: LeiosNotify point announcement vote).
ActiveState st =>
StateToken st
-> m (DecodeStep
        (AnyMessage (LeiosNotify point announcement vote))
        CodecFailure
        m
        (SomeMessage st))
decode :: forall (st :: LeiosNotify point announcement vote).
ActiveState st =>
StateToken st
-> m (DecodeStep
        (AnyMessage (LeiosNotify point announcement vote))
        CodecFailure
        m
        (SomeMessage st))
decode :: forall (st :: LeiosNotify point announcement vote).
ActiveState st =>
StateToken st
-> m (DecodeStep
        (AnyMessage (LeiosNotify point announcement vote))
        CodecFailure
        m
        (SomeMessage st))
decode}
 where
  encode ::
    forall st st'.
    ( ActiveState st
    , StateTokenI st
    ) =>
    Message (LeiosNotify point announcement vote) st st' ->
    AnyMessage (LeiosNotify point announcement vote)
  encode :: forall (st :: LeiosNotify point announcement vote)
       (st' :: LeiosNotify point announcement vote).
(ActiveState st, StateTokenI st) =>
Message (LeiosNotify point announcement vote) st st'
-> AnyMessage (LeiosNotify point announcement vote)
encode = Message (LeiosNotify point announcement vote) st st'
-> AnyMessage (LeiosNotify point announcement vote)
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, ActiveState st) =>
Message ps st st' -> AnyMessage ps
AnyMessage

  decode ::
    forall (st :: LeiosNotify point announcement vote).
    ActiveState st =>
    StateToken st ->
    m
      ( DecodeStep
          (AnyMessage (LeiosNotify point announcement vote))
          CodecFailure
          m
          (SomeMessage st)
      )
  decode :: forall (st :: LeiosNotify point announcement vote).
ActiveState st =>
StateToken st
-> m (DecodeStep
        (AnyMessage (LeiosNotify point announcement vote))
        CodecFailure
        m
        (SomeMessage st))
decode StateToken st
stok = DecodeStep
  (AnyMessage (LeiosNotify point announcement vote))
  CodecFailure
  m
  (SomeMessage st)
-> m (DecodeStep
        (AnyMessage (LeiosNotify point announcement vote))
        CodecFailure
        m
        (SomeMessage st))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (DecodeStep
   (AnyMessage (LeiosNotify point announcement vote))
   CodecFailure
   m
   (SomeMessage st)
 -> m (DecodeStep
         (AnyMessage (LeiosNotify point announcement vote))
         CodecFailure
         m
         (SomeMessage st)))
-> DecodeStep
     (AnyMessage (LeiosNotify point announcement vote))
     CodecFailure
     m
     (SomeMessage st)
-> m (DecodeStep
        (AnyMessage (LeiosNotify point announcement vote))
        CodecFailure
        m
        (SomeMessage st))
forall a b. (a -> b) -> a -> b
$ (Maybe (AnyMessage (LeiosNotify point announcement vote))
 -> m (DecodeStep
         (AnyMessage (LeiosNotify point announcement vote))
         CodecFailure
         m
         (SomeMessage st)))
-> DecodeStep
     (AnyMessage (LeiosNotify point announcement vote))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
(Maybe bytes -> m (DecodeStep bytes failure m a))
-> DecodeStep bytes failure m a
DecodePartial ((Maybe (AnyMessage (LeiosNotify point announcement vote))
  -> m (DecodeStep
          (AnyMessage (LeiosNotify point announcement vote))
          CodecFailure
          m
          (SomeMessage st)))
 -> DecodeStep
      (AnyMessage (LeiosNotify point announcement vote))
      CodecFailure
      m
      (SomeMessage st))
-> (Maybe (AnyMessage (LeiosNotify point announcement vote))
    -> m (DecodeStep
            (AnyMessage (LeiosNotify point announcement vote))
            CodecFailure
            m
            (SomeMessage st)))
-> DecodeStep
     (AnyMessage (LeiosNotify point announcement vote))
     CodecFailure
     m
     (SomeMessage st)
forall a b. (a -> b) -> a -> b
$ \Maybe (AnyMessage (LeiosNotify point announcement vote))
bytes ->
    DecodeStep
  (AnyMessage (LeiosNotify point announcement vote))
  CodecFailure
  m
  (SomeMessage st)
-> m (DecodeStep
        (AnyMessage (LeiosNotify point announcement vote))
        CodecFailure
        m
        (SomeMessage st))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (DecodeStep
   (AnyMessage (LeiosNotify point announcement vote))
   CodecFailure
   m
   (SomeMessage st)
 -> m (DecodeStep
         (AnyMessage (LeiosNotify point announcement vote))
         CodecFailure
         m
         (SomeMessage st)))
-> DecodeStep
     (AnyMessage (LeiosNotify point announcement vote))
     CodecFailure
     m
     (SomeMessage st)
-> m (DecodeStep
        (AnyMessage (LeiosNotify point announcement vote))
        CodecFailure
        m
        (SomeMessage st))
forall a b. (a -> b) -> a -> b
$ case (StateToken st
SingLeiosNotify st
stok, Maybe (AnyMessage (LeiosNotify point announcement vote))
bytes) of
      (SingLeiosNotify st
SingIdle, Just (AnyMessage msg :: Message (LeiosNotify point announcement vote) st st'
msg@Message (LeiosNotify point announcement vote) st st'
R:MessageLeiosNotifyfromto point announcement vote st st'
MsgLeiosNotificationRequestNext)) ->
        SomeMessage st
-> Maybe (AnyMessage (LeiosNotify point announcement vote))
-> DecodeStep
     (AnyMessage (LeiosNotify point announcement vote))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
a -> Maybe bytes -> DecodeStep bytes failure m a
DecodeDone (Message (LeiosNotify point announcement vote) st st'
-> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (LeiosNotify point announcement vote) st st'
Message (LeiosNotify point announcement vote) st st'
msg) Maybe (AnyMessage (LeiosNotify point announcement vote))
forall a. Maybe a
Nothing
      (SingLeiosNotify st
SingBusy, Just (AnyMessage msg :: Message (LeiosNotify point announcement vote) st st'
msg@MsgLeiosBlockAnnouncement{})) ->
        SomeMessage st
-> Maybe (AnyMessage (LeiosNotify point announcement vote))
-> DecodeStep
     (AnyMessage (LeiosNotify point announcement vote))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
a -> Maybe bytes -> DecodeStep bytes failure m a
DecodeDone (Message (LeiosNotify point announcement vote) st st'
-> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (LeiosNotify point announcement vote) st st'
Message (LeiosNotify point announcement vote) st st'
msg) Maybe (AnyMessage (LeiosNotify point announcement vote))
forall a. Maybe a
Nothing
      (SingLeiosNotify st
SingBusy, Just (AnyMessage msg :: Message (LeiosNotify point announcement vote) st st'
msg@MsgLeiosBlockOffer{})) ->
        SomeMessage st
-> Maybe (AnyMessage (LeiosNotify point announcement vote))
-> DecodeStep
     (AnyMessage (LeiosNotify point announcement vote))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
a -> Maybe bytes -> DecodeStep bytes failure m a
DecodeDone (Message (LeiosNotify point announcement vote) st st'
-> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (LeiosNotify point announcement vote) st st'
Message (LeiosNotify point announcement vote) st st'
msg) Maybe (AnyMessage (LeiosNotify point announcement vote))
forall a. Maybe a
Nothing
      (SingLeiosNotify st
SingBusy, Just (AnyMessage msg :: Message (LeiosNotify point announcement vote) st st'
msg@MsgLeiosBlockTxsOffer{})) ->
        SomeMessage st
-> Maybe (AnyMessage (LeiosNotify point announcement vote))
-> DecodeStep
     (AnyMessage (LeiosNotify point announcement vote))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
a -> Maybe bytes -> DecodeStep bytes failure m a
DecodeDone (Message (LeiosNotify point announcement vote) st st'
-> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (LeiosNotify point announcement vote) st st'
Message (LeiosNotify point announcement vote) st st'
msg) Maybe (AnyMessage (LeiosNotify point announcement vote))
forall a. Maybe a
Nothing
      (SingLeiosNotify st
SingBusy, Just (AnyMessage msg :: Message (LeiosNotify point announcement vote) st st'
msg@MsgLeiosVotes{})) ->
        SomeMessage st
-> Maybe (AnyMessage (LeiosNotify point announcement vote))
-> DecodeStep
     (AnyMessage (LeiosNotify point announcement vote))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
a -> Maybe bytes -> DecodeStep bytes failure m a
DecodeDone (Message (LeiosNotify point announcement vote) st st'
-> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (LeiosNotify point announcement vote) st st'
Message (LeiosNotify point announcement vote) st st'
msg) Maybe (AnyMessage (LeiosNotify point announcement vote))
forall a. Maybe a
Nothing
      (SingLeiosNotify st
SingQuit, Just (AnyMessage msg :: Message (LeiosNotify point announcement vote) st st'
msg@Message (LeiosNotify point announcement vote) st st'
R:MessageLeiosNotifyfromto point announcement vote st st'
MsgDone)) ->
        SomeMessage st
-> Maybe (AnyMessage (LeiosNotify point announcement vote))
-> DecodeStep
     (AnyMessage (LeiosNotify point announcement vote))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
a -> Maybe bytes -> DecodeStep bytes failure m a
DecodeDone (Message (LeiosNotify point announcement vote) st st'
-> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (LeiosNotify point announcement vote) st st'
Message (LeiosNotify point announcement vote) st st'
msg) Maybe (AnyMessage (LeiosNotify point announcement vote))
forall a. Maybe a
Nothing
      (SingLeiosNotify st
SingIdle, Just (AnyMessage msg :: Message (LeiosNotify point announcement vote) st st'
msg@Message (LeiosNotify point announcement vote) st st'
R:MessageLeiosNotifyfromto point announcement vote st st'
MsgQuit)) ->
        SomeMessage st
-> Maybe (AnyMessage (LeiosNotify point announcement vote))
-> DecodeStep
     (AnyMessage (LeiosNotify point announcement vote))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
a -> Maybe bytes -> DecodeStep bytes failure m a
DecodeDone (Message (LeiosNotify point announcement vote) st st'
-> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (LeiosNotify point announcement vote) st st'
Message (LeiosNotify point announcement vote) st st'
msg) Maybe (AnyMessage (LeiosNotify point announcement vote))
forall a. Maybe a
Nothing
      (SingLeiosNotify st
SingBusy, Just (AnyMessage msg :: Message (LeiosNotify point announcement vote) st st'
msg@Message (LeiosNotify point announcement vote) st st'
R:MessageLeiosNotifyfromto point announcement vote st st'
MsgCanceled)) ->
        SomeMessage st
-> Maybe (AnyMessage (LeiosNotify point announcement vote))
-> DecodeStep
     (AnyMessage (LeiosNotify point announcement vote))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
a -> Maybe bytes -> DecodeStep bytes failure m a
DecodeDone (Message (LeiosNotify point announcement vote) st st'
-> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message (LeiosNotify point announcement vote) st st'
Message (LeiosNotify point announcement vote) st st'
msg) Maybe (AnyMessage (LeiosNotify point announcement vote))
forall a. Maybe a
Nothing
      (SingLeiosNotify st
SingDone, Maybe (AnyMessage (LeiosNotify point announcement vote))
_) ->
        StateToken 'StDone -> forall a. a
forall ps (st :: ps).
(StateAgency st ~ 'NobodyAgency, ActiveState st) =>
StateToken st -> forall a. a
notActiveState StateToken st
StateToken 'StDone
stok
      (SingLeiosNotify st
_, Maybe (AnyMessage (LeiosNotify point announcement vote))
_) ->
        CodecFailure
-> DecodeStep
     (AnyMessage (LeiosNotify point announcement vote))
     CodecFailure
     m
     (SomeMessage st)
forall bytes failure (m :: * -> *) a.
failure -> DecodeStep bytes failure m a
DecodeFail (CodecFailure
 -> DecodeStep
      (AnyMessage (LeiosNotify point announcement vote))
      CodecFailure
      m
      (SomeMessage st))
-> CodecFailure
-> DecodeStep
     (AnyMessage (LeiosNotify point announcement vote))
     CodecFailure
     m
     (SomeMessage st)
forall a b. (a -> b) -> a -> b
$ String -> CodecFailure
CodecFailure String
"codecLeiosNotifyId: no matching message"