Skip to content

Commit

Permalink
Rename DelegationTarget to PoolDelegationTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed May 26, 2023
1 parent b74b02f commit 3e834be
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 57 deletions.
15 changes: 7 additions & 8 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Expand Up @@ -44,19 +44,18 @@ module Cardano.CLI.Shelley.Commands
, ColdVerificationKeyOrFile (..)
) where

import Prelude

import Cardano.Api.Shelley

import Data.Text (Text)

import Cardano.CLI.Shelley.Key (DelegationTarget, PaymentVerifier, StakeIdentifier,
import Cardano.Chain.Common (BlockCount)
import Cardano.CLI.Shelley.Key (PaymentVerifier, PoolDelegationTarget, StakeIdentifier,
StakeVerifier, VerificationKeyOrFile, VerificationKeyOrHashOrFile,
VerificationKeyTextOrFile)
import Cardano.CLI.Types

import Cardano.Chain.Common (BlockCount)
import Cardano.Ledger.Shelley.TxBody (MIRPot)

import Prelude

import Data.Text (Text)
--
-- Shelley CLI command data types
--
Expand Down Expand Up @@ -116,7 +115,7 @@ data StakeAddressCmd
| StakeRegistrationCert StakeIdentifier (File () Out)
| StakeCredentialDelegationCert
StakeIdentifier
DelegationTarget
PoolDelegationTarget
(File () Out)
| StakeCredentialDeRegistrationCert StakeIdentifier (File () Out)
deriving Show
Expand Down
12 changes: 6 additions & 6 deletions cardano-cli/src/Cardano/CLI/Shelley/Key.hs
Expand Up @@ -26,10 +26,13 @@ module Cardano.CLI.Shelley.Key

, generateKeyPair

, DelegationTarget(..)
, PoolDelegationTarget(..)
) where

import Cardano.Api
import Cardano.Api.Shelley (StakePoolKey)

import Cardano.CLI.Types

import Control.Monad.IO.Class (MonadIO (..))
import Data.Bifunctor (Bifunctor (..))
Expand All @@ -39,9 +42,6 @@ import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text

import Cardano.Api.Shelley (StakePoolKey)
import Cardano.CLI.Types


------------------------------------------------------------------------------
-- Verification key deserialisation
Expand Down Expand Up @@ -115,8 +115,8 @@ data StakeIdentifier

-- | A resource that identifies the delegation target. At the moment a delegation
-- target can only be a stake pool.
newtype DelegationTarget
= StakePoolDelegationTarget (VerificationKeyOrHashOrFile StakePoolKey)
newtype PoolDelegationTarget
= PoolDelegationTarget (VerificationKeyOrHashOrFile StakePoolKey)
deriving Show

-- | Either an unvalidated text representation of a verification key or a path
Expand Down
65 changes: 33 additions & 32 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Expand Up @@ -15,6 +15,19 @@ module Cardano.CLI.Shelley.Parsers
, parseTxIn
) where

import Cardano.Api
import Cardano.Api.Shelley

import Cardano.Chain.Common (BlockCount (BlockCount))
import Cardano.CLI.Common.Parsers
import Cardano.CLI.Environment (EnvCli (..))
import Cardano.CLI.Shelley.Commands
import Cardano.CLI.Shelley.Key (PaymentVerifier (..), PoolDelegationTarget (..),
StakeIdentifier (..), StakeVerifier (..), VerificationKeyOrFile (..),
VerificationKeyOrHashOrFile (..), VerificationKeyTextOrFile (..))
import Cardano.CLI.Types
import qualified Cardano.Ledger.BaseTypes as Shelley
import qualified Cardano.Ledger.Shelley.TxBody as Shelley
import Cardano.Prelude (ConvertText (..))

import qualified Data.Aeson as Aeson
Expand Down Expand Up @@ -51,22 +64,6 @@ import qualified Text.Parsec.String as Parsec
import qualified Text.Parsec.Token as Parsec
import Text.Read (readEither, readMaybe)

import qualified Cardano.Ledger.BaseTypes as Shelley
import qualified Cardano.Ledger.Shelley.TxBody as Shelley

import Cardano.Api
import Cardano.Api.Shelley

import Cardano.Chain.Common (BlockCount (BlockCount))

import Cardano.CLI.Common.Parsers
import Cardano.CLI.Environment (EnvCli (..))
import Cardano.CLI.Shelley.Commands
import Cardano.CLI.Shelley.Key (DelegationTarget (..), PaymentVerifier (..),
StakeIdentifier (..), StakeVerifier (..), VerificationKeyOrFile (..),
VerificationKeyOrHashOrFile (..), VerificationKeyTextOrFile (..))
import Cardano.CLI.Types

{- HLINT ignore "Use <$>" -}
{- HLINT ignore "Move brackets to avoid $" -}

Expand Down Expand Up @@ -411,7 +408,7 @@ pStakeAddressCmd envCli =
pStakeAddressPoolDelegationCert =
StakeCredentialDelegationCert
<$> pStakeIdentifier
<*> pDelegationTarget
<*> pPoolDelegationTarget
<*> pOutputFile

pKeyCmd :: Parser KeyCmd
Expand Down Expand Up @@ -916,7 +913,7 @@ pPoolCmd envCli =
]
where
pId :: Parser PoolCmd
pId = PoolGetId <$> pStakePoolVerificationKeyOrFile <*> pOutputFormat
pId = PoolGetId <$> pPoolVerificationKeyOrFile <*> pOutputFormat

