Skip to content

Commit

Permalink
Add 'DB' for 'TxSet'
Browse files Browse the repository at this point in the history
  • Loading branch information
HeinrichApfelmus authored and paolino committed Nov 29, 2022
1 parent 21cb489 commit b7870e5
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions lib/wallet/src/Cardano/Wallet/DB/Store/Transactions/Layer.hs
@@ -0,0 +1,51 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}

{- |
Copyright: © 2022 IOHK
License: Apache-2.0
Implementation of a 'DB' for 'TxSet'.
-}
module Cardano.Wallet.DB.Store.Transactions.Layer
( ReadTxSet (..)
, mkDBTxSet
) where

import Prelude

import Cardano.Wallet.DB
( DB (..), untry )
import Cardano.Wallet.DB.Sqlite.Types
( TxId )
import Cardano.Wallet.DB.Store.Transactions.Model
( DeltaTxSet, TxRelation )
import Data.DBVar
( Store (..) )
import Database.Persist.Sql
( SqlPersistT )

import qualified Cardano.Wallet.DB.Store.Transactions.Store as TxSet

{-----------------------------------------------------------------------------
DB for 'TxSet'
------------------------------------------------------------------------------}
data ReadTxSet b where
GetByTxId :: TxId -> ReadTxSet (Maybe TxRelation)

-- | Implementation of a 'DB' for 'TxSet'.
mkDBTxSet :: DB (SqlPersistT IO) ReadTxSet DeltaTxSet
mkDBTxSet = DB
{ readDB = \case
GetByTxId txid -> TxSet.selectTx txid
, loadDB = untry loadS
, writeDB = writeS
, updateDB = TxSet.updateTxSet
}
where
Store{loadS,writeS} = TxSet.mkStoreTransactions

0 comments on commit b7870e5

Please sign in to comment.