Skip to content

Commit

Permalink
Merge #862 #864 #878 #879
Browse files Browse the repository at this point in the history
862: jormungandr launch: use --rest-listen instead of generating config.yaml r=KtorZ a=rvl

Relates to #832 and #848.
Supersedes #850.

# Overview

`cardano-wallet-jormungandr launch` specifies the REST API port and storage directory. The user provides the rest of the Jörmungandr configuration (e.g. trusted peers). 

# Comments

The Jörmungandr P2P listen address, port, and log level are no longer configured by cardano-wallet.


864: nix: Provide derivations for Daedalus installer r=KtorZ a=rvl

Relates to #863.
Based on #828.

# Overview

- @disassembler @cleverca22 It's not exactly the same as before but should work ok I think.
- Adds source filtering to avoid unnecessary rebuilds.

# Comments

To build:

```
nix-build -A cardano-wallet-jormungandr
nix-build release.nix -A daedalus-jormungandr.windows -o daedalus-jormungandr-windows
nix-build release.nix -A daedalus-jormungandr.macos -o daedalus-jormungandr-macos
nix-build release.nix -A daedalus-jormungandr.linux -o daedalus-jormungandr-linux
```

Note that `daedalus-jormungandr.{windows,macos,linux}` from `release.nix` reference the same `cardano-wallet-jormungandr` derivation, only with different `system` or `crossSystem` arguments. So Daedalus may also import from `default.nix` rather than `release.nix`.

878: Support for legacy UTxO witness in Jörmungandr r=KtorZ a=KtorZ

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->

#779 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- [x] I have extended `mkStdTx` so that it would properly handle transactions coming from a `RndKey` and construct `legacy-utxo` witnesses for it.

# Comments

<!-- Additional comments or screenshots to attach if any -->

Jörmungandr doesn't implement creating legacy utxo witnesses from jcli ... 

[jcli/src/jcli_app/transaction/mk_witness.rs](https://github.com/input-output-hk/jormungandr/blob/master/jcli/src/jcli_app/transaction/mk_witness.rs#L78-L82)
```rust
            WitnessType::OldUTxO => {
                // TODO unimplemented!()
                let _secret_key: SecretKey<Ed25519Bip32> = self.secret()?;
                Err(Error::MakeWitnessLegacyUtxoUnsupported)?;
                unimplemented!()
            }
``` 

so I had to construct them by hand according to:

- The format defined in [chain-impl-mockchain#witnesses](https://github.com/input-output-hk/chain-libs/blob/incentive/chain-impl-mockchain/doc/format.md#witnesses)

- The format from the source (double checking it matches the doc..) [chain-impl-mockchain/src/transaction/witness.rs](https://github.com/input-output-hk/chain-libs/blob/incentive/chain-impl-mockchain/src/transaction/witness.rs#L173-L176)

It'd be nice to review our golden if / when the constructor for the witness type gets updated.

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Acknowledge any changes required to the Wiki
-->


879: Porting the rest of forget pending tx integration tests to CLI r=KtorZ a=paweljakubas

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->
#836 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- [x] I have ported the rest of forgetting pending tx integration tests to CLI

# Comments

<!-- Additional comments or screenshots to attach if any -->

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: Rodney Lorrimar <rodney.lorrimar@iohk.io>
Co-authored-by: KtorZ <matthias.benkort@gmail.com>
Co-authored-by: Pawel Jakubas <pawel.jakubas@iohk.io>
  • Loading branch information
4 people committed Oct 22, 2019
5 parents c3f7cef + bcf292f + cc7b2c2 + a2e7232 + 358c9d5 commit df16a27
Show file tree
Hide file tree
Showing 20 changed files with 689 additions and 258 deletions.
16 changes: 10 additions & 6 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ let
haskell = iohkLib.nix-tools.haskell { inherit pkgs; };
src = iohkLib.cleanSourceHaskell ./.;

inherit (import ./nix/jormungandr.nix { inherit iohkLib pkgs; })
jormungandr jormungandr-cli;
jmPkgs = import ./nix/jormungandr.nix { inherit iohkLib pkgs; };
inherit (jmPkgs) jormungandr jormungandr-cli;

cardano-http-bridge = iohkLib.rust-packages.pkgs.callPackage
./nix/cardano-http-bridge.nix { inherit pkgs; };
Expand All @@ -26,15 +26,19 @@ let
inherit (iohkLib.nix-tools) iohk-extras iohk-module;
};

inherit (haskellPackages.cardano-wallet-core.identifier) version;
in {
inherit pkgs iohkLib src haskellPackages;
inherit pkgs iohkLib src haskellPackages version;
inherit cardano-http-bridge cardano-sl-node jormungandr jormungandr-cli;
inherit (haskellPackages.cardano-wallet-core.identifier) version;

inherit (haskellPackages.cardano-wallet-http-bridge.components.exes)
cardano-wallet-http-bridge;
inherit (haskellPackages.cardano-wallet-jormungandr.components.exes)
cardano-wallet-jormungandr;

cardano-wallet-jormungandr = import ./nix/package-jormungandr.nix {
inherit (haskellPackages.cardano-wallet-jormungandr.components.exes)
cardano-wallet-jormungandr;
inherit pkgs jmPkgs version;
};

tests = collectComponents "tests" isCardanoWallet haskellPackages;
benchmarks = collectComponents "benchmarks" isCardanoWallet haskellPackages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ import Test.Integration.Framework.TestData
( arabicWalletName
, errMsg403Fee
, errMsg403InputsDepleted
, errMsg403NoPendingAnymore
, errMsg403NotEnoughMoney
, errMsg403UTxO
, errMsg403WrongPass
, errMsg404CannotFindTx
, errMsg404NoWallet
, falseWalletIds
, kanjiWalletName
Expand Down Expand Up @@ -970,6 +972,84 @@ spec = do
[ expectCliFieldEqual balanceAvailable amt
, expectCliFieldEqual balanceTotal amt
]

(Exit c2, Stdout out2, Stderr err2) <-
listTransactionsViaCLI @t ctx [T.unpack $ wSrc ^. walletId]
err2 `shouldBe` "Ok.\n"
c2 `shouldBe` ExitSuccess

txsJson <- expectValidJSON (Proxy @([ApiTransaction t])) out2
let txJson2 = filter (\json -> json ^. #id == txId') txsJson
verify txJson2
[ expectCliListItemFieldEqual 0 direction Outgoing
, expectCliListItemFieldEqual 0 status InLedger
]

it "TRANS_DELETE_02 - Checking not pending anymore error via CLI" $ \ctx -> do
wSrc <- fixtureWallet ctx
wDest <- emptyWallet ctx
addr:_ <- listAddresses ctx wDest
let addrStr =
encodeAddress (Proxy @t) (getApiT $ fst $ addr ^. #id)
let amt = 1
let args = T.unpack <$>
[ wSrc ^. walletId
, "--payment", T.pack (show amt) <> "@" <> addrStr
]

-- post transaction
(c, out, err) <- postTransactionViaCLI @t ctx "cardano-wallet" args
err `shouldBe` "Please enter your passphrase: **************\nOk.\n"
txJson <- expectValidJSON (Proxy @(ApiTransaction t)) out
verify txJson
[ expectCliFieldEqual direction Outgoing
, expectCliFieldEqual status Pending
]
c `shouldBe` ExitSuccess

let txId' = txJson ^. #id
let txId = toUrlPiece (ApiTxId txId')

-- forget transaction
let wid = T.unpack $ wSrc ^. walletId
Exit c1 <- deleteTransactionViaCLI @t ctx wid (T.unpack txId)
c1 `shouldBe` ExitSuccess

expectEventually' ctx getWalletEp balanceTotal amt wDest

-- forget transaction once again
(Exit c2, Stdout out2, Stderr err2) <-
deleteTransactionViaCLI @t ctx wid (T.unpack txId)
err2 `shouldContain` errMsg403NoPendingAnymore txId
out2 `shouldBe` ""
c2 `shouldBe` ExitFailure 1

it "TRANS_DELETE_03 - Checking no transaction id error via CLI" $ \ctx -> do
wSrc <- fixtureWallet ctx
let wid = T.unpack $ wSrc ^. walletId
let txId = "3e6ec12da4414aa0781ff8afa9717ae53ee8cb4aa55d622f65bc62619a4f7b12"
-- forget transaction once again
(Exit c, Stdout out, Stderr err) <-
deleteTransactionViaCLI @t ctx wid (T.unpack txId)
err `shouldContain` errMsg404CannotFindTx txId
out `shouldBe` ""
c `shouldBe` ExitFailure 1

describe "TRANS_DELETE_04 - False wallet ids via CLI" $ do
forM_ falseWalletIds $ \(title, walId) -> it title $ \ctx -> do
let txId = "3e6ec12da4414aa0781ff8afa9717ae53ee8cb4aa55d622f65bc62619a4f7b12"
-- forget transaction once again
(Exit c, Stdout out, Stderr err) <-
deleteTransactionViaCLI @t ctx walId (T.unpack txId)
out `shouldBe` ""
c `shouldBe` ExitFailure 1
if (title == "40 chars hex") then
err `shouldContain` "I couldn't find a wallet with \
\the given id: 1111111111111111111111111111111111111111"
else
err `shouldContain` "wallet id should be an \
\hex-encoded string of 40 characters"

where
unsafeGetTransactionTime
:: [ApiTransaction t]
Expand Down
62 changes: 49 additions & 13 deletions lib/jormungandr/exe/cardano-wallet-jormungandr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ import Cardano.Wallet.Version
( showVersion, version )
import Control.Applicative
( optional, (<|>) )
import Data.List
( isPrefixOf )
import Data.Maybe
( fromMaybe )
import Data.Text
Expand All @@ -87,22 +89,24 @@ import Options.Applicative
, Parser
, argument
, command
, footer
, footerDoc
, help
, helper
, info
, long
, many
, metavar
, progDesc
, some
, str
)
import Options.Applicative.Types
( readerAsk, readerError )
import System.Exit
( exitWith )
import System.FilePath
( (</>) )

import qualified Data.Text as T
import qualified Options.Applicative.Help.Pretty as D

{-------------------------------------------------------------------------------
Main entry point
Expand Down Expand Up @@ -163,17 +167,34 @@ data LaunchArgs = LaunchArgs

data JormungandrArgs = JormungandrArgs
{ genesisBlock :: Either (Hash "Genesis") FilePath
, extraJormungandrArgs :: [Text]
, extraJormungandrArgs :: [String]
}

cmdLaunch
:: FilePath
-> Mod CommandFields (IO ())
cmdLaunch dataDir = command "launch" $ info (helper <*> cmd) $ mempty
<> progDesc "Launch and monitor a wallet server and its chain producers."
<> footer
"Please note that launch will generate a configuration for Jörmungandr \
\in a folder specified by '--state-dir'."
<> footerDoc (Just $ D.empty
<> D.text "Examples:"
<> D.line
<> D.text "1) Minimal setup, relying on sensible defaults:" <> D.line
<> D.text " launch --genesis-block block0.bin" <> D.line
<> D.line
<> D.text "2) Launching a full node: " <> D.line
<> D.text " launch --genesis-block block0.bin -- --secret secret.yaml" <> D.line
<> D.line
<> D.text "3) Bootstrapping from trusted peers*:" <> D.line
<> D.text " launch --genesis-block-hash 4c05c5bb -- --config config.yaml" <> D.line
<> D.line
<> D.text "(*) assuming 'trusted_peers' is defined in 'config.yaml'"
<> D.line
<> D.line
<> D.text "Please also note that 'launch' will define a 'rest' and" <> D.line
<> D.text "'storage' configuration for Jörmungandr so in case you" <> D.line
<> D.text "provide a configuration file as extra arguments, make sure" <> D.line
<> D.text "not to define any these configuration settings."
)
where
cmd = fmap exec $ LaunchArgs
<$> hostPreferenceOption
Expand All @@ -186,8 +207,7 @@ cmdLaunch dataDir = command "launch" $ info (helper <*> cmd) $ mempty
<$> genesisBlockOption
<*> extraArguments)
exec (LaunchArgs hostPreference listen nodePort mStateDir logCfg verbosity jArgs) = do
let minSeverity = verbosityToMinSeverity verbosity
withLogging logCfg minSeverity $ \(cfg, tr) -> do
withLogging logCfg (verbosityToMinSeverity verbosity) $ \(cfg, tr) -> do
case genesisBlock jArgs of
Right block0File -> requireFilePath block0File
Left _ -> pure ()
Expand All @@ -197,7 +217,6 @@ cmdLaunch dataDir = command "launch" $ info (helper <*> cmd) $ mempty
{ _stateDir = stateDir
, _genesisBlock = genesisBlock jArgs
, _restApiPort = fromIntegral . getPort <$> nodePort
, _minSeverity = minSeverity
, _outputStream = Inherit
, _extraArgs = extraJormungandrArgs jArgs
}
Expand Down Expand Up @@ -286,7 +305,24 @@ genesisHashOption = optionT $ mempty
<> help "Blake2b_256 hash of the genesis block, in base 16."

-- | -- [ARGUMENTS...]
extraArguments :: Parser [Text]
extraArguments = some $ argument str $ mempty
extraArguments :: Parser [String]
extraArguments = many $ argument jmArg $ mempty
<> metavar "[-- ARGUMENTS...]"
<> help "Extra arguments to be passed to jormungandr."
<> help "Extra arguments to be passed to Jörmungandr."
where
jmArg = do
arg <- readerAsk
case validate arg of
Just err -> readerError err
Nothing -> pure arg
validate arg
| "--genesis-block" `isPrefixOf` arg = Just $
"The " <> arg <> " option must be placed before the --"
| "--rest-listen" `isPrefixOf` arg = Just $
suggestion "--rest-listen"
| "--storage" `isPrefixOf` arg = Just $
suggestion "--storage"
| otherwise = Nothing
suggestion arg = "The " <> arg <> " argument is used by the launch command."
<> "\nIf you need this level of flexibility, run \"jormungandr\" "
<> "separately and use \"cardano-wallet-jormungandr serve\"."
19 changes: 11 additions & 8 deletions lib/jormungandr/src/Cardano/Wallet/Jormungandr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import Cardano.Wallet.Jormungandr.Transaction
import Cardano.Wallet.Network
( NetworkLayer (..), defaultRetryPolicy, waitForNetwork )
import Cardano.Wallet.Primitive.AddressDerivation
( KeyToAddress, PersistKey )
( PersistKey )
import Cardano.Wallet.Primitive.AddressDerivation.Random
( RndKey )
import Cardano.Wallet.Primitive.AddressDerivation.Sequential
Expand All @@ -77,6 +77,8 @@ import Cardano.Wallet.Primitive.Model
( BlockchainParameters (..) )
import Cardano.Wallet.Primitive.Types
( Block, Hash (..) )
import Cardano.Wallet.Transaction
( TransactionLayer )
import Control.Concurrent.Async
( race_ )
import Control.DeepSeq
Expand Down Expand Up @@ -132,8 +134,10 @@ serveWallet (cfg, tr) databaseDir hostPref listen lj beforeMainLoop = do
waitForService "Jörmungandr" tr nPort $
waitForNetwork nl defaultRetryPolicy
let (_, bp) = staticBlockchainParameters nl
rndApi <- apiLayer tr (toWLBlock <$> nl)
seqApi <- apiLayer tr (toWLBlock <$> nl)
let rndTl = newTransactionLayer @n (getGenesisBlockHash bp)
let seqTl = newTransactionLayer @n (getGenesisBlockHash bp)
rndApi <- apiLayer tr rndTl (toWLBlock <$> nl)
seqApi <- apiLayer tr seqTl (toWLBlock <$> nl)
startServer tr nPort bp rndApi seqApi
Left e -> handleNetworkStartupError e
where
Expand Down Expand Up @@ -162,20 +166,19 @@ serveWallet (cfg, tr) databaseDir hostPref listen lj beforeMainLoop = do
toWLBlock = J.convertBlock

apiLayer
:: forall s k .
( KeyToAddress (Jormungandr 'Testnet) k
, IsOurs s
:: forall s k.
( IsOurs s
, NFData s
, Show s
, PersistState s
, PersistKey k
)
=> Trace IO Text
-> TransactionLayer t k
-> NetworkLayer IO t (Block Tx)
-> IO (ApiLayer s t k)
apiLayer tracer nl = do
apiLayer tracer tl nl = do
let (block0, bp) = staticBlockchainParameters nl
let tl = newTransactionLayer @n (getGenesisBlockHash bp)
wallets <- maybe (pure []) (Sqlite.findDatabases @k tr) databaseDir
Server.newApiLayer tracer (block0, bp) nl tl dbFactory wallets

Expand Down
Loading

0 comments on commit df16a27

Please sign in to comment.