Skip to content

Commit

Permalink
Merge pull request #884 from IntersectMBO/drepupdatecert
Browse files Browse the repository at this point in the history
add support for script based drep on update certificate
  • Loading branch information
CarlosLopezDeLara committed Sep 6, 2024
2 parents 26051f0 + 8547400 commit e90cf44
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ data GovernanceDRepRetirementCertificateCmdArgs era
data GovernanceDRepUpdateCertificateCmdArgs era
= GovernanceDRepUpdateCertificateCmdArgs
{ eon :: !(ConwayEraOnwards era)
, drepVkeyHashSource :: !(VerificationKeyOrHashOrFile DRepKey)
, drepHashSource :: !DRepHashSource
, mAnchor :: !(Maybe (L.Anchor (L.EraCrypto (ShelleyLedgerEra era))))
, outFile :: !(File () Out)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pUpdateCertificateCmd era = do
( fmap GovernanceDRepUpdateCertificateCmd $
conwayEraOnwardsConstraints w $
GovernanceDRepUpdateCertificateCmdArgs w
<$> pDRepVerificationKeyOrHashOrFile
<$> pDRepHashSource
<*> pDRepMetadata
<*> pOutputFile
)
Expand Down
14 changes: 5 additions & 9 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ module Cardano.CLI.EraBased.Run.Governance.DRep
where

import Cardano.Api
import Cardano.Api.Ledger (Credential (KeyHashObj))
import Cardano.Api.Shelley

import qualified Cardano.CLI.EraBased.Commands.Governance.DRep as Cmd
import qualified Cardano.CLI.EraBased.Run.Key as Key
Expand Down Expand Up @@ -147,17 +145,15 @@ runGovernanceDRepUpdateCertificateCmd
runGovernanceDRepUpdateCertificateCmd
Cmd.GovernanceDRepUpdateCertificateCmdArgs
{ eon = w
, drepVkeyHashSource
, drepHashSource
, mAnchor
, outFile
} =
conwayEraOnwardsConstraints w $ do
DRepKeyHash drepKeyHash <-
firstExceptT GovernanceCmdKeyReadError $
readVerificationKeyOrHashOrFile AsDRepKey drepVkeyHashSource
makeDrepUpdateCertificate (DRepUpdateRequirements w (KeyHashObj drepKeyHash)) mAnchor
& writeFileTextEnvelope outFile (Just "DRep Update Certificate")
& firstExceptT GovernanceCmdTextEnvWriteError . newExceptT
drepCredential <- modifyError GovernanceCmdKeyReadError $ readDRepCredential drepHashSource
let updateCertificate = makeDrepUpdateCertificate (DRepUpdateRequirements w drepCredential) mAnchor
firstExceptT GovernanceCmdTextEnvWriteError . newExceptT $
writeFileTextEnvelope outFile (Just "DRep Update Certificate") updateCertificate

runGovernanceDRepMetadataHashCmd
:: ()
Expand Down
17 changes: 17 additions & 0 deletions cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,23 @@ hprop_golden_governance_drep_update_certificate_vkey_file = propertyOnce . H.mod
]

H.diffFileVsGoldenFile outFile goldenFile

-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden governance drep update certificate script hash/"'@
hprop_golden_governance_drep_update_certificate_script_hash :: Property
hprop_golden_governance_drep_update_certificate_script_hash = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
goldenFile <- H.note "test/cardano-cli-golden/files/golden/governance/drep/drep_update_certificate_script_hash.json"
outFile <- H.noteTempFile tempDir "drep-upd-cert.txt"

void $ execCardanoCLI
[ "conway", "governance", "drep", "update-certificate"
, "--drep-script-hash", "8f33600845940d65bdbc7ea7a247a7997aa8558649128fa82c4c0468"
, "--drep-metadata-url", "https://github.com/raw/cardano-foundation/CIPs/master/CIP-0119/examples/drep.jsonld"
, "--drep-metadata-hash", "fecc1773db89b45557d82e07719c275f6877a6cadfd2469f4dc5a7df5b38b4a4"
, "--out-file", outFile
]

H.diffFileVsGoldenFile outFile goldenFile

-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden verification key drep/"'@
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "CertificateConway",
"description": "DRep Update Certificate",
"cborHex": "83128201581c8f33600845940d65bdbc7ea7a247a7997aa8558649128fa82c4c046882785e68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f63617264616e6f2d666f756e646174696f6e2f434950732f6d61737465722f4349502d303131392f6578616d706c65732f647265702e6a736f6e6c645820fecc1773db89b45557d82e07719c275f6877a6cadfd2469f4dc5a7df5b38b4a4"
}
3 changes: 2 additions & 1 deletion cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -7003,7 +7003,8 @@ Usage: cardano-cli conway governance drep retirement-certificate
Create a DRep retirement certificate.

Usage: cardano-cli conway governance drep update-certificate
( --drep-verification-key STRING
( --drep-script-hash HASH
| --drep-verification-key STRING
| --drep-verification-key-file FILE
| --drep-key-hash HASH
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Usage: cardano-cli conway governance drep update-certificate
( --drep-verification-key STRING
( --drep-script-hash HASH
| --drep-verification-key STRING
| --drep-verification-key-file FILE
| --drep-key-hash HASH
)
Expand All @@ -10,6 +11,8 @@ Usage: cardano-cli conway governance drep update-certificate
Create a DRep update certificate.

Available options:
--drep-script-hash HASH DRep script hash (hex-encoded). Obtain it with
"cardano-cli hash script ...".
--drep-verification-key STRING
DRep verification key (Bech32 or hex-encoded).
--drep-verification-key-file FILE
Expand Down

0 comments on commit e90cf44

Please sign in to comment.