Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add module Marconi.Index.Common for common instances
- Loading branch information
Showing
3 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters