-
Notifications
You must be signed in to change notification settings - Fork 213
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
Remove defaultTxSortOrder #592
Remove defaultTxSortOrder #592
Conversation
lib/core/src/Cardano/Wallet.hs
Outdated
(w, _) <- withExceptT ErrListTransactionsNoSuchWallet $ _readWallet wid | ||
case (mStart, mEnd) of | ||
(Just start, Just end) -> when (start > end) $ throwE $ | ||
ErrListTransactionsStartTimeLaterThanEndTime $ | ||
ErrStartTimeLaterThanEndTime start end | ||
_ -> pure () | ||
let tip = currentTip w ^. #slotId | ||
let order = maybe Descending id mOrder |
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.
Maybe the walletLayer should take a SortOrder
instead of a Maybe SortOrder
and leave the Api
to decide on the default 🤷♂ I think this works though.
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 do agree 👍
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.
FWIW, I think that referring to a named constant (defined somewhere) within a function is greatly preferable to embedding a magic value. Having a named constant means that the code is more self-documenting.
I'd much prefer to see (not necessarily in the same module):
-- | The default sort order used when listing transactions, if none is specified.
defaultTxSortOrder :: SortOrder
defaultTxSortOrder = Descending
...
_listTransactions wid mStart mEnd mOrder = do
(w, _) <- withExceptT ErrListTransactionsNoSuchWallet $ _readWallet wid
case (mStart, mEnd) of
(Just start, Just end) -> when (start > end) $ throwE $
ErrListTransactionsStartTimeLaterThanEndTime $
ErrStartTimeLaterThanEndTime start end
_ -> pure ()
let tip = currentTip w ^. #slotId
let order = maybe defaultTxSortOrder id mOrder
...
than:
_listTransactions wid mStart mEnd mOrder = do
(w, _) <- withExceptT ErrListTransactionsNoSuchWallet $ _readWallet wid
case (mStart, mEnd) of
(Just start, Just end) -> when (start > end) $ throwE $
ErrListTransactionsStartTimeLaterThanEndTime $
ErrStartTimeLaterThanEndTime start end
_ -> pure ()
let tip = currentTip w ^. #slotId
let order = maybe Descending id mOrder
With the latter, I find myself thinking: "Where did this Descending
value come from?" Of course, we could add a comment, but in my opinion creating a constant with a suitable name to describe the intent is much clearer.
If the default is defined by the API, then one option is for the API server to refer to this named constant, and then explicitly pass the value down to subordinate functions in the lower layers (so that they don't have to refer to it).
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.
Probably the easiest way to test db sorting of the transactions is by modifying ReadTxHistory
in the state machine tests. Then it will make test cases with random combinations for you.
edit: oh, I see this is based on another PR which does that.
Why exactly 🤔 ? |
315fec4
to
13eab2e
Compare
30e3125
to
bf5a841
Compare
Because most use-cases didn't care about having a default sort order, they only needed an arbitrary sort order. (#588 (comment))
@jonathanknowles 👍 I have now removed the value from |
return $ map mkApiTransactionFromInfo txs | ||
where | ||
defaultSortOrder :: SortOrder | ||
defaultSortOrder = Descending |
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 notion of a default sort order for listTransactions
now only lives here in the Api. WalletLayer.listTransactions
doesn't have a default sort-order anymore.
bf5a841
to
0b7f866
Compare
Issue Number
#466
Overview
I have removedI have moved it from the WalletLayer to the Api.defaultTxSortOrder
_listTransactions
actually pass itsSortOrder
toDB.readTxHistory
Comments
Base is #588