@@ -13,6 +13,7 @@ import Control.Applicative
13
13
import Control.Concurrent.STM
14
14
import Control.Monad
15
15
import Control.Monad.IO.Class
16
+ import Control.Monad.Reader
16
17
import Control.Monad.Trans.Cont
17
18
import Data.Bifunctor (first )
18
19
import Data.Either
@@ -45,14 +46,14 @@ import Cardano.Api.Modes
45
46
-- In order to make pipelining still possible we can explore the use of Selective Functors
46
47
-- which would allow us to straddle both worlds.
47
48
newtype LocalStateQueryExpr block point query r m a = LocalStateQueryExpr
48
- { runLocalStateQueryExpr :: ContT (Net.Query. ClientStAcquired block point query m r ) m a
49
- } deriving (Functor , Applicative , Monad , MonadIO )
49
+ { runLocalStateQueryExpr :: ReaderT NodeToClientVersion ( ContT (Net.Query. ClientStAcquired block point query m r ) m ) a
50
+ } deriving (Functor , Applicative , Monad , MonadReader NodeToClientVersion , MonadIO )
50
51
51
52
-- | Execute a local state query expression.
52
53
executeLocalStateQueryExpr
53
54
:: LocalNodeConnectInfo mode
54
55
-> Maybe ChainPoint
55
- -> ( NodeToClientVersion -> LocalStateQueryExpr (BlockInMode mode ) ChainPoint (QueryInMode mode ) () IO a )
56
+ -> LocalStateQueryExpr (BlockInMode mode ) ChainPoint (QueryInMode mode ) () IO a
56
57
-> IO (Either AcquiringFailure a )
57
58
executeLocalStateQueryExpr connectInfo mpoint f = do
58
59
tmvResultLocalState <- newEmptyTMVarIO
@@ -63,7 +64,7 @@ executeLocalStateQueryExpr connectInfo mpoint f = do
63
64
(\ ntcVersion ->
64
65
LocalNodeClientProtocols
65
66
{ localChainSyncClient = NoLocalChainSyncClient
66
- , localStateQueryClient = Just $ setupLocalStateQueryExpr waitResult mpoint tmvResultLocalState (f ntcVersion)
67
+ , localStateQueryClient = Just $ setupLocalStateQueryExpr waitResult mpoint tmvResultLocalState ntcVersion f
67
68
, localTxSubmissionClient = Nothing
68
69
, localTxMonitoringClient = Nothing
69
70
}
@@ -79,12 +80,13 @@ setupLocalStateQueryExpr ::
79
80
-- cause other incomplete protocols to abort which may lead to deadlock.
80
81
-> Maybe ChainPoint
81
82
-> TMVar (Either Net.Query. AcquireFailure a )
83
+ -> NodeToClientVersion
82
84
-> LocalStateQueryExpr (BlockInMode mode ) ChainPoint (QueryInMode mode ) () IO a
83
85
-> Net.Query. LocalStateQueryClient (BlockInMode mode ) ChainPoint (QueryInMode mode ) IO ()
84
- setupLocalStateQueryExpr waitDone mPointVar' resultVar' f =
86
+ setupLocalStateQueryExpr waitDone mPointVar' resultVar' ntcVersion f =
85
87
LocalStateQueryClient . pure . Net.Query. SendMsgAcquire mPointVar' $
86
88
Net.Query. ClientStAcquiring
87
- { Net.Query. recvMsgAcquired = runContT (runLocalStateQueryExpr f) $ \ result -> do
89
+ { Net.Query. recvMsgAcquired = runContT (runReaderT ( runLocalStateQueryExpr f) ntcVersion ) $ \ result -> do
88
90
atomically $ putTMVar resultVar' (Right result)
89
91
void $ atomically waitDone -- Wait for all protocols to complete before exiting.
90
92
pure $ Net.Query. SendMsgRelease $ pure $ Net.Query. SendMsgDone ()
@@ -98,7 +100,7 @@ setupLocalStateQueryExpr waitDone mPointVar' resultVar' f =
98
100
-- | Use 'queryExpr' in a do block to construct monadic local state queries.
99
101
queryExpr :: QueryInMode mode a -> LocalStateQueryExpr block point (QueryInMode mode ) r IO a
100
102
queryExpr q =
101
- LocalStateQueryExpr . ContT $ \ f -> pure $
103
+ LocalStateQueryExpr . ReaderT $ \ _ -> ContT $ \ f -> pure $
102
104
Net.Query. SendMsgQuery q $
103
105
Net.Query. ClientStQuerying
104
106
{ Net.Query. recvMsgResult = f
0 commit comments