Skip to content

Commit

Permalink
Merge pull request #330 from input-output-hk/smelc/drep-reg-certifica…
Browse files Browse the repository at this point in the history
…te-add-metadata

Drep certification registration: add parameters for anchor
  • Loading branch information
smelc authored Oct 6, 2023
2 parents f1e4419 + a429d39 commit 3cf1808
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module Cardano.CLI.EraBased.Commands.Governance.DRep
) where

import Cardano.Api
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley

import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Key
Expand All @@ -27,6 +29,7 @@ data GovernanceDRepCmds era
(ConwayEraOnwards era)
(VerificationKeyOrHashOrFile DRepKey)
Lovelace
(Maybe (Ledger.Anchor (Ledger.EraCrypto (ShelleyLedgerEra era))))
(File () Out)

renderGovernanceDRepCmds :: ()
Expand Down
28 changes: 27 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ import Cardano.CLI.Environment
import Cardano.CLI.EraBased.Commands.Governance.DRep
import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.Parser
import Cardano.CLI.Read
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Key
import qualified Cardano.Ledger.BaseTypes as L
import qualified Cardano.Ledger.Crypto as Crypto
import qualified Cardano.Ledger.SafeHash as L

import Control.Applicative
import Data.Foldable
Expand Down Expand Up @@ -88,14 +92,36 @@ pRegistrationCertificateCmd era = do
w <- forEraMaybeEon era
pure
$ subParser "registration-certificate"
$ Opt.info (mkParser w)
$ Opt.info (conwayEraOnwardsConstraints w $ mkParser w)
$ Opt.progDesc "Create a registration certificate."
where
mkParser w = GovernanceDRepRegistrationCertificateCmd w
<$> pDRepVerificationKeyOrHashOrFile
<*> pKeyRegistDeposit
<*> pDRepMetadata
<*> pOutputFile

pDRepMetadata :: Parser (Maybe (L.Anchor Crypto.StandardCrypto))
pDRepMetadata =
optional $
L.Anchor
<$> fmap unAnchorUrl pDrepMetadataUrl
<*> pDrepMetadataHash

pDrepMetadataUrl :: Parser AnchorUrl
pDrepMetadataUrl =
AnchorUrl
<$> pUrl "drep-metadata-url" "DRep anchor URL"

pDrepMetadataHash :: Parser (L.SafeHash Crypto.StandardCrypto L.AnchorData)
pDrepMetadataHash =
Opt.option readSafeHash $ mconcat
[ Opt.long "drep-metadata-hash"
, Opt.metavar "HASH"
, Opt.help "DRep anchor data hash."
]


--------------------------------------------------------------------------------

data AnyEraDecider era where
Expand Down
14 changes: 7 additions & 7 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ runGovernanceDRepCmds = \case
runGovernanceDRepIdCmd w vkey idOutputFormat mOutFp
& firstExceptT CmdGovernanceCmdError

GovernanceDRepRegistrationCertificateCmd w vkey lovelace outFp ->
runGovernanceRegistrationCertificateCmd w vkey lovelace outFp
& firstExceptT CmdRegistrationError
GovernanceDRepRegistrationCertificateCmd w vkey lovelace anchor outFp ->
conwayEraOnwardsConstraints w $ do
runGovernanceRegistrationCertificateCmd w vkey lovelace anchor outFp
& firstExceptT CmdRegistrationError

runGovernanceDRepIdCmd :: ()
=> ConwayEraOnwards era
Expand Down Expand Up @@ -72,18 +73,17 @@ runGovernanceRegistrationCertificateCmd
:: ConwayEraOnwards era
-> VerificationKeyOrHashOrFile DRepKey
-> Lovelace
-> Maybe (Ledger.Anchor (Ledger.EraCrypto (ShelleyLedgerEra era)))
-> File () Out
-> ExceptT RegistrationError IO ()
runGovernanceRegistrationCertificateCmd cOnwards drepKOrHOrF deposit outfp = do
runGovernanceRegistrationCertificateCmd cOnwards drepKOrHOrF deposit anchor outfp = do
DRepKeyHash drepKeyHash <- firstExceptT RegistrationReadError
. newExceptT
$ readVerificationKeyOrHashOrFile AsDRepKey drepKOrHOrF
let drepCred = Ledger.KeyHashObj $ conwayEraOnwardsConstraints cOnwards drepKeyHash
votingCredential = VotingCredential drepCred
req = DRepRegistrationRequirements cOnwards votingCredential deposit
registrationCert = makeDrepRegistrationCertificate req
-- TODO https://github.com/input-output-hk/cardano-cli/issues/198#issuecomment-1739874922
Nothing
registrationCert = makeDrepRegistrationCertificate req anchor
description = Just @TextEnvelopeDescr "DRep Key Registration Certificate"

firstExceptT RegistrationWriteFileError
Expand Down
12 changes: 11 additions & 1 deletion cardano-cli/src/Cardano/CLI/Types/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
{-# LANGUAGE StandaloneDeriving #-}

module Cardano.CLI.Types.Common
( AllOrOnly(..)
( AnchorDataHash(..)
, AnchorUrl(..)
, AllOrOnly(..)
, AddressKeyType(..)
, BalanceTxExecUnits (..)
, BlockId(..)
Expand Down Expand Up @@ -127,6 +129,14 @@ data ProposalHashSource
| ProposalHashSourceHash (L.SafeHash Crypto.StandardCrypto L.AnchorData)
deriving Show

newtype AnchorUrl = AnchorUrl
{ unAnchorUrl :: L.Url
} deriving (Eq, Show)

newtype AnchorDataHash = AnchorDataHash
{ unAnchorDataHash :: L.SafeHash Crypto.StandardCrypto L.AnchorData
} deriving (Eq, Show)

-- | Specify whether to render the script cost as JSON
-- in the cli's build command.
data TxBuildOutputOptions = OutputScriptCostOnly (File () Out)
Expand Down
2 changes: 2 additions & 0 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -6546,6 +6546,8 @@ Usage: cardano-cli conway governance drep registration-certificate
| --drep-key-hash HASH
)
--key-reg-deposit-amt NATURAL
[--drep-metadata-url TEXT
--drep-metadata-hash HASH]
--out-file FILE

Create a registration certificate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Usage: cardano-cli conway governance drep registration-certificate
| --drep-key-hash HASH
)
--key-reg-deposit-amt NATURAL
[--drep-metadata-url TEXT
--drep-metadata-hash HASH]
--out-file FILE

Create a registration certificate.
Expand All @@ -18,5 +20,8 @@ Available options:
is allowed.
--key-reg-deposit-amt NATURAL
Key registration deposit amount.
--drep-metadata-url TEXT DRep anchor URL
--drep-metadata-hash HASH
DRep anchor data hash.
--out-file FILE The output file.
-h,--help Show this help text

0 comments on commit 3cf1808

Please sign in to comment.