{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
module Ouroboros.Network.Protocol.LocalTxSubmission.Type where
import Data.Kind (Type)
import Control.DeepSeq
import Network.TypedProtocol.Core
import Ouroboros.Network.Util.ShowProxy
data LocalTxSubmission tx reject where
StIdle :: LocalTxSubmission tx reject
StBusy :: LocalTxSubmission tx reject
StDone :: LocalTxSubmission tx reject
instance ( ShowProxy tx
, ShowProxy reject
) => ShowProxy (LocalTxSubmission tx reject) where
showProxy :: Proxy (LocalTxSubmission tx reject) -> String
showProxy Proxy (LocalTxSubmission tx reject)
_ = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ String
"LocalTxSubmission ("
, Proxy tx -> String
forall {k} (p :: k). ShowProxy p => Proxy p -> String
showProxy (Proxy tx
forall {k} (t :: k). Proxy t
Proxy :: Proxy tx)
, String
") ("
, Proxy reject -> String
forall {k} (p :: k). ShowProxy p => Proxy p -> String
showProxy (Proxy reject
forall {k} (t :: k). Proxy t
Proxy :: Proxy reject)
, String
")"
]
type SingLocalTxSubmission :: LocalTxSubmission tx rejct
-> Type
data SingLocalTxSubmission k where
SingIdle :: SingLocalTxSubmission StIdle
SingBusy :: SingLocalTxSubmission StBusy
SingDone :: SingLocalTxSubmission StDone
instance StateTokenI StIdle where stateToken :: StateToken 'StIdle
stateToken = StateToken 'StIdle
SingLocalTxSubmission 'StIdle
forall {k} {k} {tx :: k} {rejct :: k}.
SingLocalTxSubmission 'StIdle
SingIdle
instance StateTokenI StBusy where stateToken :: StateToken 'StBusy
stateToken = StateToken 'StBusy
SingLocalTxSubmission 'StBusy
forall {k} {k} {tx :: k} {rejct :: k}.
SingLocalTxSubmission 'StBusy
SingBusy
instance StateTokenI StDone where stateToken :: StateToken 'StDone
stateToken = StateToken 'StDone
SingLocalTxSubmission 'StDone
forall {k} {k} {tx :: k} {rejct :: k}.
SingLocalTxSubmission 'StDone
SingDone
deriving instance Show (SingLocalTxSubmission k)
data SubmitResult reason
= SubmitSuccess
| SubmitFail reason
deriving (SubmitResult reason -> SubmitResult reason -> Bool
(SubmitResult reason -> SubmitResult reason -> Bool)
-> (SubmitResult reason -> SubmitResult reason -> Bool)
-> Eq (SubmitResult reason)
forall reason.
Eq reason =>
SubmitResult reason -> SubmitResult reason -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall reason.
Eq reason =>
SubmitResult reason -> SubmitResult reason -> Bool
== :: SubmitResult reason -> SubmitResult reason -> Bool
$c/= :: forall reason.
Eq reason =>
SubmitResult reason -> SubmitResult reason -> Bool
/= :: SubmitResult reason -> SubmitResult reason -> Bool
Eq, (forall a b. (a -> b) -> SubmitResult a -> SubmitResult b)
-> (forall a b. a -> SubmitResult b -> SubmitResult a)
-> Functor SubmitResult
forall a b. a -> SubmitResult b -> SubmitResult a
forall a b. (a -> b) -> SubmitResult a -> SubmitResult b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> SubmitResult a -> SubmitResult b
fmap :: forall a b. (a -> b) -> SubmitResult a -> SubmitResult b
$c<$ :: forall a b. a -> SubmitResult b -> SubmitResult a
<$ :: forall a b. a -> SubmitResult b -> SubmitResult a
Functor)
instance Protocol (LocalTxSubmission tx reject) where
data Message (LocalTxSubmission tx reject) from to where
MsgSubmitTx
:: tx
-> Message (LocalTxSubmission tx reject) StIdle StBusy
MsgAcceptTx
:: Message (LocalTxSubmission tx reject) StBusy StIdle
MsgRejectTx
:: reject
-> Message (LocalTxSubmission tx reject) StBusy StIdle
MsgDone
:: Message (LocalTxSubmission tx reject) StIdle StDone
type StateAgency StIdle = ClientAgency
type StateAgency StBusy = ServerAgency
type StateAgency StDone = NobodyAgency
type StateToken = SingLocalTxSubmission
instance ( NFData tx
, NFData reject
) => NFData (Message (LocalTxSubmission tx reject) from to) where
rnf :: Message (LocalTxSubmission tx reject) from to -> ()
rnf (MsgSubmitTx tx
tx) = tx -> ()
forall a. NFData a => a -> ()
rnf tx
tx
rnf Message (LocalTxSubmission tx reject) from to
R:MessageLocalTxSubmissionfromto (*) (*) tx reject from to
MsgAcceptTx = ()
rnf (MsgRejectTx reject
reject) = reject -> ()
forall a. NFData a => a -> ()
rnf reject
reject
rnf Message (LocalTxSubmission tx reject) from to
R:MessageLocalTxSubmissionfromto (*) (*) tx reject from to
MsgDone = ()
deriving instance (Eq tx, Eq reject) =>
Eq (Message (LocalTxSubmission tx reject) from to)
deriving instance (Show tx, Show reject) =>
Show (Message (LocalTxSubmission tx reject) from to)