Skip to content

Commit

Permalink
Add output file option to Shelley address info command
Browse files Browse the repository at this point in the history
  • Loading branch information
intricate committed Jul 9, 2020
1 parent d22d825 commit 20ae9f0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Expand Up @@ -78,7 +78,7 @@ data AddressCmd
| AddressKeyHash VerificationKeyFile (Maybe OutputFile)
| AddressBuild VerificationKeyFile (Maybe VerificationKeyFile) NetworkId (Maybe OutputFile)
| AddressBuildMultiSig --TODO
| AddressInfo Text
| AddressInfo Text (Maybe OutputFile)
| AddressConvertKey SigningKeyFile SigningKeyFile
deriving (Eq, Show)

Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Expand Up @@ -159,7 +159,7 @@ pAddressCmd =
pAddressBuildMultiSig = pure AddressBuildMultiSig

pAddressInfo :: Parser AddressCmd
pAddressInfo = AddressInfo <$> pAddress
pAddressInfo = AddressInfo <$> pAddress <*> pMaybeOutputFile

pAddressConvert :: Parser AddressCmd
pAddressConvert = AddressConvertKey <$> pByronKeyFile Input
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Run/Address.hs
Expand Up @@ -49,7 +49,7 @@ runAddressCmd cmd =
AddressKeyHash vkf mOFp -> runAddressKeyHash vkf mOFp
AddressBuild payVk stkVk nw mOutFp -> runAddressBuild payVk stkVk nw mOutFp
AddressBuildMultiSig {} -> runAddressBuildMultiSig
AddressInfo txt -> firstExceptT ShelleyAddressCmdAddressInfoError $ runAddressInfo txt
AddressInfo txt mOFp -> firstExceptT ShelleyAddressCmdAddressInfoError $ runAddressInfo txt mOFp
AddressConvertKey skfOld skfNew -> runAddressConvertKey skfOld skfNew


Expand Down
11 changes: 8 additions & 3 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Address/Info.hs
Expand Up @@ -15,6 +15,8 @@ import Control.Monad.Trans.Except.Extra (left)

import Cardano.Api.Typed

import Cardano.CLI.Shelley.Parsers (OutputFile (..))


data ShelleyAddressInfoError = ShelleyAddressInvalid Text
deriving Show
Expand All @@ -39,8 +41,8 @@ instance ToJSON AddressInfo where
, "address" .= aiAddress addrInfo
]

runAddressInfo :: Text -> ExceptT ShelleyAddressInfoError IO ()
runAddressInfo addrTxt = do
runAddressInfo :: Text -> Maybe OutputFile -> ExceptT ShelleyAddressInfoError IO ()
runAddressInfo addrTxt mOutputFp = do
addrInfo <- case (Left <$> deserialiseAddress AsShelleyAddress addrTxt)
<|> (Right <$> deserialiseAddress AsStakeAddress addrTxt) of

Expand Down Expand Up @@ -71,4 +73,7 @@ runAddressInfo addrTxt = do
, aiEncoding = "bech32"
, aiAddress = addrTxt
}
liftIO $ LBS.putStrLn $ encodePretty addrInfo

case mOutputFp of
Just (OutputFile fpath) -> liftIO $ LBS.writeFile fpath $ encodePretty addrInfo
Nothing -> liftIO $ LBS.putStrLn $ encodePretty addrInfo

0 comments on commit 20ae9f0

Please sign in to comment.