Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 13f5729

Browse files
committed
make acid-state database optional from the command-line
1 parent 6054e7e commit 13f5729

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

wallet/export-wallets/Main.hs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,42 @@ import qualified Data.Text.IO as TIO
4343

4444
data Options = Options
4545
{ pm :: ProtocolMagic
46-
, dbPath :: FilePath
46+
, dbPath :: Maybe FilePath
4747
, usPath :: FilePath
4848
}
4949

5050
main :: IO ()
5151
main = do
5252
let preferences = prefs showHelpOnEmpty
5353
Options{pm,dbPath,usPath} <- customExecParser preferences parserInfo
54-
let dbOpts = DatabaseOptions
55-
{ dbPathAcidState = dbPath <> "-acid"
56-
, dbPathMetadata = dbPath <> "-sqlite.sqlite3"
57-
, dbRebuild = False
58-
}
59-
guardDatabase dbOpts
54+
dbMode <- getDbMode dbPath
6055
userSecret <- readUserSecret (contramap snd stderrTrace) usPath
6156
bracketLegacyKeystore userSecret $ \ks -> do
6257
fInjects <- mkFInjects Nothing
63-
bracketPassiveWallet pm (UseFilePath dbOpts) log ks mockNodeStateDef fInjects $ \pw -> do
58+
bracketPassiveWallet pm dbMode log ks mockNodeStateDef fInjects $ \pw -> do
6459
wallets <- extractWallet pw
6560
BL8.putStrLn $ Json.encodePretty (Export <$> wallets)
6661
where
6762
log = const (B8.hPutStrLn stderr . T.encodeUtf8)
63+
6864
stderrTrace = Trace $ Op $ TIO.hPutStrLn stderr
65+
6966
guardDatabase = doesDirectoryExist . dbPathAcidState >=> \case
7067
True -> pure ()
7168
False -> fail "There's no acid-state database matching the given path."
7269

70+
getDbMode = \case
71+
Nothing ->
72+
pure UseInMemory
73+
Just dbPath -> do
74+
let dbOpts = DatabaseOptions
75+
{ dbPathAcidState = dbPath <> "-acid"
76+
, dbPathMetadata = dbPath <> "-sqlite.sqlite3"
77+
, dbRebuild = False
78+
}
79+
guardDatabase dbOpts
80+
pure (UseFilePath dbOpts)
81+
7382
extractWallet
7483
:: Kernel.PassiveWallet
7584
-> IO [(Maybe WalletName, EncryptedSecretKey)]
@@ -122,8 +131,8 @@ pmOption = mainnetFlag <|> (ProtocolMagic <$> magicOption <*> pure RequiresMagic
122131
<> metavar "MAGIC"
123132

124133
-- --db-path FILEPATH
125-
dbOption :: Parser FilePath
126-
dbOption = option str $ mempty
134+
dbOption :: Parser (Maybe FilePath)
135+
dbOption = optional $ option str $ mempty
127136
<> long "wallet-db-path"
128137
<> metavar "FILEPATH"
129138
<> help "Path to the wallet's database."

0 commit comments

Comments
 (0)