pPoolMetadataHashSubCmd :: Parser PoolCmd
pPoolMetadataHashSubCmd = PoolMetadataHash <$> pPoolMetadataFile <*> pMaybeOutputFile
Expand Down Expand Up @@ -1078,7 +1075,7 @@ pQueryCmd envCli =
<*> pConsensusModeParams
<*> pNetworkId envCli
<*> pGenesisFile "Shelley genesis filepath"
<*> pStakePoolVerificationKeyOrHashOrFile
<*> pPoolVerificationKeyOrHashOrFile
<*> pVrfSigningKeyFile
<*> pWhichLeadershipSchedule
<*> pMaybeOutputFile
Expand Down Expand Up @@ -2738,21 +2735,25 @@ pStakePoolVerificationKey =
<> Opt.help "Stake pool verification key (Bech32 or hex-encoded)."
)

pStakePoolVerificationKeyOrFile
pPoolVerificationKeyOrFile
:: Parser (VerificationKeyOrFile StakePoolKey)
pStakePoolVerificationKeyOrFile =
VerificationKeyValue <$> pStakePoolVerificationKey
<|> VerificationKeyFilePath <$> pStakePoolVerificationKeyFile
pPoolVerificationKeyOrFile =
asum
[ VerificationKeyValue <$> pStakePoolVerificationKey
, VerificationKeyFilePath <$> pStakePoolVerificationKeyFile
]

pDelegationTarget
:: Parser DelegationTarget
pDelegationTarget = StakePoolDelegationTarget <$> pStakePoolVerificationKeyOrHashOrFile
pPoolDelegationTarget
:: Parser PoolDelegationTarget
pPoolDelegationTarget = PoolDelegationTarget <$> pPoolVerificationKeyOrHashOrFile

pStakePoolVerificationKeyOrHashOrFile
pPoolVerificationKeyOrHashOrFile
:: Parser (VerificationKeyOrHashOrFile StakePoolKey)
pStakePoolVerificationKeyOrHashOrFile =
VerificationKeyOrFile <$> pStakePoolVerificationKeyOrFile
<|> VerificationKeyHash <$> pStakePoolVerificationKeyHash
pPoolVerificationKeyOrHashOrFile =
asum
[ VerificationKeyOrFile <$> pPoolVerificationKeyOrFile
, VerificationKeyHash <$> pStakePoolVerificationKeyHash
]

pVrfVerificationKeyFile :: Parser (VerificationKeyFile In)
pVrfVerificationKeyFile =
Expand Down Expand Up @@ -2990,7 +2991,7 @@ pStakePoolMetadataHash =
pStakePoolRegistrationCert :: EnvCli -> Parser PoolCmd
pStakePoolRegistrationCert envCli =
PoolRegistrationCert
<$> pStakePoolVerificationKeyOrFile
<$> pPoolVerificationKeyOrFile
<*> pVrfVerificationKeyOrFile
<*> pPoolPledge
<*> pPoolCost
Expand All @@ -3005,7 +3006,7 @@ pStakePoolRegistrationCert envCli =
pStakePoolRetirementCert :: Parser PoolCmd
pStakePoolRetirementCert =
PoolRetirementCert
<$> pStakePoolVerificationKeyOrFile
<$> pPoolVerificationKeyOrFile
<*> pEpochNo
<*> pOutputFile

Expand Down
22 changes: 11 additions & 11 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/StakeAddress.hs
Expand Up @@ -9,25 +9,25 @@ module Cardano.CLI.Shelley.Run.StakeAddress
, runStakeAddressKeyGenToFile
) where

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

import Cardano.Api
import Cardano.Api.Shelley

import Cardano.CLI.Shelley.Key (DelegationTarget (..), StakeIdentifier (..),
import Cardano.CLI.Shelley.Key (PoolDelegationTarget (..), StakeIdentifier (..),
StakeVerifier (..), VerificationKeyOrFile, readVerificationKeyOrFile,
readVerificationKeyOrHashOrFile)
import Cardano.CLI.Shelley.Parsers
import Cardano.CLI.Shelley.Run.Read
import Cardano.CLI.Types

import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans (lift)
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, 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

data ShelleyStakeAddressCmdError
= ShelleyStakeAddressCmdReadKeyFileError !(FileError InputDecodeError)
Expand Down Expand Up @@ -130,14 +130,14 @@ runStakeCredentialRegistrationCert stakeIdentifier oFp = do
runStakeCredentialDelegationCert
:: StakeIdentifier
-- ^ Delegator stake verification key, verification key file or script file.
-> DelegationTarget
-> PoolDelegationTarget
-- ^ Delegatee stake pool verification key or verification key file or
-- verification key hash.
-> File () Out
-> ExceptT ShelleyStakeAddressCmdError IO ()
runStakeCredentialDelegationCert stakeVerifier delegationTarget outFp =
case delegationTarget of
StakePoolDelegationTarget poolVKeyOrHashOrFile -> do
PoolDelegationTarget poolVKeyOrHashOrFile -> do
poolStakeVKeyHash <- lift (readVerificationKeyOrHashOrFile AsStakePoolKey poolVKeyOrHashOrFile)
& onLeft (left . ShelleyStakeAddressCmdReadKeyFileError)
stakeCred <- getStakeCredentialFromIdentifier stakeVerifier
Expand Down

0 comments on commit 3e834be

Please sign in to comment.