Skip to content

Commit

Permalink
Remove OutputFormat option from PoolGetId command
Browse files Browse the repository at this point in the history
  • Loading branch information
intricate authored and newhoggy committed Mar 21, 2023
1 parent 9190a97 commit 53b5a97
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 41 deletions.
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Expand Up @@ -332,9 +332,9 @@ data PoolCmd
EpochNo
-- ^ Epoch in which to retire the stake pool.
OutputFile
| PoolGetId (VerificationKeyOrFile StakePoolKey) OutputFormat
| PoolGetId (VerificationKeyOrFile StakePoolKey) (Maybe OutputFile)
| PoolMetadataHash PoolMetadataFile (Maybe OutputFile)
deriving Show
deriving (Eq, Show)

renderPoolCmd :: PoolCmd -> Text
renderPoolCmd cmd =
Expand Down Expand Up @@ -517,11 +517,11 @@ data MetadataFile = MetadataFileJSON FilePath
newtype OutputFile = OutputFile
{ unOutputFile :: FilePath
}
deriving Show
deriving (Eq, Show)

newtype PoolMetadataFile = PoolMetadataFile
{ unPoolMetadataFile :: FilePath }
deriving Show
deriving (Eq, Show)

newtype GenesisDir
= GenesisDir FilePath
Expand Down
26 changes: 4 additions & 22 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Expand Up @@ -913,7 +913,10 @@ pPoolCmd =
]
where
pId :: Parser PoolCmd
pId = PoolGetId <$> pStakePoolVerificationKeyOrFile <*> pOutputFormat
pId =
PoolGetId
<$> pStakePoolVerificationKeyOrFile
<*> pMaybeOutputFile

pPoolMetadataHashSubCmd :: Parser PoolCmd
pPoolMetadataHashSubCmd = PoolMetadataHash <$> pPoolMetadataFile <*> pMaybeOutputFile
Expand Down Expand Up @@ -1792,16 +1795,6 @@ pOperationalCertificateFile =
<> Opt.completer (Opt.bashCompleter "file")
)

pOutputFormat :: Parser OutputFormat
pOutputFormat =
Opt.option readOutputFormat
( Opt.long "output-format"
<> Opt.metavar "STRING"
<> Opt.help "Optional output format. Accepted output formats are \"hex\" \
\and \"bech32\" (default is \"bech32\")."
<> Opt.value OutputFormatBech32
)

pMaybeOutputFile :: Parser (Maybe OutputFile)
pMaybeOutputFile =
optional $
Expand Down Expand Up @@ -3330,17 +3323,6 @@ readVerificationKey asType =
first (Text.unpack . renderInputDecodeError) $
deserialiseInput (AsVerificationKey asType) keyFormats (BSC.pack str)

readOutputFormat :: Opt.ReadM OutputFormat
readOutputFormat = do
s <- Opt.str
case s of
"hex" -> pure OutputFormatHex
"bech32" -> pure OutputFormatBech32
_ ->
fail $ "Invalid output format: \""
<> s
<> "\". Accepted output formats are \"hex\" and \"bech32\"."

readURIOfMaxLength :: Int -> Opt.ReadM Text
readURIOfMaxLength maxLen =
Text.pack <$> readStringOfMaxLength maxLen
Expand Down
30 changes: 15 additions & 15 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Pool.hs
Expand Up @@ -8,13 +8,13 @@ import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT
newExceptT)
import qualified Data.ByteString.Char8 as BS
import qualified Data.Text as Text
import qualified Data.Text.IO as Text

import Cardano.Api
import Cardano.Api.Shelley
import Cardano.CLI.Shelley.Commands
import Cardano.CLI.Shelley.Key (VerificationKeyOrFile, readVerificationKeyOrFile)
import Cardano.CLI.Types (OutputFormat (..))
import Cardano.CLI.Shelley.Key (OutputDirection (..), VerificationKeyOrFile,
readVerificationKeyOrFile, writeOutputBech32)


import qualified Cardano.Ledger.Slot as Shelley
import Control.Monad.IO.Class (MonadIO (..))
Expand Down Expand Up @@ -44,7 +44,7 @@ runPoolCmd (PoolRegistrationCert sPvkey vrfVkey pldg pCost pMrgn rwdVerFp ownerV
runStakePoolRegistrationCert sPvkey vrfVkey pldg pCost pMrgn rwdVerFp ownerVerFps relays mbMetadata network outfp
runPoolCmd (PoolRetirementCert sPvkeyFp retireEpoch outfp) =
runStakePoolRetirementCert sPvkeyFp retireEpoch outfp
runPoolCmd (PoolGetId sPvkey outputFormat) = runPoolId sPvkey outputFormat
runPoolCmd (PoolGetId sPvkey mOutFile) = runPoolId sPvkey mOutFile
runPoolCmd (PoolMetadataHash poolMdFile mOutFile) = runPoolMetadataHash poolMdFile mOutFile


Expand Down Expand Up @@ -163,18 +163,18 @@ runStakePoolRetirementCert stakePoolVerKeyOrFile retireEpoch (OutputFile outfp)

runPoolId
:: VerificationKeyOrFile StakePoolKey
-> OutputFormat
-> Maybe OutputFile
-> ExceptT ShelleyPoolCmdError IO ()
runPoolId verKeyOrFile outputFormat = do
stakePoolVerKey <- firstExceptT ShelleyPoolCmdReadKeyFileError
. newExceptT
$ readVerificationKeyOrFile AsStakePoolKey verKeyOrFile
liftIO $
case outputFormat of
OutputFormatHex ->
BS.putStrLn $ serialiseToRawBytesHex (verificationKeyHash stakePoolVerKey)
OutputFormatBech32 ->
Text.putStrLn $ serialiseToBech32 (verificationKeyHash stakePoolVerKey)
runPoolId verKeyOrFile mOutFile = do
stakePoolVerKey <- firstExceptT ShelleyPoolCmdReadKeyFileError
. newExceptT
$ readVerificationKeyOrFile AsStakePoolKey verKeyOrFile

firstExceptT ShelleyPoolCmdWriteFileError
. newExceptT
$ writeOutputBech32
(maybe OutputDirectionStdout (\(OutputFile fp) -> OutputDirectionFile fp) mOutFile)
(verificationKeyHash stakePoolVerKey)

runPoolMetadataHash :: PoolMetadataFile -> Maybe OutputFile -> ExceptT ShelleyPoolCmdError IO ()
runPoolMetadataHash (PoolMetadataFile poolMDPath) mOutFile = do
Expand Down

0 comments on commit 53b5a97

Please sign in to comment.