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 17, 2023
1 parent 1fe198c commit b2c2884
Show file tree
Hide file tree
Showing 4 changed files with 31 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 @@ -912,7 +912,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 @@ -1791,16 +1794,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 @@ -3329,17 +3322,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
8 changes: 8 additions & 0 deletions cardano-cli/src/Cardano/CLI/Types.hs
Expand Up @@ -20,6 +20,7 @@ module Cardano.CLI.Types
, OutputFormat (..)
, TxBuildOutputOptions(..)
, ReferenceScriptAnyEra (..)
, QueryFilter (..)
, SigningKeyFile (..)
, ScriptFile (..)
, ScriptDataOrFile (..)
Expand All @@ -43,6 +44,7 @@ module Cardano.CLI.Types

import Data.Aeson (FromJSON (..), ToJSON (..), object, pairs, (.=))
import qualified Data.Aeson as Aeson
import Data.Set (Set)
import Data.String (IsString)
import qualified Data.Text as Text
import Data.Word (Word64)
Expand Down Expand Up @@ -220,6 +222,12 @@ instance Crypto.Crypto crypto => ToJSON (Params crypto) where
, "retiring" .= r
]

-- | UTxO query filtering options.
data QueryFilter
= FilterByAddress !(Set AddressAny)
| NoFilter
deriving (Eq, Show)

newtype SigningKeyFile = SigningKeyFile
{ unSigningKeyFile :: FilePath }
deriving stock (Eq, Ord)
Expand Down

0 comments on commit b2c2884

Please sign in to comment.