Skip to content

Commit

Permalink
Marconi index utxo for aditional slot info
Browse files Browse the repository at this point in the history
Add CLI golden tests for marconi
  • Loading branch information
kayvank committed Dec 4, 2022
1 parent 1596c33 commit 4a14855
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 487 deletions.
2 changes: 1 addition & 1 deletion marconi-mamba/examples/json-rpc-server/src/Main.hs
Expand Up @@ -19,7 +19,7 @@ import Marconi.Api.Types (DBQueryEnv, HasDBQueryEnv (queryTMVar), HasJsonRpcEnv
unUtxoIndex)
import Marconi.Bootstrap (bootstrapHttp, bootstrapJsonRpc)
import Marconi.CLI (multiString)
import Marconi.Index.Utxos (Depth (Depth), open)
import Marconi.Index.Utxo (Depth (Depth), open)


data CliOptions = CliOptions
Expand Down
2 changes: 1 addition & 1 deletion marconi-mamba/src/Marconi/Api/Types.hs
Expand Up @@ -38,7 +38,7 @@ import GHC.Generics (Generic)
import Network.Wai.Handler.Warp (Settings)

import Cardano.Api (NetworkId)
import Marconi.Index.Utxos (UtxoRow)
import Marconi.Index.Utxo (UtxoRow)
import Marconi.Indexers (UtxoQueryTMVar (UtxoQueryTMVar, unUtxoIndex))
import Marconi.Types as Export (TargetAddresses)

Expand Down
16 changes: 8 additions & 8 deletions marconi-mamba/src/Marconi/Api/UtxoIndexersQuery.hs
Expand Up @@ -6,8 +6,8 @@ module Marconi.Api.UtxoIndexersQuery
, findByAddress
, findAll
, reportQueryAddresses
, Utxos.UtxoRow(..)
, Utxos.UtxoIndex
, Utxo.UtxoRow(..)
, Utxo.UtxoIndex
, reportQueryCardanoAddresses
, reportBech32Addresses
, withQueryAction
Expand All @@ -26,7 +26,7 @@ import Marconi.Api.Types (DBQueryEnv (DBQueryEnv, _queryAddresses, _queryTMVar),
HasDBQueryEnv (queryAddresses, queryTMVar),
QueryExceptions (AddressNotInListError, QueryError), TargetAddresses,
UtxoTxOutReport (UtxoTxOutReport))
import Marconi.Index.Utxos qualified as Utxos
import Marconi.Index.Utxo qualified as Utxo
import Marconi.Indexers (UtxoQueryTMVar (UtxoQueryTMVar, unUtxoIndex))

-- | Bootstraps the utxo query environment.
Expand All @@ -36,7 +36,7 @@ bootstrap
:: TargetAddresses -- ^ user provided target addresses
-> IO DBQueryEnv -- ^ returns Query runtime environment
bootstrap targetAddresses = do
ix <- atomically (newEmptyTMVar :: STM (TMVar Utxos.UtxoIndex) )
ix <- atomically (newEmptyTMVar :: STM (TMVar Utxo.UtxoIndex) )
pure $ DBQueryEnv
{_queryTMVar = UtxoQueryTMVar ix
, _queryAddresses = targetAddresses
Expand All @@ -60,7 +60,7 @@ findAll env = forConcurrently addresses f
findByCardanoAddress
:: DBQueryEnv -- ^ Query run time environment
-> C.AddressAny -- ^ Cardano address to query
-> IO [Utxos.UtxoRow]
-> IO [Utxo.UtxoRow]
findByCardanoAddress env address = withQueryAction env address

-- | Retrieve a Set of TxOutRefs associated with the given Cardano Era address
Expand Down Expand Up @@ -90,12 +90,12 @@ findByAddress env addressText =
withQueryAction
:: DBQueryEnv -- ^ Query run time environment
-> C.AddressAny -- ^ Cardano address to query
-> IO [Utxos.UtxoRow]
-> IO [Utxo.UtxoRow]
withQueryAction env address =
let
utxoIndexer = unUtxoIndex $ env ^. queryTMVar
action :: Utxos.UtxoIndex -> IO [Utxos.UtxoRow]
action ndxr = (Utxos.queryPlusVolatile ndxr address) >>= pure . (\case { Just x -> x; _ -> [] })
action :: Utxo.UtxoIndex -> IO [Utxo.UtxoRow]
action ndxr = (Utxo.queryPlusVolatile ndxr address) >>= pure . (\case { Just x -> x; _ -> [] })
in
bracket
(atomically $ takeTMVar utxoIndexer)
Expand Down
10 changes: 7 additions & 3 deletions marconi/marconi.cabal
Expand Up @@ -46,7 +46,7 @@ library
Marconi.CLI
Marconi.Index.Datum
Marconi.Index.ScriptTx
Marconi.Index.Utxos
Marconi.Index.Utxo
Marconi.Indexers
Marconi.Logging
Marconi.Orphans
Expand Down Expand Up @@ -125,8 +125,9 @@ test-suite marconi-test
main-is: Spec.hs
hs-source-dirs: test
other-modules:
Index.Spec
Integration
Spec.Cli
Spec.Utxo

--------------------
-- Local components
Expand All @@ -153,20 +154,23 @@ test-suite marconi-test
------------------------
build-depends:
, aeson
, base >=4.9 && <5
, base >=4.9 && <5
, bytestring
, containers
, directory
, filepath
, hedgehog
, hedgehog-extras
, lens
, optparse-applicative
, prettyprinter
, serialise
, sqlite-simple
, stm
, streaming
, tasty
, tasty-golden
, tasty-hedgehog
, tasty-hunit
, temporary
, text
1 change: 1 addition & 0 deletions marconi/src/Marconi/CLI.hs
Expand Up @@ -6,6 +6,7 @@ module Marconi.CLI
, parseCardanoAddresses
, pNetworkId
, Options (..)
, optionsParser
, parseOptions
, utxoDbPath
, datumDbPath
Expand Down

0 comments on commit 4a14855

Please sign in to comment.