Skip to content
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

Merged

Conversation

Anviking
Copy link
Member

@Anviking Anviking commented Jul 30, 2019

Issue Number

#466

Overview

  • I have removed defaultTxSortOrder I have moved it from the WalletLayer to the Api.
  • I made _listTransactions actually pass its SortOrder to DB.readTxHistory

Comments

Base is #588

@Anviking Anviking self-assigned this Jul 30, 2019
(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
Copy link
Member Author

@Anviking Anviking Jul 30, 2019

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree 👍

Copy link
Member

@jonathanknowles jonathanknowles left a 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).

Copy link
Contributor

@rvl rvl left a 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.

@KtorZ
Copy link
Member

KtorZ commented Jul 31, 2019

@Anviking

I have removed defaultTxSortOrder

Why exactly 🤔 ?

@Anviking Anviking force-pushed the anviking/466/add-filtering-to-db branch from 315fec4 to 13eab2e Compare July 31, 2019 12:03
@Anviking Anviking force-pushed the anviking/466/remove-defaultTxSortOrder branch from 30e3125 to bf5a841 Compare July 31, 2019 12:51
@Anviking
Copy link
Member Author

Why exactly

Because most use-cases didn't care about having a default sort order, they only needed an arbitrary sort order. (#588 (comment))

I'd much prefer to see (not necessarily in the same module):

@jonathanknowles 👍 I have now removed the value from WalletLayer.listTransactions and defined it in the where-clause of the Api listTransactions handle.

return $ map mkApiTransactionFromInfo txs
where
defaultSortOrder :: SortOrder
defaultSortOrder = Descending
Copy link
Member Author

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.

@Anviking Anviking force-pushed the anviking/466/remove-defaultTxSortOrder branch from bf5a841 to 0b7f866 Compare July 31, 2019 13:15
@KtorZ KtorZ merged commit 37e9242 into anviking/466/add-filtering-to-db Jul 31, 2019
@KtorZ KtorZ deleted the anviking/466/remove-defaultTxSortOrder branch July 31, 2019 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants