Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeinsky committed Jul 25, 2022
1 parent 27640b8 commit a01afb6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
36 changes: 33 additions & 3 deletions plutus-chain-index/app/Marconi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -225,23 +227,51 @@ 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
void . forkIO . datumWorker coordinator ch $ fromJust datumPath
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
Expand Down Expand Up @@ -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 $
Expand Down
8 changes: 8 additions & 0 deletions plutus-chain-index/app/Marconi/Index/ScriptTx.hs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a01afb6

Please sign in to comment.