Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21cb489
commit b7870e5
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
lib/wallet/src/Cardano/Wallet/DB/Store/Transactions/Layer.hs
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,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 |