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

Integrate Jörmungandr backend with CLI. #483

Merged
merged 11 commits into from
Jun 28, 2019
Merged

Conversation

jonathanknowles
Copy link
Contributor

@jonathanknowles jonathanknowles commented Jun 26, 2019

Issue Number

#357

Overview

This PR forks our wallet CLI into two separate executables:

  1. cardano-wallet
    built with the cardano-wallet-http-bridge backend

  2. cardano-wallet-jormungandr
    built with the cardano-wallet-jormungandr backend

Parts common to both executables are located within the cardano-wallet-cli library.

Usage Examples

Launching with HTTP bridge backend

stack exec cardano-wallet -- launch

Launching with Jörmungandr backend

stack exec cardano-wallet-jormungandr -- launch \
    --backend-port=8081 \
    --genesis-hash=dba597bee5f0987efbf56f6bd7f44c38158a7770d0cb28a26b5eca40613a7ebd \
    --genesis-block=lib/jormungandr/test/data/jormungandr/block0.bin \
    --node-config=lib/jormungandr/test/data/jormungandr/config.yaml \
    --node-secret=lib/jormungandr/test/data/jormungandr/secret.yaml

Work not tackled by this PR

There is a small amount of code duplication between both executables (the execServe functions in exe/wallet/http-bridge/Main.hs and exe/wallet/jormungandr/Main.hs are very similar). Ideally, we should reduce this duplication (probably suitable for a future PR).

@jonathanknowles jonathanknowles changed the title WIP: Amend CLI to work with Jörmungandr backend. WIP: Integrate Jörmungandr backend with CLI. Jun 26, 2019
let jormungandr = Jormungandr.mkJormungandrLayer mgr url
let nl = Jormungandr.mkNetworkLayer jormungandr
waitForConnection nl defaultRetryPolicy
block0 <- unsafeRunExceptT $ getBlock jormungandr (coerce block0H)
Copy link
Member

Choose a reason for hiding this comment

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

FYI, we can retrieve block0H ourselves

{-# LANGUAGE OverloadedStrings #-}
import Cardano.Wallet.Jormungandr.Network
import Cardano.Wallet.Primitive.Types
import Cardano.Wallet.Unsafe
import Data.Coerce
    ( coerce )

main :: IO ()
main = do
    mgr <- newManager defaultManagerSettings
    let j = mkJormungandrLayer mgr (BaseUrl Http "localhost" 8081 "/api")
    let absentParent = Hash "\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL"
    [block0H] <- unsafeRunExceptT $ getDescendantIds j absentParent 1
    block0 <- unsafeRunExceptT $ getBlock j (coerce block0H)
    print block0

Copy link
Member

Choose a reason for hiding this comment

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

Yes and no. We do want the user to provide it such that we can verify they match!

@jonathanknowles jonathanknowles force-pushed the jonathanknowles/jormungandr-cli branch 4 times, most recently from e8f7b4c to 6f5b1d9 Compare June 28, 2019 04:05
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/jormungandr-cli branch from 6f5b1d9 to fda06ae Compare June 28, 2019 04:39
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/jormungandr-cli branch from 490cd3c to 388a257 Compare June 28, 2019 06:32
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/jormungandr-cli branch from bb38651 to 929c639 Compare June 28, 2019 07:02
…ent backends.

1. cardano-wallet-http-bridge
2. cardano-wallet-jormungandr
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/jormungandr-cli branch from ed017f7 to 96e491d Compare June 28, 2019 08:35
@jonathanknowles jonathanknowles marked this pull request as ready for review June 28, 2019 08:46
@jonathanknowles jonathanknowles changed the title WIP: Integrate Jörmungandr backend with CLI. Integrate Jörmungandr backend with CLI. Jun 28, 2019
<> cliOptionsGeneric
cliExamples = unlines $ filter (not . null) $ lines $ mempty
<> cliExamplesSpecific
<> cliExamplesGeneric
Copy link
Member

Choose a reason for hiding this comment

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

🤔 I think we're loosing the benefits of using docopt in a first place. I understand the need for removing duplication between both files yet I am not sure we are taking it to the right direction :/ .. It's probably the right time to switch to optparse-applicative for the CLI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we're loosing the benefits of using docopt in a first place. I understand the need for removing duplication between both files yet I am not sure we are taking it to the right direction :/ .. It's probably the right time to switch to optparse-applicative for the CLI.

I completely agree. Looking forward to trying a different direction with optparse-applicative here.

KtorZ added 3 commits June 28, 2019 13:07
The rationale here is to make it a bit easier to read
by outlining the different steps in the initialization
process and the creation of each layer.
@KtorZ KtorZ force-pushed the jonathanknowles/jormungandr-cli branch from e9c983b to 44ed2a7 Compare June 28, 2019 13:57
@KtorZ KtorZ merged commit d29879d into master Jun 28, 2019
@KtorZ KtorZ deleted the jonathanknowles/jormungandr-cli branch June 28, 2019 15:58
@KtorZ KtorZ added this to the Jörmungandr Integration Testing milestone Jul 2, 2019
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.

3 participants