From a01afb61cff3ac641cc8b1c049ee002181205bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20L=C3=A4ll?= Date: Mon, 25 Jul 2022 15:44:14 +0300 Subject: [PATCH] wip --- plutus-chain-index/app/Marconi.hs | 36 +++++++++++++++++-- .../app/Marconi/Index/ScriptTx.hs | 8 +++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 plutus-chain-index/app/Marconi/Index/ScriptTx.hs diff --git a/plutus-chain-index/app/Marconi.hs b/plutus-chain-index/app/Marconi.hs index 8ee6c17bc8..f9073d8d8d 100644 --- a/plutus-chain-index/app/Marconi.hs +++ b/plutus-chain-index/app/Marconi.hs @@ -34,6 +34,8 @@ import Ledger.Tx.CardanoAPI (fromCardanoTxId, fromCardanoTxIn, fromCardanoTxOut, scriptDataFromCardanoTxBody) import Marconi.Index.Datum (DatumIndex) import Marconi.Index.Datum qualified as Datum +import Marconi.Index.ScriptTx () +import Marconi.Index.ScriptTx qualified as ScriptTx import Marconi.Index.Utxo (UtxoIndex, UtxoUpdate (..)) import Marconi.Index.Utxo qualified as Utxo import Marconi.Logging (logging) @@ -225,16 +227,41 @@ utxoWorker Coordinator{_barrier} ch path = Utxo.open path (Utxo.Depth 2160) >>= offset <- findIndex (\u -> (u ^. Utxo.slotNo) < slot) events Ix.rewind offset index +scriptTxWorker + :: Coordinator + -> TChan (ChainSyncEvent (BlockInMode CardanoMode)) + -> FilePath + -> IO () +scriptTxWorker Coordinator{_barrier} ch path = ScriptTx.open path (ScriptTx.Depth 2160) >>= innerLoop + where + innerLoop :: ScriptTx.ScriptTxIndex -> IO () + innerLoop index = do + signalQSemN _barrier 1 + event <- atomically $ readTChan ch + case event of + RollForward (BlockInMode (Block (BlockHeader slotNo _ _) txs) _) _ct -> + -- Ix.insert (getUtxoUpdate slotNo txs) index >>= innerLoop + Ix.insert undefined index >>= innerLoop + RollBackward cp _ct -> do + undefined + -- events <- Ix.getEvents (index ^. Ix.storage) + -- innerLoop $ + -- fromMaybe index $ do + -- slot <- chainPointToSlotNo cp + -- offset <- findIndex (\u -> (u ^. Utxo.slotNo) < slot) events + -- Ix.rewind offset index + combinedIndexer :: Maybe FilePath -> Maybe FilePath + -> Maybe FilePath -> S.Stream (S.Of (ChainSyncEvent (BlockInMode CardanoMode))) IO r -> IO () -combinedIndexer utxoPath datumPath = S.foldM_ step initial finish +combinedIndexer utxoPath datumPath scriptTxPath = S.foldM_ step initial finish where initial :: IO Coordinator initial = do - let indexerCount = length . catMaybes $ [utxoPath, datumPath] + let indexerCount = length . catMaybes $ [utxoPath, datumPath, scriptTxPath] coordinator <- initialCoordinator indexerCount when (isJust datumPath) $ do ch <- atomically . dupTChan $ _channel coordinator @@ -242,6 +269,9 @@ combinedIndexer utxoPath datumPath = S.foldM_ step initial finish when (isJust utxoPath) $ do ch <- atomically . dupTChan $ _channel coordinator void . forkIO . utxoWorker coordinator ch $ fromJust utxoPath + when (isJust scriptTxPath) $ do + ch <- atomically . dupTChan $ _channel coordinator + void . forkIO . scriptTxWorker coordinator ch $ fromJust scriptTxPath pure coordinator step :: Coordinator -> ChainSyncEvent (BlockInMode CardanoMode) -> IO Coordinator @@ -269,7 +299,7 @@ main = do optionsSocketPath optionsNetworkId optionsChainPoint - (combinedIndexer optionsUtxoPath optionsDatumPath . logging trace) + (combinedIndexer optionsUtxoPath optionsDatumPath optionsScriptTxPath . logging trace) `catch` \NoIntersectionFound -> logError trace $ renderStrict $ diff --git a/plutus-chain-index/app/Marconi/Index/ScriptTx.hs b/plutus-chain-index/app/Marconi/Index/ScriptTx.hs new file mode 100644 index 0000000000..2fb6eedfc8 --- /dev/null +++ b/plutus-chain-index/app/Marconi/Index/ScriptTx.hs @@ -0,0 +1,8 @@ +module Marconi.Index.ScriptTx where + +newtype Depth = Depth Int + +data ScriptTxIndex = ScriptTxIndex + +open :: FilePath -> Depth -> IO ScriptTxIndex +open path (Depth k) = undefined