Skip to content

Commit cf8bab8

Browse files
committed
Implement executeLocalStateQueryExprWithVersion
1 parent 27111c3 commit cf8bab8

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

cardano-api/src/Cardano/Api/Network/IPC.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ module Cardano.Api.Network.IPC
219219
-- **** Query monad
220220
, LocalStateQueryExpr
221221
, executeLocalStateQueryExpr
222+
, executeLocalStateQueryExprWithVersion
222223
, queryExpr
223224

224225
-- *** Local tx monitoring

cardano-api/src/Cardano/Api/Network/IPC/Internal/Monad.hs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
module Cardano.Api.Network.IPC.Internal.Monad
66
( LocalStateQueryExpr
77
, executeLocalStateQueryExpr
8+
, executeLocalStateQueryExprWithVersion
89
, queryExpr
910
)
1011
where
@@ -44,6 +45,31 @@ newtype LocalStateQueryExpr block point query r m a = LocalStateQueryExpr
4445
}
4546
deriving (Functor, Applicative, Monad, MonadReader NodeToClientVersion, MonadIO)
4647

48+
-- | Execute a local state query expression.
49+
executeLocalStateQueryExprWithVersion
50+
:: ()
51+
=> LocalNodeConnectInfo
52+
-> Net.Query.Target ChainPoint
53+
-> (NodeToClientVersion -> LocalStateQueryExpr BlockInMode ChainPoint QueryInMode () IO a)
54+
-> IO (Either AcquiringFailure a)
55+
executeLocalStateQueryExprWithVersion connectInfo target f = do
56+
tmvResultLocalState <- newEmptyTMVarIO
57+
let waitResult = readTMVar tmvResultLocalState
58+
59+
connectToLocalNodeWithVersion
60+
connectInfo
61+
( \ntcVersion ->
62+
LocalNodeClientProtocols
63+
{ localChainSyncClient = NoLocalChainSyncClient
64+
, localStateQueryClient =
65+
Just $ setupLocalStateQueryExpr waitResult target tmvResultLocalState ntcVersion (f ntcVersion)
66+
, localTxSubmissionClient = Nothing
67+
, localTxMonitoringClient = Nothing
68+
}
69+
)
70+
71+
atomically waitResult
72+
4773
-- | Execute a local state query expression.
4874
executeLocalStateQueryExpr
4975
:: ()

0 commit comments

Comments
 (0)