{-# LANGUAGE DataKinds           #-}
{-# LANGUAGE FlexibleContexts    #-}
{-# LANGUAGE GADTs               #-}
{-# LANGUAGE LambdaCase          #-}
{-# LANGUAGE NamedFieldPuns      #-}
{-# LANGUAGE PolyKinds           #-}
{-# LANGUAGE RankNTypes          #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies        #-}
{-# LANGUAGE TypeOperators       #-}

module Ouroboros.Network.Protocol.LocalTxMonitor.Codec
  ( codecLocalTxMonitor
  , codecLocalTxMonitorId
  ) where

import Control.Monad.Class.MonadST

import Network.TypedProtocol.Codec.CBOR
import Network.TypedProtocol.Core

import Data.ByteString.Lazy (ByteString)

import Codec.CBOR.Decoding qualified as CBOR
import Codec.CBOR.Encoding qualified as CBOR
import Codec.CBOR.Read qualified as CBOR
import Text.Printf

import Ouroboros.Network.Protocol.LocalTxMonitor.Type

codecLocalTxMonitor ::
     forall txid tx slot m ptcl.
     ( MonadST m
     , ptcl ~ LocalTxMonitor txid tx slot
     )
  => (txid -> CBOR.Encoding)
  -> (forall s. CBOR.Decoder s txid)
  -> (tx -> CBOR.Encoding)
  -> (forall s. CBOR.Decoder s tx)
  -> (slot -> CBOR.Encoding)
  -> (forall s. CBOR.Decoder s slot)
  -> Codec (LocalTxMonitor txid tx slot) CBOR.DeserialiseFailure m ByteString
codecLocalTxMonitor :: forall txid tx slot (m :: * -> *) ptcl.
(MonadST m, ptcl ~ LocalTxMonitor txid tx slot) =>
(txid -> Encoding)
-> (forall s. Decoder s txid)
-> (tx -> Encoding)
-> (forall s. Decoder s tx)
-> (slot -> Encoding)
-> (forall s. Decoder s slot)
-> Codec
     (LocalTxMonitor txid tx slot) DeserialiseFailure m ByteString
codecLocalTxMonitor txid -> Encoding
encodeTxId forall s. Decoder s txid
decodeTxId
                    tx -> Encoding
encodeTx   forall s. Decoder s tx
decodeTx
                    slot -> Encoding
encodeSlot forall s. Decoder s slot
decodeSlot =
    (forall (st :: LocalTxMonitor txid tx slot)
        (st' :: LocalTxMonitor txid tx slot).
 (StateTokenI st, ActiveState st) =>
 Message (LocalTxMonitor txid tx slot) st st' -> Encoding)
-> (forall (st :: LocalTxMonitor txid tx slot) s.
    ActiveState st =>
    StateToken st -> Decoder s (SomeMessage st))
-> Codec
     (LocalTxMonitor txid tx slot) DeserialiseFailure m ByteString
forall ps (m :: * -> *).
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 (SomeMessage st))
-> Codec ps DeserialiseFailure m ByteString
mkCodecCborLazyBS Message ptcl st st' -> Encoding
Message (LocalTxMonitor txid tx slot) st st' -> Encoding
forall (st :: ptcl) (st' :: ptcl). Message ptcl st st' -> Encoding
forall (st :: LocalTxMonitor txid tx slot)
       (st' :: LocalTxMonitor txid tx slot).
(StateTokenI st, ActiveState st) =>
Message (LocalTxMonitor txid tx slot) st st' -> Encoding
encode StateToken st -> Decoder s (SomeMessage st)
StateToken st -> Decoder s (SomeMessage st)
forall s (st :: ptcl).
ActiveState st =>
StateToken st -> Decoder s (SomeMessage st)
forall (st :: LocalTxMonitor txid tx slot) s.
ActiveState st =>
StateToken st -> Decoder s (SomeMessage st)
decode
  where
    encode ::
         forall (st  :: ptcl) (st' :: ptcl).
         Message ptcl st st'
      -> CBOR.Encoding
    encode :: forall (st :: ptcl) (st' :: ptcl). Message ptcl st st' -> Encoding
encode = \case
      Message ptcl st st'
R:MessageLocalTxMonitorfromto txid tx slot st st'
MsgDone ->
        Word -> Encoding
CBOR.encodeListLen Word
1 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
0
      Message ptcl st st'
R:MessageLocalTxMonitorfromto txid tx slot st st'
MsgAcquire ->
        Word -> Encoding
CBOR.encodeListLen Word
1 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
1
      Message ptcl st st'
R:MessageLocalTxMonitorfromto txid tx slot st st'
MsgAwaitAcquire ->
        Word -> Encoding
CBOR.encodeListLen Word
1 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
1
      Message ptcl st st'
R:MessageLocalTxMonitorfromto txid tx slot st st'
MsgRelease ->
        Word -> Encoding
CBOR.encodeListLen Word
1 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
3
      Message ptcl st st'
R:MessageLocalTxMonitorfromto txid tx slot st st'
MsgNextTx ->
        Word -> Encoding
CBOR.encodeListLen Word
1 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
5
      MsgHasTx txid
txid ->
        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
<> txid -> Encoding
encodeTxId txid
txid
      Message ptcl st st'
R:MessageLocalTxMonitorfromto txid tx slot st st'
MsgGetSizes ->
        Word -> Encoding
CBOR.encodeListLen Word
1 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
9
      MsgAcquired slot
slot ->
        Word -> Encoding
CBOR.encodeListLen Word
2 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
2 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> slot -> Encoding
encodeSlot slot
slot
      MsgReplyNextTx Maybe tx
Nothing ->
        Word -> Encoding
CBOR.encodeListLen Word
1 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
6
      MsgReplyNextTx (Just tx
tx) ->
        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
<> tx -> Encoding
encodeTx tx
tx
      MsgReplyHasTx Bool
has ->
        Word -> Encoding
CBOR.encodeListLen Word
2 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
8 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Bool -> Encoding
CBOR.encodeBool Bool
has
      MsgReplyGetSizes MempoolSizeAndCapacity
sz ->
           Word -> Encoding
CBOR.encodeListLen Word
2
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeWord Word
10
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
CBOR.encodeListLen Word
3
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word32 -> Encoding
CBOR.encodeWord32 (MempoolSizeAndCapacity -> Word32
capacityInBytes MempoolSizeAndCapacity
sz)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word32 -> Encoding
CBOR.encodeWord32 (MempoolSizeAndCapacity -> Word32
sizeInBytes MempoolSizeAndCapacity
sz)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word32 -> Encoding
CBOR.encodeWord32 (MempoolSizeAndCapacity -> Word32
numberOfTxs MempoolSizeAndCapacity
sz)

    decode ::
         forall s (st :: ptcl).
         ActiveState st
      => StateToken st
      -> CBOR.Decoder s (SomeMessage st)
    decode :: forall s (st :: ptcl).
ActiveState st =>
StateToken st -> Decoder s (SomeMessage st)
decode StateToken st
stok = do
      len <- Decoder s Int
forall s. Decoder s Int
CBOR.decodeListLen
      key <- CBOR.decodeWord
      case (stok, len, key) of
        (SingLocalTxMonitor st
SingIdle, Int
1, Word
0) ->
          SomeMessage st -> Decoder s (SomeMessage st)
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Message ptcl st 'StDone -> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message ptcl st 'StDone
Message (LocalTxMonitor txid tx slot) 'StIdle 'StDone
forall txid tx slot.
Message (LocalTxMonitor txid tx slot) 'StIdle 'StDone
MsgDone)
        (SingLocalTxMonitor st
SingIdle, Int
1, Word
1) ->
          SomeMessage st -> Decoder s (SomeMessage st)
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Message ptcl st 'StAcquiring -> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message ptcl st 'StAcquiring
Message (LocalTxMonitor txid tx slot) 'StIdle 'StAcquiring
forall txid tx slot.
Message (LocalTxMonitor txid tx slot) 'StIdle 'StAcquiring
MsgAcquire)

        (SingLocalTxMonitor st
SingAcquired, Int
1, Word
1) ->
          SomeMessage st -> Decoder s (SomeMessage st)
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Message ptcl st 'StAcquiring -> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message ptcl st 'StAcquiring
Message (LocalTxMonitor txid tx slot) 'StAcquired 'StAcquiring
forall txid tx slot.
Message (LocalTxMonitor txid tx slot) 'StAcquired 'StAcquiring
MsgAwaitAcquire)
        (SingLocalTxMonitor st
SingAcquired, Int
1, Word
3) ->
          SomeMessage st -> Decoder s (SomeMessage st)
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Message ptcl st 'StIdle -> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message ptcl st 'StIdle
Message (LocalTxMonitor txid tx slot) 'StAcquired 'StIdle
forall txid tx slot.
Message (LocalTxMonitor txid tx slot) 'StAcquired 'StIdle
MsgRelease)
        (SingLocalTxMonitor st
SingAcquired, Int
1, Word
5) ->
          SomeMessage st -> Decoder s (SomeMessage st)
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Message ptcl st ('StBusy 'NextTx) -> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message ptcl st ('StBusy 'NextTx)
Message (LocalTxMonitor txid tx slot) 'StAcquired ('StBusy 'NextTx)
forall txid tx slot.
Message (LocalTxMonitor txid tx slot) 'StAcquired ('StBusy 'NextTx)
MsgNextTx)
        (SingLocalTxMonitor st
SingAcquired, Int
2, Word
7) -> do
          txid <- Decoder s txid
forall s. Decoder s txid
decodeTxId
          return (SomeMessage (MsgHasTx txid))
        (SingLocalTxMonitor st
SingAcquired, Int
1, Word
9) ->
          SomeMessage st -> Decoder s (SomeMessage st)
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Message ptcl st ('StBusy 'GetSizes) -> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message ptcl st ('StBusy 'GetSizes)
Message
  (LocalTxMonitor txid tx slot) 'StAcquired ('StBusy 'GetSizes)
forall txid tx slot.
Message
  (LocalTxMonitor txid tx slot) 'StAcquired ('StBusy 'GetSizes)
MsgGetSizes)

        (SingLocalTxMonitor st
SingAcquiring, Int
2, Word
2) -> do
          slot <- Decoder s slot
forall s. Decoder s slot
decodeSlot
          return (SomeMessage (MsgAcquired slot))

        (SingBusy SingBusyKind k
SingNextTx, Int
1, Word
6) ->
          SomeMessage st -> Decoder s (SomeMessage st)
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Message ptcl st 'StAcquired -> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage (Maybe tx
-> Message
     (LocalTxMonitor txid tx slot) ('StBusy 'NextTx) 'StAcquired
forall tx txid slot.
Maybe tx
-> Message
     (LocalTxMonitor txid tx slot) ('StBusy 'NextTx) 'StAcquired
MsgReplyNextTx Maybe tx
forall a. Maybe a
Nothing))
        (SingBusy SingBusyKind k
SingNextTx, Int
2, Word
6) -> do
          tx <- Decoder s tx
forall s. Decoder s tx
decodeTx
          return (SomeMessage (MsgReplyNextTx (Just tx)))

        (SingBusy SingBusyKind k
SingHasTx, Int
2, Word
8) -> do
          has <- Decoder s Bool
forall s. Decoder s Bool
CBOR.decodeBool
          return (SomeMessage (MsgReplyHasTx has))

        (SingBusy SingBusyKind k
SingGetSizes, Int
2, Word
10) -> do
          _len <- Decoder s Int
forall s. Decoder s Int
CBOR.decodeListLen
          capacityInBytes <- CBOR.decodeWord32
          sizeInBytes <- CBOR.decodeWord32
          numberOfTxs <- CBOR.decodeWord32
          let sizes = MempoolSizeAndCapacity { Word32
capacityInBytes :: Word32
capacityInBytes :: Word32
capacityInBytes, Word32
sizeInBytes :: Word32
sizeInBytes :: Word32
sizeInBytes, Word32
numberOfTxs :: Word32
numberOfTxs :: Word32
numberOfTxs }
          return (SomeMessage (MsgReplyGetSizes sizes))

        (SingLocalTxMonitor st
SingDone, Int
_, 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

        (SingLocalTxMonitor st
_, Int
_, Word
_) ->
          String -> Decoder s (SomeMessage st)
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> String -> String -> Word -> Int -> String
forall r. PrintfType r => String -> r
printf String
"codecLocalTxMonitor (%s, %s) unexpected key (%d, %d)"
                       (ActiveAgency' st (StateAgency st) -> String
forall a. Show a => a -> String
show (ActiveAgency' st (StateAgency st)
ActiveAgency' st (StateAgency st)
forall {ps} (st :: ps) (agency :: Agency).
IsActiveState st agency =>
ActiveAgency' st agency
activeAgency :: ActiveAgency st)) (SingLocalTxMonitor st -> String
forall a. Show a => a -> String
show StateToken st
SingLocalTxMonitor st
stok) Word
key Int
len)

-- | An identity 'Codec' for the 'LocalTxMonitor' protocol. It does not do
-- any serialisation. It keeps the typed messages, wrapped in 'AnyMessage'.
--
codecLocalTxMonitorId ::
     forall txid tx slot m ptcl.
     ( Monad m
     , ptcl ~ LocalTxMonitor txid tx slot
     )
  => Codec ptcl CodecFailure m (AnyMessage ptcl)
codecLocalTxMonitorId :: forall txid tx slot (m :: * -> *) ptcl.
(Monad m, ptcl ~ LocalTxMonitor txid tx slot) =>
Codec ptcl CodecFailure m (AnyMessage ptcl)
codecLocalTxMonitorId =
    (forall (st :: ptcl) (st' :: ptcl).
 (StateTokenI st, ActiveState st) =>
 Message ptcl st st' -> AnyMessage ptcl)
-> (forall (st :: ptcl).
    ActiveState st =>
    StateToken st
    -> m (DecodeStep
            (AnyMessage ptcl) CodecFailure m (SomeMessage st)))
-> Codec ptcl CodecFailure m (AnyMessage ptcl)
forall ps failure (m :: * -> *) bytes.
(forall (st :: ps) (st' :: ps).
 (StateTokenI st, ActiveState st) =>
 Message ps st st' -> bytes)
-> (forall (st :: ps).
    ActiveState st =>
    StateToken st -> m (DecodeStep bytes failure m (SomeMessage st)))
-> Codec ps failure m bytes
Codec Message ptcl st st' -> AnyMessage ptcl
forall (st :: ptcl) (st' :: ptcl).
(StateTokenI st, ActiveState st) =>
Message ptcl st st' -> AnyMessage ptcl
encode StateToken st
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
forall (st :: ptcl).
ActiveState st =>
StateToken st
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
decode
  where
    encode ::
         forall st st'.
         StateTokenI st
      => ActiveState st
      => Message ptcl st st'
      -> AnyMessage ptcl
    encode :: forall (st :: ptcl) (st' :: ptcl).
(StateTokenI st, ActiveState st) =>
Message ptcl st st' -> AnyMessage ptcl
encode = Message ptcl st st' -> AnyMessage ptcl
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, ActiveState st) =>
Message ps st st' -> AnyMessage ps
AnyMessage

    decode ::
         forall (st :: ptcl).
         ActiveState st
      => StateToken st
      -> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
    decode :: forall (st :: ptcl).
ActiveState st =>
StateToken st
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
decode StateToken st
stok =
      let res :: (StateTokenI st, StateTokenI st')
              => Message ptcl st st' -> m (DecodeStep bytes failure m (SomeMessage st))
          res :: forall (st' :: ptcl) bytes failure.
(StateTokenI st, StateTokenI st') =>
Message ptcl st st'
-> m (DecodeStep bytes failure m (SomeMessage st))
res Message ptcl st st'
msg = DecodeStep bytes failure m (SomeMessage st)
-> m (DecodeStep bytes failure m (SomeMessage st))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (SomeMessage st
-> Maybe bytes -> DecodeStep bytes failure m (SomeMessage st)
forall bytes failure (m :: * -> *) a.
a -> Maybe bytes -> DecodeStep bytes failure m a
DecodeDone (Message ptcl st st' -> SomeMessage st
forall ps (st :: ps) (st' :: ps).
(StateTokenI st, StateTokenI st', ActiveState st) =>
Message ps st st' -> SomeMessage st
SomeMessage Message ptcl st st'
msg) Maybe bytes
forall a. Maybe a
Nothing)
      in DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st)
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st)
 -> m (DecodeStep
         (AnyMessage ptcl) CodecFailure m (SomeMessage st)))
-> DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st)
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
forall a b. (a -> b) -> a -> b
$ (Maybe (AnyMessage ptcl)
 -> m (DecodeStep
         (AnyMessage ptcl) CodecFailure m (SomeMessage st)))
-> DecodeStep (AnyMessage ptcl) 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 ptcl)
  -> m (DecodeStep
          (AnyMessage ptcl) CodecFailure m (SomeMessage st)))
 -> DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
-> (Maybe (AnyMessage ptcl)
    -> m (DecodeStep
            (AnyMessage ptcl) CodecFailure m (SomeMessage st)))
-> DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st)
forall a b. (a -> b) -> a -> b
$ \Maybe (AnyMessage ptcl)
bytes -> case (StateToken st
SingLocalTxMonitor st
stok, Maybe (AnyMessage ptcl)
bytes) of
        (SingLocalTxMonitor st
SingIdle,     Just (AnyMessage msg :: Message ptcl st st'
msg@MsgAcquire{}))      -> Message ptcl st st'
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
forall (st' :: ptcl) bytes failure.
(StateTokenI st, StateTokenI st') =>
Message ptcl st st'
-> m (DecodeStep bytes failure m (SomeMessage st))
res Message ptcl st st'
Message ptcl st st'
msg
        (SingLocalTxMonitor st
SingIdle,     Just (AnyMessage msg :: Message ptcl st st'
msg@MsgDone{}))         -> Message ptcl st st'
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
forall (st' :: ptcl) bytes failure.
(StateTokenI st, StateTokenI st') =>
Message ptcl st st'
-> m (DecodeStep bytes failure m (SomeMessage st))
res Message ptcl st st'
Message ptcl st st'
msg
        (SingLocalTxMonitor st
SingAcquired, Just (AnyMessage msg :: Message ptcl st st'
msg@MsgAwaitAcquire{})) -> Message ptcl st st'
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
forall (st' :: ptcl) bytes failure.
(StateTokenI st, StateTokenI st') =>
Message ptcl st st'
-> m (DecodeStep bytes failure m (SomeMessage st))
res Message ptcl st st'
Message ptcl st st'
msg
        (SingLocalTxMonitor st
SingAcquired, Just (AnyMessage msg :: Message ptcl st st'
msg@MsgNextTx{}))       -> Message ptcl st st'
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
forall (st' :: ptcl) bytes failure.
(StateTokenI st, StateTokenI st') =>
Message ptcl st st'
-> m (DecodeStep bytes failure m (SomeMessage st))
res Message ptcl st st'
Message ptcl st st'
msg
        (SingLocalTxMonitor st
SingAcquired, Just (AnyMessage msg :: Message ptcl st st'
msg@MsgHasTx{}))        -> Message ptcl st st'
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
forall (st' :: ptcl) bytes failure.
(StateTokenI st, StateTokenI st') =>
Message ptcl st st'
-> m (DecodeStep bytes failure m (SomeMessage st))
res Message ptcl st st'
Message ptcl st st'
msg
        (SingLocalTxMonitor st
SingAcquired, Just (AnyMessage msg :: Message ptcl st st'
msg@MsgRelease{}))      -> Message ptcl st st'
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
forall (st' :: ptcl) bytes failure.
(StateTokenI st, StateTokenI st') =>
Message ptcl st st'
-> m (DecodeStep bytes failure m (SomeMessage st))
res Message ptcl st st'
Message ptcl st st'
msg
        (SingLocalTxMonitor st
SingAcquiring,       Just (AnyMessage msg :: Message ptcl st st'
msg@MsgAcquired{}))    -> Message ptcl st st'
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
forall (st' :: ptcl) bytes failure.
(StateTokenI st, StateTokenI st') =>
Message ptcl st st'
-> m (DecodeStep bytes failure m (SomeMessage st))
res Message ptcl st st'
Message ptcl st st'
msg
        (SingBusy SingBusyKind k
SingNextTx, Just (AnyMessage msg :: Message ptcl st st'
msg@MsgReplyNextTx{})) -> Message ptcl st st'
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
forall (st' :: ptcl) bytes failure.
(StateTokenI st, StateTokenI st') =>
Message ptcl st st'
-> m (DecodeStep bytes failure m (SomeMessage st))
res Message ptcl st st'
Message ptcl st st'
msg
        (SingBusy SingBusyKind k
SingHasTx,  Just (AnyMessage msg :: Message ptcl st st'
msg@MsgReplyHasTx{}))  -> Message ptcl st st'
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
forall (st' :: ptcl) bytes failure.
(StateTokenI st, StateTokenI st') =>
Message ptcl st st'
-> m (DecodeStep bytes failure m (SomeMessage st))
res Message ptcl st st'
Message ptcl st st'
msg

        (SingLocalTxMonitor st
SingDone, Maybe (AnyMessage ptcl)
_) -> 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

        (SingLocalTxMonitor st
_, Maybe (AnyMessage ptcl)
Nothing) ->
          DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st)
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (CodecFailure
-> DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st)
forall bytes failure (m :: * -> *) a.
failure -> DecodeStep bytes failure m a
DecodeFail CodecFailure
CodecFailureOutOfInput)
        (SingLocalTxMonitor st
_, Maybe (AnyMessage ptcl)
_) ->
          DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st)
-> m (DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (CodecFailure
-> DecodeStep (AnyMessage ptcl) CodecFailure m (SomeMessage st)
forall bytes failure (m :: * -> *) a.
failure -> DecodeStep bytes failure m a
DecodeFail (String -> CodecFailure
CodecFailure String
"codecLocalTxMonitorId: no matching message"))