Skip to content

Commit

Permalink
rename readTxHistory in readTransactions
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino authored and erikd committed Jan 31, 2023
1 parent b1c32ec commit c40d499
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/wallet/bench/db-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ benchReadTxHistory
-> DBLayerBench
-> IO [TransactionInfo]
benchReadTxHistory sortOrder (inf, sup) mstatus DBLayer{..} =
atomically $ readTxHistory testWid Nothing sortOrder range mstatus
atomically $ readTransactions testWid Nothing sortOrder range mstatus
where
range = Range
(SlotNo . fromIntegral <$> inf)
Expand Down
7 changes: 4 additions & 3 deletions lib/wallet/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,8 @@ readWallet
readWallet ctx wid = db & \DBLayer{..} -> mapExceptT atomically $ do
cp <- withNoSuchWallet wid $ readCheckpoint wid
meta <- withNoSuchWallet wid $ readWalletMeta wid
pending <- lift $ readTxHistory wid Nothing Descending wholeRange (Just Pending)
pending <- lift
$ readTransactions wid Nothing Descending wholeRange (Just Pending)
pure (cp, meta, Set.fromList (fromTransactionInfo <$> pending))
where
db = ctx ^. dbLayer @IO @s @k
Expand Down Expand Up @@ -3066,7 +3067,7 @@ listTransactions ctx wid mMinWithdrawal mStart mEnd order = db & \DBLayer{..} ->
mapExceptT atomically $ do
mapExceptT liftIO getSlotRange >>= maybe
(pure [])
(\r -> lift (readTxHistory wid mMinWithdrawal order r Nothing))
(\r -> lift (readTransactions wid mMinWithdrawal order r Nothing))
where
ti :: TimeInterpreter (ExceptT PastHorizonException IO)
ti = timeInterpreter (ctx ^. networkLayer)
Expand Down Expand Up @@ -3099,7 +3100,7 @@ listAssets ctx wid = db & \DBLayer{..} -> do
txs <- lift . atomically $
let noMinWithdrawal = Nothing
allTxStatuses = Nothing
in readTxHistory wid noMinWithdrawal Ascending wholeRange allTxStatuses
in readTransactions wid noMinWithdrawal Ascending wholeRange allTxStatuses
let txAssets :: TransactionInfo -> Set TokenMap.AssetId
txAssets = Set.unions
. map (TokenBundle.getAssets . view #tokens)
Expand Down
4 changes: 2 additions & 2 deletions lib/wallet/src/Cardano/Wallet/DB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ data DBLayer m s k = forall stm. (MonadIO stm, MonadFail stm) => DBLayer
--
-- If the wallet doesn't exist, this operation returns an error.

, readTxHistory
, readTransactions
:: WalletId
-> Maybe Coin
-> SortOrder
Expand Down Expand Up @@ -468,7 +468,7 @@ mkDBLayerFromParts ti DBLayerCollection{..} = DBLayer
readDelegationRewardBalance_ (dbDelegation wid)
, putTxHistory = \wid a -> wrapNoSuchWallet wid $
putTxHistory_ dbTxHistory wid a
, readTxHistory = \wid minWithdrawal order range status ->
, readTransactions = \wid minWithdrawal order range status ->
readCurrentTip wid >>= \case
Just tip -> do
tinfos <- (readTxHistory_ dbTxHistory) wid range status tip
Expand Down
2 changes: 1 addition & 1 deletion lib/wallet/src/Cardano/Wallet/DB/Pure/Implementation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ data WalletDatabase s xprv = WalletDatabase
-- | Shorthand for the putTxHistory argument type.
type TxHistoryMap = Map (Hash "Tx") (Tx, TxMeta)

-- | Shorthand for the readTxHistory result type.
-- | Shorthand for the readTransactions result type.
type TxHistory = [(Tx, TxMeta)]

-- | Produces an empty model database.
Expand Down
2 changes: 1 addition & 1 deletion lib/wallet/src/Cardano/Wallet/DB/Pure/Layer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ newDBLayer timeInterpreter = do
alterDB errNoSuchWallet db $
mPutTxHistory pk txh

, readTxHistory = \pk minWithdrawal order range mstatus ->
, readTransactions = \pk minWithdrawal order range mstatus ->
readDB db $
mReadTxHistory
timeInterpreter
Expand Down
20 changes: 12 additions & 8 deletions lib/wallet/test/unit/Cardano/Wallet/DB/LayerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,9 @@ fileModeSpec = do
unsafeRunExceptT $ putTxHistory testWid testTxs
testOpeningCleaning
f
(\db' -> readTxHistory' db' testWid Ascending wholeRange Nothing)
(\db' ->
readTransactions' db' testWid Ascending wholeRange Nothing
)
testTxs -- expected after opening db
mempty -- expected after cleaning db

Expand All @@ -529,7 +531,9 @@ fileModeSpec = do
unsafeRunExceptT $ putTxHistory testWid testTxs
testOpeningCleaning
f
(\db' -> readTxHistory' db' testWid Descending wholeRange Nothing)
(\db' ->
readTransactions' db' testWid Descending wholeRange Nothing
)
(reverse testTxs) -- expected after opening db
mempty -- expected after cleaning db

Expand Down Expand Up @@ -933,15 +937,15 @@ readWalletMeta'
readWalletMeta' DBLayer{..} =
atomically . readWalletMeta

readTxHistory'
readTransactions'
:: DBLayer m s k
-> WalletId
-> SortOrder
-> Range SlotNo
-> Maybe TxStatus
-> m [(Tx, TxMeta)]
readTxHistory' DBLayer{..} a0 a1 a2 =
atomically . fmap (fmap toTxHistory) . readTxHistory a0 Nothing a1 a2
readTransactions' DBLayer{..} a0 a1 a2 =
atomically . fmap (fmap toTxHistory) . readTransactions a0 Nothing a1 a2

readPrivateKey'
:: DBLayer m s k
Expand Down Expand Up @@ -1156,7 +1160,7 @@ testMigrationTxMetaFee dbName expectedLength caseByCase = do
$ \DBLayer{..} -> atomically
$ do
[wid] <- listWallets
readTxHistory wid Nothing Descending wholeRange Nothing
readTransactions wid Nothing Descending wholeRange Nothing

-- Check that we've indeed logged a needed migration for 'fee'
length (filter isMsgManualMigration logs) `shouldBe` 1
Expand Down Expand Up @@ -1482,14 +1486,14 @@ getAvailableBalance DBLayer{..} = do
cp <- fmap (fromMaybe (error "nothing")) <$>
atomically $ readCheckpoint testWid
pend <- atomically $ fmap toTxHistory
<$> readTxHistory testWid Nothing Descending wholeRange (Just Pending)
<$> readTransactions testWid Nothing Descending wholeRange (Just Pending)
return $ fromIntegral $ unCoin $ TokenBundle.getCoin $
availableBalance (Set.fromList $ map fst pend) cp

getTxsInLedger :: DBLayer IO s k -> IO ([(Direction, Natural)])
getTxsInLedger DBLayer {..} = do
pend <- atomically $ fmap toTxHistory
<$> readTxHistory testWid Nothing Descending wholeRange (Just InLedger)
<$> readTransactions testWid Nothing Descending wholeRange (Just InLedger)
pure $ map (\(_, m) -> (direction m, fromIntegral $ unCoin $ amount m)) pend

{-------------------------------------------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions lib/wallet/test/unit/Cardano/Wallet/DB/Properties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,16 @@ properties = do
it "Correctly re-construct tx history on rollbacks"
(checkCoverage . prop_rollbackTxHistory)

-- | Wrap the result of 'readTxHistory' in an arbitrary identity Applicative
-- | Wrap the result of 'readTransactions' in an arbitrary identity Applicative
readTxHistory_
:: Functor m
=> DBLayer m s ShelleyKey
-> WalletId
-> m (Identity GenTxHistory)
readTxHistory_ DBLayer{..} wid =
(Identity . GenTxHistory . fmap toTxHistory)
<$> atomically (readTxHistory wid Nothing Descending wholeRange Nothing)
<$> atomically
(readTransactions wid Nothing Descending wholeRange Nothing)

putTxHistory_
:: DBLayer m s ShelleyKey
Expand Down Expand Up @@ -320,7 +321,7 @@ unions =
. foldl (\m (k, v) -> Map.unionWith (<>) (Map.fromList [(k, v)]) m) mempty

-- | Keep the unions (right-biased) of all transactions, and sort them in the
-- default order for readTxHistory.
-- default order for readTransactions.
sortedUnions :: Ord k => [(k, GenTxHistory)] -> [Identity GenTxHistory]
sortedUnions = map (Identity . sort' . runIdentity) . unions
where
Expand Down Expand Up @@ -791,7 +792,7 @@ prop_rollbackTxHistory db@DBLayer{..} (InitialCheckpoint cp0) (GenTxHistory txs0
point <- run $ unsafeRunExceptT $ mapExceptT atomically $
rollbackTo wid (At requestedPoint)
txs <- run $ atomically $ fmap toTxHistory
<$> readTxHistory wid Nothing Descending wholeRange Nothing
<$> readTransactions wid Nothing Descending wholeRange Nothing

monitor $ counterexample $ "\n" <> "Actual Rollback Point:\n" <> (pretty point)
monitor $ counterexample $ "\nOriginal tx history:\n" <> (txsF txs0)
Expand Down
10 changes: 5 additions & 5 deletions lib/wallet/test/unit/Cardano/Wallet/DB/StateMachine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ runIO db@DBLayer{..} = fmap Resp . go
ReadTxHistory wid minWith order range status ->
fmap (Right . TxHistory) $
atomically $
readTxHistory wid minWith order range status
readTransactions wid minWith order range status
GetTx wid tid ->
catchNoSuchWallet (TxHistory . maybe [] pure) $
mapExceptT atomically $ getTx wid tid
Expand Down Expand Up @@ -1154,8 +1154,8 @@ tag = Foldl.fold $ catMaybes <$> sequenceA
, createWalletTwice
, removeWalletTwice
, createThenList
, readTxHistory (not . null) SuccessfulReadTxHistory
, readTxHistory null UnsuccessfulReadTxHistory
, readTransactions (not . null) SuccessfulReadTxHistory
, readTransactions null UnsuccessfulReadTxHistory
, txUnsorted inputs TxUnsortedInputs
, txUnsorted outputs TxUnsortedOutputs
, readCheckpoint isJust SuccessfulReadCheckpoint
Expand Down Expand Up @@ -1291,11 +1291,11 @@ tag = Foldl.fold $ catMaybes <$> sequenceA
| or created = Just CreateThenList
| otherwise = Nothing

readTxHistory
readTransactions
:: ([TransactionInfo] -> Bool)
-> Tag
-> Fold (Event s Symbolic) (Maybe Tag)
readTxHistory check res = Fold update False (extractf res)
readTransactions check res = Fold update False (extractf res)
where
update :: Bool -> Event s Symbolic -> Bool
update didRead ev = didRead || case (cmd ev, mockResp ev) of
Expand Down

0 comments on commit c40d499

Please sign in to comment.