Skip to content

Commit

Permalink
Remote PoolMetadataFile type. Use File instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed May 5, 2023
1 parent e805f06 commit 4c3373f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
7 changes: 1 addition & 6 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ module Cardano.CLI.Shelley.Commands
, VerificationKeyBase64 (..)
, GenesisKeyFile (..)
, MetadataFile (..)
, PoolMetadataFile (..)
, PrivKeyFile (..)
, BlockId (..)
, WitnessSigningData (..)
Expand Down Expand Up @@ -324,7 +323,7 @@ data PoolCmd
-- ^ Epoch in which to retire the stake pool.
(File () Out)
| PoolGetId (VerificationKeyOrFile StakePoolKey) OutputFormat
| PoolMetadataHash PoolMetadataFile (Maybe (File () Out))
| PoolMetadataHash (File StakePoolMetadata In) (Maybe (File () Out))
deriving Show

renderPoolCmd :: PoolCmd -> Text
Expand Down Expand Up @@ -524,10 +523,6 @@ data MetadataFile = MetadataFileJSON (File () In)

deriving Show

newtype PoolMetadataFile = PoolMetadataFile
{ unPoolMetadataFile :: FilePath }
deriving Show

newtype GenesisDir
= GenesisDir FilePath
deriving Show
Expand Down
15 changes: 7 additions & 8 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,15 +1626,14 @@ pCertificateFile balanceExecUnits =
, "stake key certificates etc). Optionally specify a script witness."
]

pPoolMetadataFile :: Parser PoolMetadataFile
pPoolMetadataFile :: Parser (File StakePoolMetadata In)
pPoolMetadataFile =
PoolMetadataFile <$>
Opt.strOption
( Opt.long "pool-metadata-file"
<> Opt.metavar "FILE"
<> Opt.help "Filepath of the pool metadata."
<> Opt.completer (Opt.bashCompleter "file")
)
fmap File $ Opt.strOption $ mconcat
[ Opt.long "pool-metadata-file"
, Opt.metavar "FILE"
, Opt.help "Filepath of the pool metadata."
, Opt.completer (Opt.bashCompleter "file")
]

pTxMetadataJsonSchema :: Parser TxMetadataJsonSchema
pTxMetadataJsonSchema =
Expand Down
21 changes: 12 additions & 9 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Pool.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ module Cardano.CLI.Shelley.Run.Pool
, runPoolCmd
) where

import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT, hoistEither,
newExceptT)
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans (lift)
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT, hoistEither, left,
newExceptT, onLeft)
import qualified Data.ByteString.Char8 as BS
import Data.Function ((&))
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.IO as Text

Expand All @@ -19,9 +24,6 @@ import Cardano.CLI.Shelley.Key (VerificationKeyOrFile, readVerificatio
import Cardano.CLI.Types (OutputFormat (..))

import qualified Cardano.Ledger.Slot as Shelley
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans.Except (ExceptT)
import Data.Text (Text)

data ShelleyPoolCmdError
= ShelleyPoolCmdReadFileError !(FileError TextEnvelopeError)
Expand Down Expand Up @@ -180,10 +182,11 @@ runPoolId verKeyOrFile outputFormat = do
OutputFormatBech32 ->
Text.putStrLn $ serialiseToBech32 (verificationKeyHash stakePoolVerKey)

runPoolMetadataHash :: PoolMetadataFile -> Maybe (File () Out) -> ExceptT ShelleyPoolCmdError IO ()
runPoolMetadataHash (PoolMetadataFile poolMDPath) mOutFile = do
metadataBytes <- handleIOExceptT (ShelleyPoolCmdReadFileError . FileIOError poolMDPath) $
BS.readFile poolMDPath
runPoolMetadataHash :: File StakePoolMetadata In -> Maybe (File () Out) -> ExceptT ShelleyPoolCmdError IO ()
runPoolMetadataHash poolMDPath mOutFile = do
metadataBytes <- lift (readByteStringFile poolMDPath)
& onLeft (left . ShelleyPoolCmdReadFileError)

(_metadata, metadataHash) <-
firstExceptT ShelleyPoolCmdMetadataValidationError
. hoistEither
Expand Down

0 comments on commit 4c3373f

Please sign in to comment.