Skip to content

Commit

Permalink
Events should be lists of txs, and moving counting to a zip
Browse files Browse the repository at this point in the history
  • Loading branch information
raduom committed Aug 8, 2022
1 parent 61868a9 commit 58fbc06
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions plutus-chain-index/src/Marconi/Index/TxConfirmationStatus.hs
Expand Up @@ -32,7 +32,7 @@ import Index.VSqlite (SqliteIndex)
import Index.VSqlite qualified as Ix

type Result = Maybe TxConfirmedState
type Event = (TxId, (Int, BlockNumber))
type Event = [(TxId, BlockNumber)]

type TCSIndex = SqliteIndex Event () TxId Result

Expand Down Expand Up @@ -69,8 +69,9 @@ query ix txId events = (<|>) <$> searchInMemory
searchInMemory :: IO Result
searchInMemory = do
buffered <- Ix.getBuffer $ ix ^. Ix.storage
let event = find ((== txId) . fst) $ events ++ buffered
pure $ event <&> \ (_, (cs, bn)) ->
let event = find ((== txId) . fst . snd)
$ zip [1..] (concat $ events ++ buffered)
pure $ event <&> \ (cs, (_, bn)) ->
TxConfirmedState { timesConfirmed = Sum cs
, blockAdded = Last $ Just bn
, validity = Last $ Just TxValid
Expand All @@ -93,11 +94,11 @@ store :: TCSIndex -> IO ()
store ix = do
events <- Ix.getEvents $ ix ^. Ix.storage
buffer <- Ix.getBuffer $ ix ^. Ix.storage
let all' = buffer ++ events
c = ix ^. Ix.handle
let all' = concat $ buffer ++ events
c = ix ^. Ix.handle
SQL.execute_ c "BEGIN"
forM_ all' $ \(txId, (block, _)) ->
SQL.execute c "INSERT INTO tx_status (txId, blockNumber) VALUES (?, ?)" (txId, block)
forM_ all' $
SQL.execute c "INSERT INTO tx_status (txId, blockNumber) VALUES (?, ?)"
SQL.execute_ c "COMMIT"

onInsert :: TCSIndex -> Event -> IO [()]
Expand Down

0 comments on commit 58fbc06

Please sign in to comment.