-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…re-for-delegation-reward-balance [ADP-3071] Store for delegation reward balance
- Loading branch information
Showing
10 changed files
with
147 additions
and
104 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
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
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,49 @@ | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE NoMonomorphismRestriction #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
-- | | ||
-- Copyright: © 2022–2023 IOHK | ||
-- License: Apache-2.0 | ||
-- | ||
-- Rewards-history store and migration from old db tables. | ||
module Cardano.Wallet.DB.Store.Rewards.Store ( | ||
mkStoreRewards, | ||
) where | ||
|
||
import Prelude | ||
|
||
import Cardano.Wallet.DB.Sqlite.Schema | ||
( DelegationReward (..) ) | ||
import Control.Exception | ||
( SomeException (SomeException) ) | ||
import Data.Delta | ||
( Replace ) | ||
import Data.Store | ||
( UpdateStore, mkSimpleStore ) | ||
import Database.Persist.Sql | ||
( Entity (..), Filter, SqlPersistT, deleteWhere, insert_, selectList ) | ||
|
||
import qualified Cardano.Wallet.Primitive.Types as W | ||
import qualified Cardano.Wallet.Primitive.Types.Coin as W | ||
|
||
mkStoreRewards :: W.WalletId -> UpdateStore (SqlPersistT IO) (Replace W.Coin) | ||
mkStoreRewards wid = mkSimpleStore loadS' (writeS' wid) | ||
|
||
writeS' :: W.WalletId -> W.Coin -> SqlPersistT IO () | ||
writeS' wid x = do | ||
deleteWhere ([] :: [Filter DelegationReward]) | ||
insert_ $ DelegationReward wid $ W.unsafeToWord64 x | ||
|
||
loadS' :: SqlPersistT IO (Either SomeException W.Coin) | ||
loadS' = do | ||
xs <- selectList [] [] | ||
case xs of | ||
[Entity _ (DelegationReward _ y)] -> pure $ Right $ W.fromWord64 y | ||
[] -> pure $ Right $ W.Coin 0 | ||
_multiple -> | ||
pure | ||
$ Left | ||
$ SomeException | ||
$ userError "Multiple rewards found" |
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
Oops, something went wrong.