Skip to content

Commit

Permalink
Add utility function to convert target address list to a predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeinsky committed Jun 5, 2023
1 parent d86659f commit 4f1647a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 2 additions & 5 deletions marconi-chain-index/src/Marconi/ChainIndex/Indexers.hs
Expand Up @@ -210,11 +210,8 @@ addressDatumWorker_ onInsert targetAddresses depth Coordinator{_barrier, _errorV
case event of
RollForward (BlockInMode (Block (BlockHeader slotNo bh _) txs) _) _ -> do
-- TODO Redo. Inefficient filtering
let addressFilter =
fmap (flip elem)
targetAddresses
addressDatumIndexEvent =
AddressDatum.toAddressDatumIndexEvent addressFilter txs (C.ChainPoint slotNo bh)
let addressDatumIndexEvent =
AddressDatum.toAddressDatumIndexEvent (Utils.addressesToPredicate targetAddresses) txs (C.ChainPoint slotNo bh)
void $ updateWith index _errorVar $ Storable.insert addressDatumIndexEvent
void $ onInsert addressDatumIndexEvent
innerLoop index
Expand Down
7 changes: 6 additions & 1 deletion marconi-chain-index/src/Marconi/ChainIndex/Utils.hs
Expand Up @@ -5,6 +5,7 @@ module Marconi.ChainIndex.Utils
, querySecurityParam
, querySecurityParamEra
, chainPointOrGenesis
, addressesToPredicate
) where

import Cardano.Api qualified as C
Expand All @@ -13,7 +14,7 @@ import Control.Monad.Except (ExceptT, throwError)
import Control.Monad.Trans (MonadTrans (lift))
import Data.Text (pack)
import Marconi.ChainIndex.Error (IndexerError (CantStartIndexer))
import Marconi.ChainIndex.Types (SecurityParam)
import Marconi.ChainIndex.Types (SecurityParam, TargetAddresses)
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch)

isBlockRollbackable :: SecurityParam -> C.BlockNo -> C.BlockNo -> Bool
Expand Down Expand Up @@ -64,3 +65,7 @@ chainPointOrGenesis :: [C.ChainPoint] -> C.ChainPoint
chainPointOrGenesis result = case result of
[] -> C.ChainPointAtGenesis
cp : _ -> cp

-- | Convert a list of target addresses to a predicate function
addressesToPredicate :: Maybe TargetAddresses -> Maybe (C.Address C.ShelleyAddr -> Bool)
addressesToPredicate = fmap (\list -> (`elem` list))

0 comments on commit 4f1647a

Please sign in to comment.