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

cli: Add cardano-wallet --database option #374

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions exe/launcher/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Main where
import Prelude

import Cardano.CLI
( Port, help, parseArgWith, showVersion )
( Port, getVersion, help, parseArgWith )
import Cardano.Launcher
( Command (Command)
, ProcessHasExited (ProcessHasExited)
Expand Down Expand Up @@ -72,7 +72,7 @@ main = do
args <- parseArgsOrExit cli =<< getArgs
when (args `isPresent` (longOption "help")) $ help cli
when (args `isPresent` (shortOption 'h')) $ help cli
when (args `isPresent` (longOption "version")) showVersion
when (args `isPresent` (longOption "version")) $ putStrLn getVersion

network <- args `parseArg` longOption "network"
bridgePort <- args `parseArg` longOption "http-bridge-port"
Expand Down
13 changes: 8 additions & 5 deletions exe/wallet/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import Prelude hiding
import Cardano.CLI
( getLine
, getSensitiveLine
, getVersion
, help
, parseAllArgsWith
, parseArgWith
, putErrLn
, setUtf8Encoding
, showVersion
)
import Cardano.Wallet
( newWalletLayer )
Expand Down Expand Up @@ -94,6 +94,7 @@ import System.Console.Docopt
, command
, docopt
, exitWithUsage
, getArg
, isPresent
, longOption
, parseArgsOrExit
Expand All @@ -107,7 +108,7 @@ import System.IO
( BufferMode (NoBuffering), hSetBuffering, stderr, stdout )

import qualified Cardano.Wallet.Api.Server as Server
import qualified Cardano.Wallet.DB.MVar as MVar
import qualified Cardano.Wallet.DB.Sqlite as Sqlite
import qualified Cardano.Wallet.HttpBridge.Network as HttpBridge
import qualified Cardano.Wallet.HttpBridge.Transaction as HttpBridge
import qualified Data.Aeson as Aeson
Expand All @@ -132,7 +133,7 @@ and can be run "offline". (e.g. 'generate mnemonic')
⚠️ Options are positional (--a --b is not equivalent to --b --a) ! ⚠️

Usage:
cardano-wallet server [--network=STRING] [--port=INT] [--bridge-port=INT]
cardano-wallet server [--network=STRING] [--port=INT] [--bridge-port=INT] [--database=FILE]
cardano-wallet mnemonic generate [--size=INT]
cardano-wallet wallet list [--port=INT]
cardano-wallet wallet create [--port=INT] <name> [--address-pool-gap=INT]
Expand All @@ -151,6 +152,7 @@ Options:
--size <INT> number of mnemonic words to generate [default: 15]
--payment <PAYMENT> address to send to and amount to send separated by @: '<amount>@<address>'
--network <STRING> testnet, staging, or mainnet [default: testnet]
--database <FILE> use this file for storing wallet state

Examples:
# Create a transaction and send 22 lovelace from wallet-id to specified addres
Expand Down Expand Up @@ -260,7 +262,7 @@ exec execServer manager args
wId <- args `parseArg` argument "wallet-id"
runClient Aeson.encodePretty $ listAddresses (ApiT wId) Nothing

| args `isPresent` longOption "version" = showVersion
| args `isPresent` longOption "version" = putStrLn getVersion

| otherwise =
exitWithUsage cli
Expand Down Expand Up @@ -334,7 +336,8 @@ execHttpBridge args _ = do
<- args `parseArg` longOption "port"
(bridgePort :: Int)
<- args `parseArg` longOption "bridge-port"
db <- MVar.newDBLayer
let dbFile = args `getArg` longOption "database"
db <- Sqlite.newDBLayer dbFile
nw <- HttpBridge.newNetworkLayer @n bridgePort
waitForConnection nw defaultRetryPolicy
let tl = HttpBridge.newTransactionLayer @n
Expand Down
2 changes: 2 additions & 0 deletions lib/cli/cardano-wallet-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ library
src
exposed-modules:
Cardano.CLI
other-modules:
Paths_cardano_wallet_cli

test-suite unit
default-language:
Expand Down
29 changes: 7 additions & 22 deletions lib/cli/src/Cardano/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}

-- |
-- Copyright: © 2018-2019 IOHK
Expand Down Expand Up @@ -36,31 +35,31 @@ module Cardano.CLI
, hGetSensitiveLine

-- * Show version
, showVersion
, getVersion
) where

import Prelude hiding
( getLine )

import Control.Applicative
( many )
import Control.Exception
( bracket )
import Data.FileEmbed
( embedFile )
import Data.Functor
( (<$) )
import qualified Data.List.NonEmpty as NE
import Data.Text
( Text )
import Data.Text.Class
( FromText (..), TextDecodingError (..), ToText (..) )
import Data.Version
( showVersion )
import Fmt
( Buildable, pretty )
import GHC.Generics
( Generic )
import GHC.TypeLits
( Symbol )
import Paths_cardano_wallet_cli
( version )
import System.Console.ANSI
( Color (..)
, ColorIntensity (..)
Expand Down Expand Up @@ -96,10 +95,7 @@ import System.IO
, stdout
, utf8
)
import Text.Regex.Applicative
( anySym, few, match, string, sym )

import qualified Data.ByteString.Char8 as B8
import qualified Data.Text as T
import qualified Data.Text.IO as TIO

Expand Down Expand Up @@ -270,19 +266,8 @@ getSensitiveLine = hGetSensitiveLine (stdin, stderr)
Internals
-------------------------------------------------------------------------------}

showVersion :: IO ()
showVersion = do
let cabal = B8.unpack $(embedFile "../../cardano-wallet.cabal")
let re = few anySym
*> string "version:" *> many (sym ' ') *> few anySym
<* sym '\n' <* many anySym
case match re cabal of
Nothing -> do
putErrLn "Couldn't find program version!"
exitFailure
Just version -> do
TIO.putStrLn $ T.pack version
exitSuccess
getVersion :: String
getVersion = showVersion version

withBuffering :: Handle -> BufferMode -> IO a -> IO a
withBuffering h buffering action = bracket aFirst aLast aBetween
Expand Down