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

Allow filtering by address state when fetching all addresses #372

Merged
merged 4 commits into from
Jun 10, 2019

Conversation

jonathanknowles
Copy link
Member

Issue Number

#356

Overview

I have:

  • Modified the listAddresses API server function to filter by the optional state query parameter.
  • Added a parseOptionalArg function to module Cardano.CLI.
  • Added an optional state filter argument to the cardano-wallet address list CLI command.

Comments

Just (Right a) -> pure $ pure a
Just (Left e) -> do
putErrLn $ T.pack $ getTextDecodingError e
exitFailure
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if we could print help (the Docopt) to the console after the failure instead (what getArgOrExitWith does)

Copy link
Member Author

@jonathanknowles jonathanknowles Jun 6, 2019

Choose a reason for hiding this comment

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

@akegalj wrote:

It would be nice if we could print help (the Docopt) to the console after the failure instead (what getArgOrExitWith does)

Thanks for this suggestion.

Actually, I can't help wondering if it wouldn't be nicer to print out something even more specific. Instead of printing out the entire help string whenever there's a problem, perhaps we could print out just the specific part that is relevant.

For example:

$ cardano-wallet address list --state on-fire 959b511ffa8213da57443226e3f9e230f956c446

Error: invalid address state: it should be either "used" nor "unused"

Usage: cardano-wallet address list [--port=INT] [--state=STRING] <wallet-id>

See here for a longer discussion: #371

I'm not sure if it's easy to do this with docopt. (Perhaps switching to optparse-applicative or some other library would make this easier.)

Copy link
Member Author

Choose a reason for hiding this comment

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

@akegalj Given that we can't (currently) print help that is specific to just one command, is it still your preference to print out the whole help string on failure? If so, I can add this in.

Copy link
Member Author

Choose a reason for hiding this comment

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

@akegalj We currently have this output when a user supplies an invalid value for --state:

$ cardano-wallet address list --state on-fire 959b511ffa8213da57443226e3f9e230f956c446
Unable to decode address state: it's neither "used" nor "unused"

Copy link
Contributor

@akegalj akegalj Jun 6, 2019

Choose a reason for hiding this comment

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

I am fine with the error output in this case.

And in general I am not sure that printing out the whole help as we usually do it atm is a user friendly thing to do. I would rather say "See 'cardano-wallet bla --help' for more details instead if you are interested" because if the whole help is printed then that usually hides the relevant error message.

I have proposed to print out help in this case just so that we can be consistent with the rest of the code - and so that we don't mix multiple styles of error handling in our CLI - and that is on our roadmap so I guess it will be handled soon.

@jonathanknowles jonathanknowles requested review from KtorZ and akegalj June 6, 2019 08:20
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/filtering-by-address-state branch from 995a323 to 9badd20 Compare June 6, 2019 08:26
@@ -143,6 +146,15 @@ parseAllArgsWith cli args option = do
getAllArgsOrExit :: Arguments -> Option -> IO (NE.NonEmpty String)
getAllArgsOrExit = getAllArgsOrExitWith cli

parseOptionalArg :: FromText a => Arguments -> Option -> IO (Maybe a)
parseOptionalArg args option =
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@jonathanknowles Maybe this would have been useful to use here instead:

https://github.com/input-output-hk/cardano-wallet/blob/master/exe/wallet/Main.hs#L369-L377 ?

An example:

https://github.com/input-output-hk/cardano-wallet/blob/master/exe/wallet/Main.hs#L224

@KtorZ I'll take a look at this later on to see whether we can use optional to simplify this code.

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.

Looks fine, though the sooner we get rid of docopt the better.

With docopt you need to write two "parsers" for each option. The first is in the help string (written in the docopt external DSL), and the second is where our code gets the argument and applies a parse function to it.

addrs <- liftHandler $ W.listAddresses w wid
return $ coerceAddress <$> addrs
return $ coerceAddress <$> filter filterCondition addrs
Copy link
Contributor

Choose a reason for hiding this comment

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

Not strictly relevant to this PR, but maybe in future we should cache addresses and their status in the database?

Copy link
Member

Choose a reason for hiding this comment

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

@rvl How do you envision caching here exactly 🤔 ?

@rvl rvl force-pushed the jonathanknowles/filtering-by-address-state branch from f96e644 to 03841b7 Compare June 7, 2019 06:26
@rvl
Copy link
Contributor

rvl commented Jun 7, 2019

Rebased on latest master to resolve merge conflict.

@KtorZ
Copy link
Member

KtorZ commented Jun 7, 2019

Looks fine, though the sooner we get rid of docopt the better.

@rvl As soon as we are done with Jormungandr's integration, I think this one will be good to have in the pipeline.

@jonathanknowles jonathanknowles merged commit fb30c13 into master Jun 10, 2019
@KtorZ KtorZ deleted the jonathanknowles/filtering-by-address-state branch June 14, 2019 20:29
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