-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add listTransactions in WalletLayer #497
Conversation
f13bc57
to
50ba757
Compare
50ba757
to
0215d82
Compare
txs `shouldBe` L.sortBy (comparing $ Down . slotId . snd) txs | ||
case txs of | ||
(a:b:_) -> | ||
((slotId . snd $ a) >= (slotId . snd $ b)) `shouldBe` True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this.
I like the >=
because it's easy to comprehend, but it is just comparing the first two elements, so we need the re-implementation of the sorting on L354.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion:
isSortedDesc = all (uncurry (<=)) . (\xs -> zip (drop 1 xs) xs) $ txs
if isSortedDesc
then return ()
else $ expectationFailure $ "..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the txs == sort txs
form of assertion.
0215d82
to
ba08044
Compare
txs `shouldBe` L.sortBy (comparing $ Down . slotId . snd) txs | ||
case txs of | ||
(a:b:_) -> | ||
((slotId . snd $ a) >= (slotId . snd $ b)) `shouldBe` True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion:
isSortedDesc = all (uncurry (<=)) . (\xs -> zip (drop 1 xs) xs) $ txs
if isSortedDesc
then return ()
else $ expectationFailure $ "..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff.
I would like to move sorting down to the DB, but the test case can stay in the Wallet layer.
lib/core/src/Cardano/Wallet.hs
Outdated
_listTransactions wid = liftIO $ | ||
L.sortOn slotIdDescending | ||
. map snd | ||
. Map.toList <$> DB.readTxHistory db (PrimaryKey wid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think sorting is very much a job for the DBLayer.
Can we
- Add a comment on
DBLayer.readTxHistory
saying that the Map short be sorted descending by slot. - Adjust the DBLayer backends accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KtorZ (asking here instead) you said
Either we gotta change the type (which I think isn't really a good idea), or do the sorting in-memory in the handler itself.
Could you elaborate on why you didn't think it was a good idea?
I'm still familiarising myself with the Sqlite schema (+ sqlite). Could we not either:
-
Just make
txHistoryFromEntity
return a sorted[(W.Tx t, W.TxMeta)]
given a sorted[W.TxMeta]
instead of returning aMap
? It seems like we currently only usereadTxHistory
inWalletLayer._listAddresses
. -
Use only one select (from three tables at once
tx_meta
,tx_in
andtx_out
)… somehow? (not sure if this is possible)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why you didn't think it was a good idea?
Mainly because of the rippling effect and the amount of changes it involves in the code-base. If we've to go through this, then, we'll have too :)
txs `shouldBe` L.sortBy (comparing $ Down . slotId . snd) txs | ||
case txs of | ||
(a:b:_) -> | ||
((slotId . snd $ a) >= (slotId . snd $ b)) `shouldBe` True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the txs == sort txs
form of assertion.
bd241e1
to
79bbf29
Compare
@Anviking What's the status with this one? |
My plan was to change the type of Although I'd be happy if you weighed in because I'm not sure this is strictly necessary, even though it would make sense: Not completely final implementation with ugly If you disagree this could be merged. |
Ok. What's missing from the branch you copy/pasted at the end of your message 🤔 ? |
@KtorZ (Then one could ask one selves if |
I got the tests compiling in a brute-force way by converting back and forth between the Wild guesses
I will try
|
@Anviking May you push somewhere whatever you have available for me to have a look 🤔 ? |
@KtorZ https://github.com/input-output-hk/cardano-wallet/compare/anviking/465/change-txHistory-type It is on this branch. Maybe it should be a separate pr to this after all? |
Ah. Will look at this branch then. (PS: you shouldn't put |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test case looks good.
lib/core/src/Cardano/Wallet.hs
Outdated
_listTransactions | ||
:: WalletId | ||
-> ExceptT ErrNoSuchWallet IO [(Tx t, TxMeta)] | ||
_listTransactions wid = liftIO $ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use #524 to handle sorting, then change this to:
_listTransactions wid = liftIO $ | |
_listTransactions wid = liftIO $ map snd <$> DB.readTxHistory db (PrimaryKey wid) | |
5779f93
to
87b5def
Compare
87b5def
to
10f4381
Compare
I'm thinking hooking this up with the api can go in a separate pr with some integration tests. merging |
Issue Number
#465
Overview
listTransactions :: WalletId -> ExceptT ErrNoSuchWallet IO [(Tx t, TxMeta)]
sorted descending onslotId
.Comments