Skip to content

Commit 408488e

Browse files
committed
[RSC-151] Rename flag and add to other entities
1 parent 39578f8 commit 408488e

File tree

11 files changed

+128
-84
lines changed

11 files changed

+128
-84
lines changed

src/Bank/BankOptions.hs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ data Command
2929
| RemoveExplorer String Int
3030

3131
data Options = Options
32-
{ cloCommand :: Command
33-
, cloPath :: FilePath
34-
, cloPeriodDelta :: Integer
35-
, cloLogSeverity :: Severity
36-
, cloSkPath :: FilePath
37-
, cloAutoCreateKey :: Bool
38-
, cloConfigPath :: FilePath
32+
{ cloCommand :: Command
33+
, cloPath :: FilePath
34+
, cloPeriodDelta :: Integer
35+
, cloLogSeverity :: Severity
36+
, cloSkPath :: FilePath
37+
, cloAutoCreateKey :: Bool
38+
, cloConfigPath :: FilePath
39+
, cloDefaultContext :: Bool -- ^ Use defaultNodeContext
3940
}
4041

4142
commandParser :: Parser Command
@@ -123,7 +124,14 @@ optionsParser defaultSKPath configDir defaultConfigPath =
123124
(long "config-path" <> help "Path to configuration file" <>
124125
value defaultConfigPath <>
125126
showDefault <>
126-
metavar "FILEPATH")
127+
metavar "FILEPATH") <*>
128+
switch
129+
(mconcat
130+
[ short 'd'
131+
, long "default-context"
132+
, help
133+
("Use default NodeContext. " <>
134+
"Intended to be used for local deployment")])
127135

128136
getOptions :: IO Options
129137
getOptions = do

src/Bank/Main.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ main = do
3434
return sk
3535
Left err -> throwM err
3636
Right sk -> return sk
37-
let ca = B.CACustomLocation cloConfigPath
37+
let ca =
38+
if cloDefaultContext
39+
then B.CADefault
40+
else B.CACustomLocation cloConfigPath
3841
case cloCommand of
3942
Opts.AddMintette host port pk -> do
4043
let m = Mintette host port

src/Deploy/Main.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ setupBankUser CommonParams{..} = do
171171
Cherepakha.echo
172172
"Use command below to do smth as bank user"
173173
Cherepakha.echo $
174-
sformat ("stack $NIX_STACK exec -- rscoin-user --local " % stext) walletPathArg
174+
sformat
175+
("stack $NIX_STACK exec -- rscoin-user --default-context " % stext)
176+
walletPathArg
175177

176178
mintettePort :: Integral a => a -> Int
177179
mintettePort = (C.defaultPort + 1 +) . fromIntegral

src/Explorer/ExplorerOptions.hs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module ExplorerOptions
77

88
import Options.Applicative (Parser, auto, execParser, fullDesc,
99
help, helper, info, long, metavar,
10-
option, progDesc, showDefault, switch,
11-
value, (<>))
10+
option, progDesc, short, showDefault,
11+
switch, value, (<>))
1212
import System.FilePath ((</>))
1313

1414
import Serokell.Util.OptParse (strOption)
@@ -18,13 +18,14 @@ import RSCoin.Core (Severity (Error), configDirectory,
1818
defaultSecretKeyPath)
1919

2020
data Options = Options
21-
{ cloPortRpc :: Int
22-
, cloPortWeb :: Int
23-
, cloPath :: FilePath
24-
, cloSecretKeyPath :: FilePath
25-
, cloAutoCreateKey :: Bool
26-
, cloLogSeverity :: Severity
27-
, cloConfigPath :: FilePath
21+
{ cloPortRpc :: Int
22+
, cloPortWeb :: Int
23+
, cloPath :: FilePath
24+
, cloSecretKeyPath :: FilePath
25+
, cloAutoCreateKey :: Bool
26+
, cloLogSeverity :: Severity
27+
, cloConfigPath :: FilePath
28+
, cloDefaultContext :: Bool
2829
}
2930

3031
optionsParser :: FilePath -> FilePath -> FilePath -> Parser Options
@@ -77,7 +78,14 @@ optionsParser defaultSKPath configDir defaultConfigPath =
7778
[ long "config-path"
7879
, help "Path to configuration file"
7980
, value defaultConfigPath
80-
, showDefault])
81+
, showDefault]) <*>
82+
switch
83+
(mconcat
84+
[ short 'd'
85+
, long "default-context"
86+
, help
87+
("Use default NodeContext. " <>
88+
"Intended to be used for local deployment")])
8189

8290

8391
getOptions :: IO Options

