Skip to content

Commit

Permalink
Add module Marconi.Index.Common for common instances
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeinsky committed Feb 8, 2023
1 parent 1daea7c commit db783ff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions marconi/marconi.cabal
Expand Up @@ -51,6 +51,7 @@ library
exposed-modules:
Marconi.CLI
Marconi.Index.AddressDatum
Marconi.Index.Common
Marconi.Index.Datum
Marconi.Index.EpochStakepoolSize
Marconi.Index.ScriptTx
Expand Down
18 changes: 18 additions & 0 deletions marconi/src/Marconi/Index/Common.hs
@@ -0,0 +1,18 @@
module Marconi.Index.Common where

import Cardano.Api qualified as C
import Data.Functor ((<&>))
import Data.Maybe
import Data.Proxy (Proxy (Proxy))
import Database.SQLite.Simple qualified as SQL
import Database.SQLite.Simple.FromField qualified as SQL
import Database.SQLite.Simple.ToField qualified as SQL

instance SQL.ToField (C.Hash C.BlockHeader) where
toField f = SQL.toField $ C.serialiseToRawBytes f

instance SQL.FromField (C.Hash C.BlockHeader) where
fromField f =
SQL.fromField f <&>
fromMaybe (error "Cannot deserialise block hash") .
C.deserialiseFromRawBytes (C.proxyToAsType Proxy)
2 changes: 2 additions & 0 deletions marconi/src/Marconi/Index/ScriptTx.hs
Expand Up @@ -38,6 +38,8 @@ import RewindableIndex.Storable (Buffered (getStoredEvents, persistToStorage), H
filterWithQueryInterval)
import RewindableIndex.Storable qualified as Storable

import Marconi.Index.Common ()

{- The first thing that we need to define for a new indexer is the `handler` data
type, meant as a wrapper for the connection type (in this case the SQLite
connection).
Expand Down

0 comments on commit db783ff

Please sign in to comment.