|
5 | 5 | module Cardano.Api.Network.IPC.Internal.Monad |
6 | 6 | ( LocalStateQueryExpr |
7 | 7 | , executeLocalStateQueryExpr |
| 8 | + , executeLocalStateQueryExprWithVersion |
8 | 9 | , queryExpr |
9 | 10 | ) |
10 | 11 | where |
@@ -44,6 +45,31 @@ newtype LocalStateQueryExpr block point query r m a = LocalStateQueryExpr |
44 | 45 | } |
45 | 46 | deriving (Functor, Applicative, Monad, MonadReader NodeToClientVersion, MonadIO) |
46 | 47 |
|
| 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 | + |
47 | 73 | -- | Execute a local state query expression. |
48 | 74 | executeLocalStateQueryExpr |
49 | 75 | :: () |
|
0 commit comments