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

Finalize CLI implementation for endpoints in scope #189

Merged
merged 13 commits into from
May 4, 2019

Conversation

akegalj
Copy link
Contributor

@akegalj akegalj commented Apr 29, 2019

Issue Number

#96

Overview

  • I have ...

Comments

Playing out with types still to see what will play well. Will compare how we work with similar use case in HttpBridge and with our old v1 version

app/cli/Main.hs Outdated
res <- runClientM (listAddresses (ApiT wid) (Just $ ApiT Unused)) (mkClientEnv manager' (BaseUrl Http "localhost" 8080 ""))
case res of
Left err -> putStrLn $ "Error: " ++ show err
Right address -> print address
Copy link
Member

Choose a reason for hiding this comment

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

Please refer to #96 about the scope of the CLI commands for now :s ... This endpoint isn't in scope, nor implemented in the API at the moment.

app/cli/Main.hs Outdated
@@ -128,6 +135,11 @@ exec args
| args `isPresent` command "address" && args `isPresent` command "list" = do
wid <- args `parseArg` longOption "wallet-id"
print (wid :: WalletId)
manager' <- newManager defaultManagerSettings
res <- runClientM (listAddresses (ApiT wid) (Just $ ApiT Unused)) (mkClientEnv manager' (BaseUrl Http "localhost" 8080 ""))
Copy link
Member

Choose a reason for hiding this comment

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

We ought to create the connection manager before and pass it as argument I believe. In particular, the port address can be set via a CLI arg although, we don't have access to it at this stage 🤔 ...
I see two options:

  • Allow the port to be passed directly from the CLI for commands to (with default)
  • Do some network discovery and try to find a corresponding wallet backend service

The former sounds more reasonable in the time-frame we have to finalize this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes - I was about to opt for the former

app/cli/Main.hs Outdated
@@ -130,7 +136,11 @@ exec args
print (wid :: WalletId)

| args `isPresent` command "wallet" && args `isPresent` command "list" = do
return ()
walletPort <- args `parseArg` longOption "port"
res <- runClientM listWallets (mkClientEnv manager (BaseUrl Http "localhost" walletPort ""))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KtorZ

what do you think about this approach vs the one we have in httpBridge https://github.com/input-output-hk/cardano-wallet/blob/master/src/Cardano/Wallet/Network/HttpBridge.hs#L167 where we are wrapping client calls to a record and having a smart constructor in main which will construct this record to talk to the backend (we could call it WalletClient or similar).

With this one we are passing Manager to the exec where with the HttpBridge like we would defined WalletClient, defined the api calls in there and then create an instance of this in main and pass it to exec.

@akegalj akegalj force-pushed the akegalj/96/list-wallet-cli branch from 05ab1a2 to 20e147d Compare May 2, 2019 08:26
app/cli/Main.hs Outdated
let walletData =
WalletPostData
(Just $ ApiT poolGap)
(ApiMnemonicT (mnemonic, ["todo"]))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KtorZ
I don't have access to raw mnemonic sentance for ApiMnemonicT. Would we prefer to:

  1. Add ToMnemonic class similar to FromMnemonic that would convert Passphrase back to [Text]. This would involve implementing ToMnemonic typeclass and few instances in https://github.com/input-output-hk/cardano-wallet/blob/f54e90fcba9c60e780c0b4c710f335f8149c158d/src/Cardano/Wallet/Primitive/AddressDerivation.hs#L267 .

  2. Modify getRequiredSensitiveValue and getOptionalSensitiveValue to return tuple IO (a, Text) instead of current IO a

Copy link
Member

Choose a reason for hiding this comment

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

Passphrase back to [Text]

This isn't possible 😶 ... We have to go for 2), although, returning a is not really necessary here. We may simply try to parse the mnemonic, and in case of success, return the raw version as a [Text]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't possible

hm - I had a quick look at the FromMnemonic instance https://github.com/input-output-hk/cardano-wallet/blob/f54e90fcba9c60e780c0b4c710f335f8149c158d/src/Cardano/Wallet/Primitive/AddressDerivation.hs#L322 and my intuition was: well we just have to do entropyToBytes $ mnemonicToEntropy m in reverse - so something like toMnemonic . toEntropy. But maybe there is hidden complexity that I have overlooked.

Copy link
Member

Choose a reason for hiding this comment

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

To go from mnemonic words to entropy, there are actually some hash going on. So it's not reversible :/

@akegalj akegalj force-pushed the akegalj/96/list-wallet-cli branch from a1cbe94 to 607e715 Compare May 2, 2019 11:45
@KtorZ KtorZ force-pushed the akegalj/96/list-wallet-cli branch from 607e715 to 6499efa Compare May 4, 2019 08:27
@KtorZ KtorZ marked this pull request as ready for review May 4, 2019 14:44
@KtorZ KtorZ changed the title Experimenting with servant-client list wallet endpoint types Finalize CLI implementation for endpoints in scope May 4, 2019
@KtorZ KtorZ merged commit f12f20f into master May 4, 2019
@KtorZ KtorZ deleted the akegalj/96/list-wallet-cli branch May 4, 2019 15:22
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.

None yet

2 participants