src/Explorer/Main.hs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,24 @@ main = do
1616
Options{..} <- getOptions
1717
C.initLogging cloLogSeverity
1818
skEither <- try $ readSecretKey cloSecretKeyPath
19-
sk <- case skEither of
20-
Left (_::SomeException) | cloAutoCreateKey -> do
21-
putStrLn $ "Generating and putting secret keys into: " ++
22-
cloSecretKeyPath
23-
let fpSecret = cloSecretKeyPath
24-
let fpPublic = cloSecretKeyPath <> ".pub"
25-
(sk,pk) <- keyGen
26-
writePublicKey fpPublic pk
27-
writeSecretKey fpSecret sk
28-
putStrLn "Wrote a keypar on the disk"
29-
return sk
30-
Left err -> throwM err
31-
Right sk -> return sk
32-
E.launchExplorerReal
33-
cloPortRpc
34-
cloPortWeb
35-
cloLogSeverity
36-
cloPath
37-
(E.CACustomLocation cloConfigPath)
38-
sk
19+
sk <-
20+
case skEither of
21+
Left (_ :: SomeException)
22+
| cloAutoCreateKey -> do
23+
putStrLn $
24+
"Generating and putting secret keys into: " ++
25+
cloSecretKeyPath
26+
let fpSecret = cloSecretKeyPath
27+
let fpPublic = cloSecretKeyPath <> ".pub"
28+
(sk,pk) <- keyGen
29+
writePublicKey fpPublic pk
30+
writeSecretKey fpSecret sk
31+
putStrLn "Wrote a keypar on the disk"
32+
return sk
33+
Left err -> throwM err
34+
Right sk -> return sk
35+
let ctxArg =
36+
if cloDefaultContext
37+
then E.CADefault
38+
else E.CACustomLocation cloConfigPath
39+
E.launchExplorerReal cloPortRpc cloPortWeb cloLogSeverity cloPath ctxArg sk

src/Mintette/Main.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ main = do
3636
if cloMemMode
3737
then Nothing
3838
else Just cloPath
39-
ctxArg = M.CACustomLocation cloConfigPath
39+
ctxArg =
40+
if cloDefaultContext
41+
then M.CADefault
42+
else M.CACustomLocation cloConfigPath
4043
epochDelta = fromInteger cloEpochDelta :: Second
4144
M.launchMintetteReal epochDelta cloPort sk dbPath ctxArg

src/Mintette/MintetteOptions.hs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ import RSCoin.Core (Severity (Error), configDirectory,
1919
defaultSecretKeyPath)
2020

2121
data Options = Options
22-
{ cloPort :: Int
23-
, cloPath :: FilePath
24-
, cloEpochDelta :: Integer
25-
, cloSecretKeyPath :: FilePath
26-
, cloAutoCreateKey :: Bool
27-
, cloLogSeverity :: Severity
28-
, cloMemMode :: Bool
29-
, cloConfigPath :: FilePath
22+
{ cloPort :: Int
23+
, cloPath :: FilePath
24+
, cloEpochDelta :: Integer
25+
, cloSecretKeyPath :: FilePath
26+
, cloAutoCreateKey :: Bool
27+
, cloLogSeverity :: Severity
28+
, cloMemMode :: Bool
29+
, cloConfigPath :: FilePath
30+
, cloDefaultContext :: Bool
3031
}
3132

3233
optionsParser :: FilePath -> FilePath -> FilePath -> Parser Options
@@ -63,7 +64,14 @@ optionsParser defaultSKPath configDir defaultConfigPath =
6364
(long "config-path" <> help "Path to configuration file" <>
6465
value defaultConfigPath <>
6566
showDefault <>
66-
metavar "FILEPATH")
67+
metavar "FILEPATH") <*>
68+
switch
69+
(mconcat
70+
[ short 'd'
71+
, long "default-context"
72+
, help
73+
("Use default NodeContext. " <>
74+
"Intended to be used for local deployment")])
6775

6876
getOptions :: IO Options
6977
getOptions = do

src/Notary/Main.hs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ main :: IO ()
1212
main = do
1313
Opts.Options{..} <- Opts.getOptions
1414
initLogging cliLogSeverity
15-
let dbPath = if cliMemMode
16-
then Nothing
17-
else Just cliPath
15+
let dbPath =
16+
if cliMemMode
17+
then Nothing
18+
else Just cliPath
1819
let trustedKeys = mapMaybe constructPublicKey cliTrustedKeys
20+
let ctxArg =
21+
if cloDefaultContext
22+
then N.CADefault
23+
else N.CACustomLocation cliConfigPath
1924
when (length trustedKeys < length cliTrustedKeys) $
2025
logWarning "Not all keys were parsed!"
21-
22-
N.launchNotaryReal
23-
cliLogSeverity
24-
dbPath
25-
(N.CACustomLocation cliConfigPath)
26-
cliWebPort
27-
trustedKeys
26+
N.launchNotaryReal cliLogSeverity dbPath ctxArg cliWebPort trustedKeys

