Skip to content

Commit

Permalink
Merge pull request #5108 from input-output-hk/newhoggy/cip-1694-make-…
Browse files Browse the repository at this point in the history
…space-for-drep-certificates

CIP-1694 make space for DRep certificates
  • Loading branch information
github-merge-queue[bot] authored Apr 18, 2023
2 parents 4f750d6 + 1232c20 commit 8faa631
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ module Cardano.Api (
-- choice for a stake address.
makeStakeAddressRegistrationCertificate,
makeStakeAddressDeregistrationCertificate,
makeStakeAddressDelegationCertificate,
makeStakeAddressPoolDelegationCertificate,

-- ** Registering stake pools
-- | Certificates that are embedded in transactions for registering and
Expand Down
14 changes: 7 additions & 7 deletions cardano-api/src/Cardano/Api/Certificate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Cardano.Api.Certificate (
-- * Registering stake address and delegating
makeStakeAddressRegistrationCertificate,
makeStakeAddressDeregistrationCertificate,
makeStakeAddressDelegationCertificate,
makeStakeAddressPoolDelegationCertificate,
PoolId,

-- * Registering stake pools
Expand Down Expand Up @@ -83,7 +83,7 @@ data Certificate =
-- Stake address certificates
StakeAddressRegistrationCertificate StakeCredential
| StakeAddressDeregistrationCertificate StakeCredential
| StakeAddressDelegationCertificate StakeCredential PoolId
| StakeAddressPoolDelegationCertificate StakeCredential PoolId

-- Stake pool certificates
| StakePoolRegistrationCertificate StakePoolParameters
Expand Down Expand Up @@ -113,7 +113,7 @@ instance HasTextEnvelope Certificate where
textEnvelopeDefaultDescr cert = case cert of
StakeAddressRegistrationCertificate{} -> "Stake address registration"
StakeAddressDeregistrationCertificate{} -> "Stake address de-registration"
StakeAddressDelegationCertificate{} -> "Stake address delegation"
StakeAddressPoolDelegationCertificate{} -> "Stake address stake pool delegation"
StakePoolRegistrationCertificate{} -> "Pool registration"
StakePoolRetirementCertificate{} -> "Pool retirement"
GenesisKeyDelegationCertificate{} -> "Genesis key delegation"
Expand Down Expand Up @@ -191,8 +191,8 @@ makeStakeAddressRegistrationCertificate = StakeAddressRegistrationCertificate
makeStakeAddressDeregistrationCertificate :: StakeCredential -> Certificate
makeStakeAddressDeregistrationCertificate = StakeAddressDeregistrationCertificate

makeStakeAddressDelegationCertificate :: StakeCredential -> PoolId -> Certificate
makeStakeAddressDelegationCertificate = StakeAddressDelegationCertificate
makeStakeAddressPoolDelegationCertificate :: StakeCredential -> PoolId -> Certificate
makeStakeAddressPoolDelegationCertificate = StakeAddressPoolDelegationCertificate

makeStakePoolRegistrationCertificate :: StakePoolParameters -> Certificate
makeStakePoolRegistrationCertificate = StakePoolRegistrationCertificate
Expand Down Expand Up @@ -225,7 +225,7 @@ toShelleyCertificate (StakeAddressDeregistrationCertificate stakecred) =
Shelley.DeRegKey
(toShelleyStakeCredential stakecred)

toShelleyCertificate (StakeAddressDelegationCertificate
toShelleyCertificate (StakeAddressPoolDelegationCertificate
stakecred (StakePoolKeyHash poolid)) =
Shelley.DCertDeleg $
Shelley.Delegate $
Expand Down Expand Up @@ -295,7 +295,7 @@ fromShelleyCertificate (Shelley.DCertDeleg (Shelley.DeRegKey stakecred)) =

fromShelleyCertificate (Shelley.DCertDeleg
(Shelley.Delegate (Shelley.Delegation stakecred poolid))) =
StakeAddressDelegationCertificate
StakeAddressPoolDelegationCertificate
(fromShelleyStakeCredential stakecred)
(StakePoolKeyHash poolid)

Expand Down
2 changes: 1 addition & 1 deletion cardano-api/src/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ mapTxScriptWitnesses f txbodycontent@TxBodyContent {
selectStakeCredential cert =
case cert of
StakeAddressDeregistrationCertificate stakecred -> Just stakecred
StakeAddressDelegationCertificate stakecred _ -> Just stakecred
StakeAddressPoolDelegationCertificate stakecred _ -> Just stakecred
_ -> Nothing

mapScriptWitnessesMinting
Expand Down
2 changes: 1 addition & 1 deletion cardano-api/src/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4208,7 +4208,7 @@ collectTxBodyScriptWitnesses TxBodyContent {
selectStakeCredential cert =
case cert of
StakeAddressDeregistrationCertificate stakecred -> Just stakecred
StakeAddressDelegationCertificate stakecred _ -> Just stakecred
StakeAddressPoolDelegationCertificate stakecred _ -> Just stakecred
_ -> Nothing

scriptWitnessesMinting
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Run/Friendly.hs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ friendlyCertificate =
StakeAddressDeregistrationCertificate credential ->
"stake address deregistration"
.= object [friendlyStakeCredential credential]
StakeAddressDelegationCertificate credential poolId ->
StakeAddressPoolDelegationCertificate credential poolId ->
"stake address delegation"
.= object [friendlyStakeCredential credential, "pool" .= poolId]

Expand Down
7 changes: 4 additions & 3 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ import Cardano.Api.Shelley

import Data.Text (Text)

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

import Cardano.Chain.Common (BlockCount)
Expand Down Expand Up @@ -115,7 +116,7 @@ data StakeAddressCmd
| StakeRegistrationCert StakeIdentifier OutputFile
| StakeCredentialDelegationCert
StakeIdentifier
(VerificationKeyOrHashOrFile StakePoolKey)
DelegationTarget
OutputFile
| StakeCredentialDeRegistrationCert StakeIdentifier OutputFile
deriving Show
Expand Down
9 changes: 9 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ module Cardano.CLI.Shelley.Key
, StakeVerifier(..)

, generateKeyPair

, DelegationTarget(..)
) where

import Cardano.Api
Expand All @@ -36,6 +38,7 @@ 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


Expand Down Expand Up @@ -110,6 +113,12 @@ data StakeIdentifier
| StakeIdentifierAddress StakeAddress
deriving (Eq, Show)

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

-- | Either an unvalidated text representation of a verification key or a path
-- to a verification key file.
data VerificationKeyTextOrFile
Expand Down
18 changes: 11 additions & 7 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ import Cardano.Chain.Common (BlockCount (BlockCount))

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

{- HLINT ignore "Use <$>" -}
Expand Down Expand Up @@ -379,7 +379,7 @@ pStakeAddressCmd =
, subParser "deregistration-certificate"
(Opt.info pStakeAddressDeregistrationCert $ Opt.progDesc "Create a stake address deregistration certificate")
, subParser "delegation-certificate"
(Opt.info pStakeAddressDelegationCert $ Opt.progDesc "Create a stake address delegation certificate")
(Opt.info pStakeAddressPoolDelegationCert $ Opt.progDesc "Create a stake address pool delegation certificate")
]
where
pStakeAddressKeyGen :: Parser StakeAddressCmd
Expand Down Expand Up @@ -409,11 +409,11 @@ pStakeAddressCmd =
<$> pStakeIdentifier
<*> pOutputFile

pStakeAddressDelegationCert :: Parser StakeAddressCmd
pStakeAddressDelegationCert =
pStakeAddressPoolDelegationCert :: Parser StakeAddressCmd
pStakeAddressPoolDelegationCert =
StakeCredentialDelegationCert
<$> pStakeIdentifier
<*> pStakePoolVerificationKeyOrHashOrFile
<*> pDelegationTarget
<*> pOutputFile

pKeyCmd :: Parser KeyCmd
Expand Down Expand Up @@ -2737,6 +2737,10 @@ pStakePoolVerificationKeyOrFile =
VerificationKeyValue <$> pStakePoolVerificationKey
<|> VerificationKeyFilePath <$> pStakePoolVerificationKeyFile

pDelegationTarget
:: Parser DelegationTarget
pDelegationTarget = StakePoolDelegationTarget <$> pStakePoolVerificationKeyOrHashOrFile

pStakePoolVerificationKeyOrHashOrFile
:: Parser (VerificationKeyOrHashOrFile StakePoolKey)
pStakePoolVerificationKeyOrHashOrFile =
Expand Down
39 changes: 15 additions & 24 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/StakeAddress.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeApplications #-}

module Cardano.CLI.Shelley.Run.StakeAddress
( ShelleyStakeAddressCmdError(ShelleyStakeAddressCmdReadKeyFileError)
Expand All @@ -9,7 +10,7 @@ module Cardano.CLI.Shelley.Run.StakeAddress

import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, newExceptT)
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
Expand All @@ -18,12 +19,14 @@ import qualified Data.Text.IO as Text
import Cardano.Api
import Cardano.Api.Shelley

import Cardano.CLI.Shelley.Key (StakeIdentifier (..), StakeVerifier (..),
VerificationKeyOrFile, VerificationKeyOrHashOrFile, readVerificationKeyOrFile,
import Cardano.CLI.Shelley.Key (DelegationTarget (..), StakeIdentifier (..),
StakeVerifier (..), VerificationKeyOrFile, readVerificationKeyOrFile,
readVerificationKeyOrHashOrFile)
import Cardano.CLI.Shelley.Parsers
import Cardano.CLI.Shelley.Run.Read
import Cardano.CLI.Types
import Control.Monad.Trans (lift)
import Data.Function ((&))

data ShelleyStakeAddressCmdError
= ShelleyStakeAddressCmdReadKeyFileError !(FileError InputDecodeError)
Expand Down Expand Up @@ -126,34 +129,22 @@ runStakeCredentialRegistrationCert stakeIdentifier (OutputFile oFp) = do
runStakeCredentialDelegationCert
:: StakeIdentifier
-- ^ Delegator stake verification key, verification key file or script file.
-> VerificationKeyOrHashOrFile StakePoolKey
-> DelegationTarget
-- ^ Delegatee stake pool verification key or verification key file or
-- verification key hash.
-> OutputFile
-> ExceptT ShelleyStakeAddressCmdError IO ()
runStakeCredentialDelegationCert stakeVerifier poolVKeyOrHashOrFile (OutputFile outFp) = do
poolStakeVKeyHash <-
firstExceptT
ShelleyStakeAddressCmdReadKeyFileError
(newExceptT $ readVerificationKeyOrHashOrFile AsStakePoolKey poolVKeyOrHashOrFile)
stakeCred <- getStakeCredentialFromIdentifier stakeVerifier
writeDelegationCert stakeCred poolStakeVKeyHash

where
writeDelegationCert
:: StakeCredential
-> Hash StakePoolKey
-> ExceptT ShelleyStakeAddressCmdError IO ()
writeDelegationCert sCred poolStakeVKeyHash = do
let delegCert = makeStakeAddressDelegationCertificate sCred poolStakeVKeyHash
runStakeCredentialDelegationCert stakeVerifier delegationTarget (OutputFile outFp) =
case delegationTarget of
StakePoolDelegationTarget poolVKeyOrHashOrFile -> do
poolStakeVKeyHash <- lift (readVerificationKeyOrHashOrFile AsStakePoolKey poolVKeyOrHashOrFile)
& onLeft (left . ShelleyStakeAddressCmdReadKeyFileError)
stakeCred <- getStakeCredentialFromIdentifier stakeVerifier
let delegCert = makeStakeAddressPoolDelegationCertificate stakeCred poolStakeVKeyHash
firstExceptT ShelleyStakeAddressCmdWriteFileError
. newExceptT
$ writeLazyByteStringFile outFp
$ textEnvelopeToJSON (Just delegCertDesc) delegCert

delegCertDesc :: TextEnvelopeDescr
delegCertDesc = "Stake Address Delegation Certificate"

$ textEnvelopeToJSON (Just @TextEnvelopeDescr "Stake Address Delegation Certificate") delegCert

runStakeCredentialDeRegistrationCert
:: StakeIdentifier
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Run/Validate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ validateTxCertificates era certsAndScriptWitnesses =
deriveStakeCredentialWitness cert = do
case cert of
StakeAddressDeregistrationCertificate sCred -> Just sCred
StakeAddressDelegationCertificate sCred _ -> Just sCred
StakeAddressPoolDelegationCertificate sCred _ -> Just sCred
_ -> Nothing

convert
Expand Down
2 changes: 1 addition & 1 deletion cardano-client-demo/StakeCredentialHistory.hs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ main = do
if t == cred then Just (StakeRegistrationEvent epochNo slotNo) else Nothing
targetedCert t epochNo slotNo (StakeAddressDeregistrationCertificate cred) =
if t == cred then Just (StakeDeRegistrationEvent epochNo slotNo) else Nothing
targetedCert t _epochNo slotNo (StakeAddressDelegationCertificate cred pool) =
targetedCert t _epochNo slotNo (StakeAddressPoolDelegationCertificate cred pool) =
if t == cred then Just (DelegationEvent slotNo pool) else Nothing
targetedCert t _epochNo slotNo (StakePoolRegistrationCertificate pool) =
inPoolCert t slotNo pool
Expand Down

0 comments on commit 8faa631

Please sign in to comment.