Skip to content

Commit 3ff8ae9

Browse files
committed
[cli] Add wallet filepath to anti wallet info
1 parent be02969 commit 3ff8ae9

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

cli/src/Core/Types/Mnemonics/Options.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Core.Types.Mnemonics.Options
22
( mnemonicsParser
33
, walletPassphraseCommon
4+
, walletFileOption
45
) where
56

67
import Core.Encryption (decryptText)
@@ -60,7 +61,7 @@ walletFileOption =
6061
setting
6162
[ env "ANTI_WALLET_FILE"
6263
, metavar "FILEPATH"
63-
, help "The file path to the wallet secrets"
64+
, help "The file path to the wallet secrets mnemonics"
6465
, reader str
6566
]
6667

cli/src/Wallet/Cli.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,20 @@ instance (ToJSON m a, Monad m) => ToJSON m (Either WalletError a) where
3030
data WalletInfo = WalletInfo
3131
{ address :: Address
3232
, owner :: Owner
33+
, filePath :: FilePath
3334
}
3435

3536
instance Monad m => ToJSON m WalletInfo where
36-
toJSON WalletInfo{address, owner} =
37+
toJSON WalletInfo{address, owner, filePath} =
3738
object
3839
[ "address" .= address
3940
, "owner" .= owner
41+
, "filePath" .= filePath
4042
]
4143

4244
data WalletCommand a where
43-
Info :: Wallet -> WalletCommand (Either WalletError WalletInfo)
45+
Info
46+
:: Wallet -> FilePath -> WalletCommand (Either WalletError WalletInfo)
4447
Create
4548
:: FilePath
4649
-> Maybe Text
@@ -50,12 +53,13 @@ deriving instance Show (WalletCommand a)
5053
deriving instance Eq (WalletCommand a)
5154

5255
walletCmd :: WalletCommand a -> IO a
53-
walletCmd (Info wallet) =
56+
walletCmd (Info wallet filePath) =
5457
pure
5558
$ Right
5659
$ WalletInfo
5760
{ address = wallet.address
5861
, owner = wallet.owner
62+
, filePath = filePath
5963
}
6064
walletCmd (Create walletFile passphrase) = do
6165
w12 <- replicateM 12 $ element englishWords
@@ -68,6 +72,7 @@ walletCmd (Create walletFile passphrase) = do
6872
$ WalletInfo
6973
{ address = wallet.address
7074
, owner = wallet.owner
75+
, filePath = walletFile
7176
}
7277

7378
element :: [a] -> IO a

cli/src/Wallet/Options.hs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,15 @@ module Wallet.Options
55
) where
66

77
import Core.Options (walletOption)
8-
import Core.Types.Mnemonics.Options (walletPassphraseCommon)
8+
import Core.Types.Mnemonics.Options
9+
( walletFileOption
10+
, walletPassphraseCommon
11+
)
912
import Data.Text (Text)
1013
import Lib.Box (Box (..))
1114
import OptEnvConf
1215
import Wallet.Cli (WalletCommand (..))
1316

14-
walletFileOption :: Parser FilePath
15-
walletFileOption =
16-
setting
17-
[ help "File to store the wallet mnemonic"
18-
, metavar "MNEMONICS"
19-
, env "ANTI_WALLET_FILE"
20-
, reader str
21-
]
22-
2317
walletCommandParser :: Parser (Box WalletCommand)
2418
walletCommandParser =
2519
commands
@@ -32,8 +26,9 @@ walletCommandParser =
3226
, command
3327
"info"
3428
"Get the wallet information"
35-
$ Box . Info
29+
$ fmap Box . Info
3630
<$> walletOption
31+
<*> walletFileOption
3732
]
3833

3934
passphraseOption :: Parser (Maybe Text)

0 commit comments

Comments
 (0)