@@ -199,6 +199,8 @@ runQueryCmd cmd =
199
199
runQueryKesPeriodInfo consensusModeParams network nodeOpCert mOutFile
200
200
QueryPoolState' consensusModeParams network poolid ->
201
201
runQueryPoolState consensusModeParams network poolid
202
+ QueryTxMempool consensusModeParams network op ->
203
+ runQueryTxMempool consensusModeParams network op
202
204
203
205
runQueryProtocolParameters
204
206
:: AnyConsensusModeParams
@@ -620,6 +622,52 @@ runQueryPoolState (AnyConsensusModeParams cModeParams) network poolIds = do
620
622
result <- executeQuery era cModeParams localNodeConnInfo qInMode
621
623
obtainLedgerEraClassConstraints sbe writePoolState result
622
624
625
+ -- | Query the local mempool state
626
+ runQueryTxMempool
627
+ :: AnyConsensusModeParams
628
+ -> NetworkId
629
+ -> TxMempoolQuery
630
+ -> ExceptT ShelleyQueryCmdError IO ()
631
+ runQueryTxMempool (AnyConsensusModeParams cModeParams) network query = do
632
+ SocketPath sockPath <- firstExceptT ShelleyQueryCmdEnvVarSocketErr readEnvSocketPath
633
+ let localNodeConnInfo = LocalNodeConnectInfo cModeParams network sockPath
634
+
635
+ localQuery <- case query of
636
+ TxMempoolQueryTxExists tx -> do
637
+ anyE@ (AnyCardanoEra era) <- determineEra cModeParams localNodeConnInfo
638
+ let cMode = consensusModeOnly cModeParams
639
+ eInMode <- toEraInMode era cMode
640
+ & hoistMaybe (ShelleyQueryCmdEraConsensusModeMismatch (AnyConsensusMode cMode) anyE)
641
+ pure $ LocalTxMonitoringQueryTx $ TxIdInMode tx eInMode
642
+ TxMempoolQueryNextTx -> pure LocalTxMonitoringSendNextTx
643
+ TxMempoolQueryInfo -> pure LocalTxMonitoringMempoolInformation
644
+
645
+ result <- liftIO $ queryTxMonitoringLocal localNodeConnInfo localQuery
646
+ liftIO $ LBS. putStrLn (renderResult result)
647
+ where
648
+ renderResult result =
649
+ case result of
650
+ LocalTxMonitoringTxExists tx slot -> encodePretty $ object
651
+ [ " exists" .= True
652
+ , " txId" .= tx
653
+ , " slot" .= slot
654
+ ]
655
+ LocalTxMonitoringTxDoesNotExist tx slot -> encodePretty $ object
656
+ [ " exists" .= False
657
+ , " txId" .= tx
658
+ , " slot" .= slot
659
+ ]
660
+ LocalTxMonitoringNextTx tx slot -> encodePretty $ object
661
+ [ " nextTx" .= (show tx :: String ) -- TODO Render this properly
662
+ , " slot" .= slot
663
+ ]
664
+ LocalTxMonitoringMempoolSizeAndCapacity mempool slot ->
665
+ encodePretty $ object
666
+ [ " capacityInBytes" .= capacityInBytes mempool
667
+ , " sizeInBytes" .= sizeInBytes mempool
668
+ , " numberOfTxs" .= numberOfTxs mempool
669
+ , " slot" .= slot
670
+ ]
623
671
624
672
-- | Obtain stake snapshot information for a pool, plus information about the total active stake.
625
673
-- This information can be used for leader slot calculation, for example, and has been requested by SPOs.
0 commit comments