{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Ouroboros.Network.Protocol.LocalTxSubmission.Server
(
LocalTxSubmissionServer (..)
, localTxSubmissionServerPeer
) where
import Network.TypedProtocol.Core
import Network.TypedProtocol.Peer.Server
import Ouroboros.Network.Protocol.LocalTxSubmission.Type
data LocalTxSubmissionServer tx reject m a =
LocalTxSubmissionServer {
forall tx reject (m :: * -> *) a.
LocalTxSubmissionServer tx reject m a
-> tx
-> m (SubmitResult reject, LocalTxSubmissionServer tx reject m a)
recvMsgSubmitTx :: tx -> m ( SubmitResult reject
, LocalTxSubmissionServer tx reject m a ),
forall tx reject (m :: * -> *) a.
LocalTxSubmissionServer tx reject m a -> a
recvMsgDone :: a
}
localTxSubmissionServerPeer
:: forall tx reject m a. Monad m
=> m (LocalTxSubmissionServer tx reject m a)
-> Server (LocalTxSubmission tx reject) NonPipelined StIdle m a
localTxSubmissionServerPeer :: forall tx reject (m :: * -> *) a.
Monad m =>
m (LocalTxSubmissionServer tx reject m a)
-> Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a
localTxSubmissionServerPeer m (LocalTxSubmissionServer tx reject m a)
server =
m (Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a)
-> Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a
forall ps (pl :: IsPipelined) (st :: ps) (m :: * -> *) a.
m (Server ps pl st m a) -> Server ps pl st m a
Effect (m (Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a)
-> Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a)
-> m (Server
(LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a)
-> Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a
forall a b. (a -> b) -> a -> b
$ LocalTxSubmissionServer tx reject m a
-> Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a
go (LocalTxSubmissionServer tx reject m a
-> Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a)
-> m (LocalTxSubmissionServer tx reject m a)
-> m (Server
(LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (LocalTxSubmissionServer tx reject m a)
server
where
go :: LocalTxSubmissionServer tx reject m a
-> Server (LocalTxSubmission tx reject) NonPipelined StIdle m a
go :: LocalTxSubmissionServer tx reject m a
-> Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a
go LocalTxSubmissionServer{tx
-> m (SubmitResult reject, LocalTxSubmissionServer tx reject m a)
recvMsgSubmitTx :: forall tx reject (m :: * -> *) a.
LocalTxSubmissionServer tx reject m a
-> tx
-> m (SubmitResult reject, LocalTxSubmissionServer tx reject m a)
recvMsgSubmitTx :: tx
-> m (SubmitResult reject, LocalTxSubmissionServer tx reject m a)
recvMsgSubmitTx, a
recvMsgDone :: forall tx reject (m :: * -> *) a.
LocalTxSubmissionServer tx reject m a -> a
recvMsgDone :: a
recvMsgDone} =
(forall (st' :: LocalTxSubmission tx reject).
Message (LocalTxSubmission tx reject) 'StIdle st'
-> Server (LocalTxSubmission tx reject) 'NonPipelined st' m a)
-> Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a
forall ps (pl :: IsPipelined) (st :: ps) (m :: * -> *) a.
(StateTokenI st, StateAgency st ~ 'ClientAgency,
Outstanding pl ~ 'Z) =>
(forall (st' :: ps). Message ps st st' -> Server ps pl st' m a)
-> Server ps pl st m a
Await ((forall (st' :: LocalTxSubmission tx reject).
Message (LocalTxSubmission tx reject) 'StIdle st'
-> Server (LocalTxSubmission tx reject) 'NonPipelined st' m a)
-> Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a)
-> (forall (st' :: LocalTxSubmission tx reject).
Message (LocalTxSubmission tx reject) 'StIdle st'
-> Server (LocalTxSubmission tx reject) 'NonPipelined st' m a)
-> Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a
forall a b. (a -> b) -> a -> b
$ \Message (LocalTxSubmission tx reject) 'StIdle st'
msg -> case Message (LocalTxSubmission tx reject) 'StIdle st'
msg of
MsgSubmitTx tx1
tx -> m (Server (LocalTxSubmission tx reject) 'NonPipelined st' m a)
-> Server (LocalTxSubmission tx reject) 'NonPipelined st' m a
forall ps (pl :: IsPipelined) (st :: ps) (m :: * -> *) a.
m (Server ps pl st m a) -> Server ps pl st m a
Effect (m (Server (LocalTxSubmission tx reject) 'NonPipelined st' m a)
-> Server (LocalTxSubmission tx reject) 'NonPipelined st' m a)
-> m (Server (LocalTxSubmission tx reject) 'NonPipelined st' m a)
-> Server (LocalTxSubmission tx reject) 'NonPipelined st' m a
forall a b. (a -> b) -> a -> b
$ do
(result, k) <- tx
-> m (SubmitResult reject, LocalTxSubmissionServer tx reject m a)
recvMsgSubmitTx tx
tx1
tx
return $
case result of
SubmitResult reject
SubmitSuccess ->
Message (LocalTxSubmission tx reject) st' 'StIdle
-> Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a
-> Server (LocalTxSubmission tx reject) 'NonPipelined st' m a
forall ps (pl :: IsPipelined) (st :: ps) (m :: * -> *) a
(st' :: ps).
(StateTokenI st, StateTokenI st', StateAgency st ~ 'ServerAgency,
Outstanding pl ~ 'Z) =>
Message ps st st' -> Server ps pl st' m a -> Server ps pl st m a
Yield
Message (LocalTxSubmission tx reject) st' 'StIdle
Message (LocalTxSubmission tx reject) 'StBusy 'StIdle
forall {k} {k1} (tx :: k) (reject :: k1).
Message (LocalTxSubmission tx reject) 'StBusy 'StIdle
MsgAcceptTx
(LocalTxSubmissionServer tx reject m a
-> Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a
go LocalTxSubmissionServer tx reject m a
k)
SubmitFail reject
reject ->
Message (LocalTxSubmission tx reject) st' 'StIdle
-> Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a
-> Server (LocalTxSubmission tx reject) 'NonPipelined st' m a
forall ps (pl :: IsPipelined) (st :: ps) (m :: * -> *) a
(st' :: ps).
(StateTokenI st, StateTokenI st', StateAgency st ~ 'ServerAgency,
Outstanding pl ~ 'Z) =>
Message ps st st' -> Server ps pl st' m a -> Server ps pl st m a
Yield
(reject -> Message (LocalTxSubmission tx reject) 'StBusy 'StIdle
forall {k} reject1 (tx :: k).
reject1 -> Message (LocalTxSubmission tx reject1) 'StBusy 'StIdle
MsgRejectTx reject
reject)
(LocalTxSubmissionServer tx reject m a
-> Server (LocalTxSubmission tx reject) 'NonPipelined 'StIdle m a
go LocalTxSubmissionServer tx reject m a
k)
Message (LocalTxSubmission tx reject) 'StIdle st'
R:MessageLocalTxSubmissionfromto (*) (*) tx reject 'StIdle st'
MsgDone -> a -> Server (LocalTxSubmission tx reject) 'NonPipelined st' m a
forall ps (pl :: IsPipelined) (st :: ps) (m :: * -> *) a.
(StateTokenI st, StateAgency st ~ 'NobodyAgency,
Outstanding pl ~ 'Z) =>
a -> Server ps pl st m a
Done a
recvMsgDone