src/Notary/NotaryOptions.hs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ module NotaryOptions
66
) where
77

88
import Data.Text (Text)
9-
import Options.Applicative (Parser, auto, execParser, fullDesc, many,
10-
help, helper, info, long, metavar,
11-
option, progDesc, short, showDefault,
12-
switch, value, (<>))
9+
import Options.Applicative (Parser, auto, execParser, fullDesc,
10+
help, helper, info, long, many,
11+
metavar, option, progDesc, short,
12+
showDefault, switch, value, (<>))
1313
import System.FilePath ((</>))
1414

1515
import Serokell.Util.OptParse (strOption)
@@ -18,12 +18,13 @@ import RSCoin.Core (Severity (Error), configDirectory,
1818
defaultConfigurationPath)
1919

2020
data Options = Options
21-
{ cliPath :: FilePath
22-
, cliLogSeverity :: Severity
23-
, cliMemMode :: Bool
24-
, cliWebPort :: Int
25-
, cliConfigPath :: FilePath
26-
, cliTrustedKeys :: [Text]
21+
{ cliPath :: FilePath
22+
, cliLogSeverity :: Severity
23+
, cliMemMode :: Bool
24+
, cliWebPort :: Int
25+
, cliConfigPath :: FilePath
26+
, cliTrustedKeys :: [Text]
27+
, cloDefaultContext :: Bool
2728
} deriving Show
2829

2930
optionsParser :: FilePath -> FilePath -> Parser Options
@@ -48,9 +49,19 @@ optionsParser configDir defaultConfigPath =
4849
value defaultConfigPath <>
4950
showDefault <>
5051
metavar "FILEPATH") <*>
51-
many (strOption $ long "trust-keys" <> metavar "[PUBLIC KEY]" <>
52-
help "Public keys notary will trust as master keys. If not specifed \
53-
\then notary will trust any key")
52+
many
53+
(strOption $
54+
long "trust-keys" <> metavar "[PUBLIC KEY]" <>
55+
help
56+
"Public keys notary will trust as master keys. If not specifed \
57+
\then notary will trust any key") <*>
58+
switch
59+
(mconcat
60+
[ short 'd'
61+
, long "default-context"
62+
, help
63+
("Use default NodeContext. " <>
64+
"Intended to be used for local deployment")])
5465

5566
getOptions :: IO Options
5667
getOptions = do

src/User/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ main = do
1919
opts@O.UserOptions{..} <- O.getUserOptions
2020
C.initLogging logSeverity
2121
let ctxArg =
22-
if localDeploy
22+
if defaultContext
2323
then CADefault
2424
else CACustomLocation configPath
2525
runRealModeUntrusted C.userLoggerName ctxArg $

src/User/UserOptions.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ data DumpCommand
9898

9999
-- | Datatype describing user command line options
100100
data UserOptions = UserOptions
101-
{ userCommand :: UserCommand -- ^ Command for the program to process
102-
, isBankMode :: Bool -- ^ If creating wallet in bank-mode,
103-
, bankModePath :: FilePath -- ^ Path to bank's secret key
104-
, addressesNum :: Int -- ^ Number of addresses to create initially
101+
{ userCommand :: UserCommand -- ^ Command for the program to process
102+
, isBankMode :: Bool -- ^ If creating wallet in bank-mode,
103+
, bankModePath :: FilePath -- ^ Path to bank's secret key
104+
, addressesNum :: Int -- ^ Number of addresses to create initially
105105
#if GtkGui
106-
, guidbPath :: FilePath -- ^ Path to the gui database.
106+
, guidbPath :: FilePath -- ^ Path to the gui database.
107107
#endif
108-
, walletPath :: FilePath -- ^ Path to the wallet
109-
, logSeverity :: Severity -- ^ Logging severity
110-
, configPath :: FilePath -- ^ Configuration file path
111-
, localDeploy :: Bool -- ^ Use defaultNodeContext
108+
, walletPath :: FilePath -- ^ Path to the wallet
109+
, logSeverity :: Severity -- ^ Logging severity
110+
, configPath :: FilePath -- ^ Configuration file path
111+
, defaultContext :: Bool -- ^ Use defaultNodeContext
112112
} deriving (Show)
113113

114114
userCommandParser :: Parser UserCommand
@@ -410,7 +410,8 @@ userOptionsParser dskp configDir defaultConfigPath =
410410
value defaultConfigPath <>
411411
showDefault <>
412412
metavar "FILEPATH") <*>
413-
switch (mconcat [long "local",
413+
switch (mconcat [short 'd',
414+
long "default-context",
414415
help ("Use default NodeContext. "
415416
<> "Intended to be used for local deployment")
416417
])

0 commit comments

Comments
 (0)