From a15d1cf139ea15cd4e403a262e1cae16cc4096f1 Mon Sep 17 00:00:00 2001 From: teodanciu Date: Wed, 18 Oct 2023 15:09:32 +0100 Subject: [PATCH 01/11] Update ledger, consensus and api versions for 8.6 --- cabal.project | 2 +- cardano-cli/cardano-cli.cabal | 20 ++++++++++---------- flake.lock | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cabal.project b/cabal.project index af4cd949e7..c91076e926 100644 --- a/cabal.project +++ b/cabal.project @@ -14,7 +14,7 @@ repository cardano-haskell-packages -- you need to run if you change them index-state: , hackage.haskell.org 2023-08-08T19:56:09Z - , cardano-haskell-packages 2023-10-20T00:31:44Z + , cardano-haskell-packages 2023-10-27T12:25:48Z packages: cardano-cli diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 6fc157010d..fece511cb3 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -203,19 +203,19 @@ library , binary , bytestring , canonical-json - , cardano-api ^>= 8.28.0.0 + , cardano-api ^>= 8.29.0.0 , cardano-binary , cardano-crypto , cardano-crypto-class ^>= 2.1.2 , cardano-crypto-wrapper ^>= 1.5.1 - , cardano-data >= 1.0 + , cardano-data >= 1.1 , cardano-git-rev - , cardano-ledger-alonzo >= 1.3.1.1 - , cardano-ledger-binary >= 1.0 + , cardano-ledger-alonzo >= 1.5.0.0 + , cardano-ledger-binary >= 1.2 , cardano-ledger-byron >= 1.0.0.2 - , cardano-ledger-conway >= 1.5 - , cardano-ledger-core >= 1.2 - , cardano-ledger-shelley >=1.4.1.0 + , cardano-ledger-conway >= 1.10 + , cardano-ledger-core >= 1.8 + , cardano-ledger-shelley >=1.7.0.0 , cardano-ping ^>= 0.2.0.5 , cardano-prelude , cardano-slotting ^>= 0.1 @@ -234,9 +234,9 @@ library , microlens , network , optparse-applicative-fork - , ouroboros-consensus >= 0.12 - , ouroboros-consensus-cardano >= 0.10 - , ouroboros-consensus-protocol >= 0.5.0.4 + , ouroboros-consensus >= 0.13 + , ouroboros-consensus-cardano >= 0.11 + , ouroboros-consensus-protocol >= 0.6.0.0 , ouroboros-network-api , ouroboros-network-protocols , parsec diff --git a/flake.lock b/flake.lock index a80ee0c93f..32dedb0bb4 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "CHaP": { "flake": false, "locked": { - "lastModified": 1697767832, - "narHash": "sha256-RkuWkTcWufRer/fyzcAnvJA7WLvNitdG8JMKSaNDJag=", + "lastModified": 1698409315, + "narHash": "sha256-0h8SwdLnp/c02K9dXMlT37nTtmhgA1hKVaMjHLEtFYE=", "owner": "input-output-hk", "repo": "cardano-haskell-packages", - "rev": "3a758410d00a426ce51596d4bc236d1b1d388b12", + "rev": "9313f1f20599a693e4828600b67a19dbf7db2e30", "type": "github" }, "original": { From 97bbd95d7921a253271251ebf1c53a96e025e1e4 Mon Sep 17 00:00:00 2001 From: teodanciu Date: Wed, 18 Oct 2023 23:39:26 +0100 Subject: [PATCH 02/11] Adapt to new anchor parameter in `ConwayResignCommitteeColdKey` --- .../EraBased/Commands/Governance/Committee.hs | 3 ++ .../EraBased/Options/Governance/Committee.hs | 40 ++++++++++++++++--- .../CLI/EraBased/Run/Governance/Committee.hs | 3 +- cardano-cli/src/Cardano/CLI/Json/Friendly.hs | 6 ++- .../CLI/Types/Errors/TxValidationError.hs | 2 +- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs index 141a3d77f8..9746c3f9ef 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs @@ -13,6 +13,8 @@ module Cardano.CLI.EraBased.Commands.Governance.Committee ) where import Cardano.Api +import qualified Cardano.Api.Ledger as Ledger +import Cardano.Api.Shelley import Cardano.CLI.Types.Key import Cardano.CLI.Types.Key.VerificationKey @@ -59,6 +61,7 @@ data GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs era = GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs { eon :: !(ConwayEraOnwards era) , vkeyColdKeySource :: !(VerificationKeyOrHashOrFile CommitteeColdKey) + , anchor :: !(Maybe (Ledger.Anchor (Ledger.EraCrypto (ShelleyLedgerEra era)))) , outFile :: !(File () Out) } deriving Show diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs index f6548bd323..72159ba55b 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE TypeFamilies #-} module Cardano.CLI.EraBased.Options.Governance.Committee ( pGovernanceCommitteeCmds @@ -8,6 +9,10 @@ import Cardano.Api import Cardano.CLI.EraBased.Commands.Governance.Committee import Cardano.CLI.EraBased.Options.Common +import Cardano.CLI.Read +import qualified Cardano.Ledger.BaseTypes as L +import qualified Cardano.Ledger.Crypto as Crypto +import qualified Cardano.Ledger.SafeHash as L import Options.Applicative (Parser) import qualified Options.Applicative as Opt @@ -116,13 +121,36 @@ pGovernanceCommitteeCreateColdKeyResignationCertificateCmd era = do w <- forEraMaybeEon era pure $ subParser "create-cold-key-resignation-certificate" - $ Opt.info - ( fmap GovernanceCommitteeCreateColdKeyResignationCertificateCmd $ - GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs w - <$> pCommitteeColdVerificationKeyOrHashOrFile - <*> pOutputFile - ) + $ Opt.info (conwayEraOnwardsConstraints w $ mkParser w) $ Opt.progDesc $ mconcat [ "Create cold key resignation certificate for a Constitutional Committee Member" ] + where + mkParser w = GovernanceCommitteeCreateColdKeyResignationCertificateCmd <$> + ( + GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs w <$> + pCommitteeColdVerificationKeyOrHashOrFile <*> + pAnchor <*> + pOutputFile + ) + +pAnchor :: Parser (Maybe (L.Anchor Crypto.StandardCrypto)) +pAnchor = + Opt.optional $ + L.Anchor + <$> fmap unAnchorUrl pAnchorUrl + <*> pSafeHash + +pAnchorUrl :: Parser AnchorUrl +pAnchorUrl = + AnchorUrl + <$> pUrl "committee-cold-key-resignation-certificate-metadata-url" "Committee cold key resignation certificate URL" + +pSafeHash :: Parser (L.SafeHash Crypto.StandardCrypto L.AnchorData) +pSafeHash = + Opt.option readSafeHash $ mconcat + [ Opt.long "committee-cold-key-resignation-certificate-metadata-hash" + , Opt.metavar "HASH" + , Opt.help "Committee cold key resignation certificate metadata hash." + ] diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs index e0056f2286..e1b8db68ec 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs @@ -172,6 +172,7 @@ runGovernanceCommitteeColdKeyResignationCertificate Cmd.GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs { Cmd.eon = w , Cmd.vkeyColdKeySource = coldVkOrHashOrFp + , Cmd.anchor = anchor , Cmd.outFile = oFp } = conwayEraOnwardsConstraints w $ do @@ -179,7 +180,7 @@ runGovernanceCommitteeColdKeyResignationCertificate lift (readVerificationKeyOrHashOrTextEnvFile AsCommitteeColdKey coldVkOrHashOrFp) & onLeft (left . GovernanceCommitteeCmdKeyReadError) - makeCommitteeColdkeyResignationCertificate (CommitteeColdkeyResignationRequirements w coldVKHash) + makeCommitteeColdkeyResignationCertificate (CommitteeColdkeyResignationRequirements w coldVKHash anchor) & textEnvelopeToJSON (Just genKeyDelegCertDesc) & writeLazyByteStringFile oFp & firstExceptT GovernanceCommitteeCmdTextEnvWriteError . newExceptT diff --git a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs index ae4bae9b25..1e5e353513 100644 --- a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs +++ b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs @@ -426,10 +426,12 @@ renderCertificate sbe = \case [ "cold key hash" .= ck , "hot key hash" .= hk ] - Ledger.ResignCommitteeColdTxCert cred -> case cred of + Ledger.ResignCommitteeColdTxCert cred anchor -> case cred of Shelley.ScriptHashObj sh -> "Cold committee resignation" .= object - [ "script hash" .= sh ] + [ "script hash" .= sh + , "anchor" .= anchor + ] Shelley.KeyHashObj ck@Shelley.KeyHash{} -> "Constitutional committee cold key resignation" .= object [ "cold key hash" .= ck diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs index 0f1f28c5e2..2dd5594d50 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs @@ -276,7 +276,7 @@ validateTxCertificates era certsAndScriptWitnesses = cardanoEraConstraints era $ L.DelegTxCert sCred _ -> Just sCred L.RegDepositDelegTxCert sCred _ _ -> Just sCred L.AuthCommitteeHotKeyTxCert{} -> Nothing - L.ResignCommitteeColdTxCert _ -> Nothing + L.ResignCommitteeColdTxCert _ _ -> Nothing L.RegDRepTxCert{} -> Nothing L.UnRegDRepTxCert{} -> Nothing L.UpdateDRepTxCert{} -> Nothing From 0672d09823f67878a4c99801e3dd06bbc9184791 Mon Sep 17 00:00:00 2001 From: teodanciu Date: Fri, 27 Oct 2023 12:20:20 +0100 Subject: [PATCH 03/11] Adapt to `ProtocolParametersUpdate` changes in cardano-api --- cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs | 1 - .../src/Cardano/CLI/EraBased/Options/Governance/Actions.hs | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs index febdb1ccd9..0f8f0ff578 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs @@ -2560,7 +2560,6 @@ pProtocolParametersUpdate = <*> optional pPoolInfluence <*> optional pMonetaryExpansion <*> optional pTreasuryExpansion - <*> pure Nothing <*> pure mempty <*> optional pExecutionUnitPrices <*> optional pMaxTxExecutionUnits diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs index 53f4d317aa..f5070c12bb 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs @@ -256,9 +256,9 @@ pDeprecatedAfterMaryPParams = DeprecatedAfterMaryPParams <$> convertToLedger toShelleyLovelace (optional pMinUTxOValue) -pShelleyToAlonzoPParams :: Parser (ShelleyToAlonzoPParams' ledgerera) +pShelleyToAlonzoPParams :: Parser (ShelleyToAlonzoPParams ledgerera) pShelleyToAlonzoPParams = - ShelleyToAlonzoPParams' + ShelleyToAlonzoPParams <$> convertToLedger id (optional $ toLedgerNonce <$> pExtraEntropy) <*> convertToLedger toUnitIntervalOrErr (optional pDecentralParam) @@ -318,7 +318,6 @@ dpGovActionProtocolParametersUpdate = \case <$> pCommonProtocolParameters <*> pShelleyToAlonzoPParams <*> pAlonzoOnwardsPParams - <*> pure (ShelleyToAlonzoPParams SNothing) ShelleyBasedEraBabbage -> BabbageEraBasedProtocolParametersUpdate <$> pCommonProtocolParameters From 87e92b18f0cb79112cb884f480a126dc1a15c06d Mon Sep 17 00:00:00 2001 From: teodanciu Date: Fri, 27 Oct 2023 13:02:03 +0100 Subject: [PATCH 04/11] Adjust to `txValidityRange` split into lower and upper bound --- cardano-cli/src/Cardano/CLI/Byron/Tx.hs | 12 ++++-------- .../src/Cardano/CLI/EraBased/Run/Transaction.hs | 16 ++++++++++------ cardano-cli/src/Cardano/CLI/Json/Friendly.hs | 7 ++++--- .../CLI/Types/Errors/TxValidationError.hs | 2 +- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Byron/Tx.hs b/cardano-cli/src/Cardano/CLI/Byron/Tx.hs index d52085a918..1518ab6be2 100644 --- a/cardano-cli/src/Cardano/CLI/Byron/Tx.hs +++ b/cardano-cli/src/Cardano/CLI/Byron/Tx.hs @@ -158,10 +158,8 @@ txSpendGenesisUTxOByronPBFT gc nId sk (ByronAddress bAddr) outs = do , txTotalCollateral = TxTotalCollateralNone , txReturnCollateral = TxReturnCollateralNone , txFee = TxFeeImplicit ByronEraOnlyByron - , txValidityRange = - ( TxValidityNoLowerBound - , defaultTxValidityUpperBound ByronEra - ) + , txValidityLowerBound = TxValidityNoLowerBound + , txValidityUpperBound = defaultTxValidityUpperBound ByronEra , txMetadata = TxMetadataNone , txAuxScripts = TxAuxScriptsNone , txExtraKeyWits = TxExtraKeyWitnessesNone @@ -207,10 +205,8 @@ txSpendUTxOByronPBFT nId sk txIns outs = do , txTotalCollateral = TxTotalCollateralNone , txReturnCollateral = TxReturnCollateralNone , txFee = TxFeeImplicit ByronEraOnlyByron - , txValidityRange = - ( TxValidityNoLowerBound - , defaultTxValidityUpperBound ByronEra - ) + , txValidityLowerBound = TxValidityNoLowerBound + , txValidityUpperBound = defaultTxValidityUpperBound ByronEra , txMetadata = TxMetadataNone , txAuxScripts = TxAuxScriptsNone , txExtraKeyWits = TxExtraKeyWitnessesNone diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index 0919fbc47d..3bec842026 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -418,8 +418,10 @@ runTxBuildRaw era <- first TxCmdReturnCollateralValidationError $ validateTxReturnCollateral era mReturnCollateral validatedFee <- first TxCmdTxFeeValidationError $ validateTxFee era mFee - validatedBounds <- (,) <$> first TxCmdTxValidityLowerBoundValidationError (validateTxValidityLowerBound era mLowerBound) - <*> first TxCmdTxValidityUpperBoundValidationError (validateTxValidityUpperBound era mUpperBound) + validatedLowerBound + <- first TxCmdTxValidityLowerBoundValidationError (validateTxValidityLowerBound era mLowerBound) + validatedUpperBound + <- first TxCmdTxValidityUpperBoundValidationError (validateTxValidityUpperBound era mUpperBound) validatedReqSigners <- first TxCmdRequiredSignersValidationError $ validateRequiredSigners era reqSigners validatedPParams @@ -443,7 +445,8 @@ runTxBuildRaw era , txTotalCollateral = validatedTotCollateral , txReturnCollateral = validatedRetCol , txFee = validatedFee - , txValidityRange = validatedBounds + , txValidityLowerBound = validatedLowerBound + , txValidityUpperBound = validatedUpperBound , txMetadata = txMetadata , txAuxScripts = txAuxScripts , txExtraKeyWits = validatedReqSigners @@ -528,8 +531,8 @@ runTxBuild validatedRetCol <- hoistEither $ first TxCmdReturnCollateralValidationError $ validateTxReturnCollateral era mReturnCollateral dFee <- hoistEither $ first TxCmdTxFeeValidationError $ validateTxFee era dummyFee - validatedBounds <- (,) <$> hoistEither (first TxCmdTxValidityLowerBoundValidationError $ validateTxValidityLowerBound era mLowerBound) - <*> hoistEither (first TxCmdTxValidityUpperBoundValidationError $ validateTxValidityUpperBound era mUpperBound) + validatedLowerBound <- hoistEither (first TxCmdTxValidityLowerBoundValidationError (validateTxValidityLowerBound era mLowerBound)) + validatedUpperBound <- hoistEither (first TxCmdTxValidityUpperBoundValidationError (validateTxValidityUpperBound era mUpperBound)) validatedReqSigners <- hoistEither (first TxCmdRequiredSignersValidationError $ validateRequiredSigners era reqSigners) validatedTxWtdrwls <- hoistEither (first TxCmdTxWithdrawalsValidationError $ validateTxWithdrawals era withdrawals) validatedTxCerts <- hoistEither (first TxCmdTxCertificatesValidationError $ validateTxCertificates era certsAndMaybeScriptWits) @@ -579,7 +582,8 @@ runTxBuild , txTotalCollateral = validatedTotCollateral , txReturnCollateral = validatedRetCol , txFee = dFee - , txValidityRange = validatedBounds + , txValidityLowerBound = validatedLowerBound + , txValidityUpperBound = validatedUpperBound , txMetadata = txMetadata , txAuxScripts = txAuxScripts , txExtraKeyWits = validatedReqSigners diff --git a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs index 1e5e353513..d4847b5896 100644 --- a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs +++ b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs @@ -151,7 +151,8 @@ friendlyTxBodyImpl , txReturnCollateral , txInsReference , txUpdateProposal - , txValidityRange + , txValidityLowerBound + ,txValidityUpperBound , txWithdrawals }) = [ "auxiliary scripts" .= friendlyAuxScripts txAuxScripts @@ -169,7 +170,7 @@ friendlyTxBodyImpl , "required signers (payment key hashes needed for scripts)" .= friendlyExtraKeyWits txExtraKeyWits , "update proposal" .= friendlyUpdateProposal txUpdateProposal - , "validity range" .= friendlyValidityRange era txValidityRange + , "validity range" .= friendlyValidityRange era (txValidityLowerBound, txValidityUpperBound) , "withdrawals" .= friendlyWithdrawals txWithdrawals ] @@ -190,7 +191,7 @@ friendlyExtraKeyWits = \case -- | Special case of validity range: -- in Shelley, upper bound is TTL, and no lower bound pattern ShelleyTtl - :: SlotNo -> (TxValidityLowerBound era, TxValidityUpperBound era) + :: Maybe SlotNo -> (TxValidityLowerBound era, TxValidityUpperBound era) pattern ShelleyTtl ttl <- ( TxValidityNoLowerBound , TxValidityUpperBound _ ttl diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs index 2dd5594d50..b825dda6a4 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs @@ -157,7 +157,7 @@ validateTxValidityUpperBound validateTxValidityUpperBound era = \case Just slot -> do supported <- conjureWitness era TxValidityUpperBoundNotSupported - pure $ TxValidityUpperBound supported slot + pure $ TxValidityUpperBound supported (Just slot) Nothing -> do supported <- conjureWitness era TxValidityUpperBoundNotSupported pure $ TxValidityNoUpperBound supported From 022b657e7f1371608f1eae7529e830e97b2853b8 Mon Sep 17 00:00:00 2001 From: teodanciu Date: Tue, 24 Oct 2023 13:53:07 +0100 Subject: [PATCH 05/11] Add `getCommitteeCold\HotCredentialFromVerKeyHashOrFile` to `Read` --- cardano-cli/src/Cardano/CLI/Read.hs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/cardano-cli/src/Cardano/CLI/Read.hs b/cardano-cli/src/Cardano/CLI/Read.hs index 4773b65f66..19113f3184 100644 --- a/cardano-cli/src/Cardano/CLI/Read.hs +++ b/cardano-cli/src/Cardano/CLI/Read.hs @@ -79,6 +79,10 @@ module Cardano.CLI.Read -- * DRep credentials , getDRepCredentialFromVerKeyHashOrFile + -- * Committee credentials + , getCommitteeColdCredentialFromVerKeyHashOrFile + , getCommitteeHotCredentialFromVerKeyHashOrFile + , ReadSafeHashError(..) , readHexAsSafeHash , readSafeHash @@ -812,7 +816,7 @@ readVoteHashSource = \case VoteHashSourceHash h -> return h VoteHashSourceText c -> return $ Ledger.hashAnchorData $ Ledger.AnchorData $ Text.encodeUtf8 c VoteHashSourceFile fp -> do - cBs <- firstExceptT VoteErrorFile . newExceptT $ readByteStringFile fp + cBs <- firstExceptT VoteErrorFile . newExceptT $ readByteStringFile fp _utf8EncodedText <- firstExceptT VoteErrorTextNotUnicode . hoistEither $ Text.decodeUtf8' cBs return $ Ledger.hashAnchorData $ Ledger.AnchorData cBs @@ -1029,6 +1033,28 @@ getDRepCredentialFromVerKeyHashOrFile = \case pure . Ledger.KeyHashObj . unDRepKeyHash $ verificationKeyHash drepVerKey VerificationKeyHash kh -> pure . Ledger.KeyHashObj $ unDRepKeyHash kh +getCommitteeColdCredentialFromVerKeyHashOrFile :: () + => VerificationKeyOrHashOrFile CommitteeColdKey + -> ExceptT (FileError InputDecodeError) IO (Ledger.Credential Ledger.ColdCommitteeRole Ledger.StandardCrypto) +getCommitteeColdCredentialFromVerKeyHashOrFile = \case + VerificationKeyOrFile verKeyOrFile -> do + commmitteeColdVerKey <- + ExceptT (readVerificationKeyOrFile AsCommitteeColdKey verKeyOrFile) + let CommitteeColdKeyHash kh = verificationKeyHash commmitteeColdVerKey + pure $ Ledger.KeyHashObj kh + VerificationKeyHash (CommitteeColdKeyHash kh) -> pure $ Ledger.KeyHashObj kh + +getCommitteeHotCredentialFromVerKeyHashOrFile :: () + => VerificationKeyOrHashOrFile CommitteeHotKey + -> ExceptT (FileError InputDecodeError) IO (Ledger.Credential Ledger.HotCommitteeRole Ledger.StandardCrypto) +getCommitteeHotCredentialFromVerKeyHashOrFile = \case + VerificationKeyOrFile verKeyOrFile -> do + commmitteeHotVerKey <- + ExceptT (readVerificationKeyOrFile AsCommitteeHotKey verKeyOrFile) + let CommitteeHotKeyHash kh = verificationKeyHash commmitteeHotVerKey + pure $ Ledger.KeyHashObj kh + VerificationKeyHash (CommitteeHotKeyHash kh) -> pure $ Ledger.KeyHashObj kh + data ReadSafeHashError = ReadSafeHashErrorNotHex ByteString String | ReadSafeHashErrorInvalidHash Text From 4303fbfa5b2aa232552ab05529de3a4ed8f74b25 Mon Sep 17 00:00:00 2001 From: teodanciu Date: Tue, 24 Oct 2023 13:53:54 +0100 Subject: [PATCH 06/11] Replace queryCommitteState with new queryCommitteeMembersState and adapt to new filter options --- .../Cardano/CLI/EraBased/Commands/Query.hs | 16 ++++++++-- .../src/Cardano/CLI/EraBased/Options/Query.hs | 28 ++++++++++++++++- .../src/Cardano/CLI/EraBased/Run/Query.hs | 30 ++++++++++++------- .../Cardano/CLI/Types/Errors/QueryCmdError.hs | 6 ++++ 4 files changed, 67 insertions(+), 13 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Query.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Query.hs index 173c0c2fdf..27075b9ba4 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Query.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Query.hs @@ -5,6 +5,7 @@ module Cardano.CLI.EraBased.Commands.Query ( QueryCmds (..) + , QueryCommitteeMembersStateCmdArgs(..) , QueryLeadershipScheduleCmdArgs(..) , QueryProtocolParametersCmdArgs(..) , QueryConstitutionHashCmdArgs(..) @@ -55,7 +56,7 @@ data QueryCmds era | QueryGovStateCmd !(QueryNoArgCmdArgs era) | QueryDRepStateCmd !(QueryDRepStateCmdArgs era) | QueryDRepStakeDistributionCmd !(QueryDRepStakeDistributionCmdArgs era) - | QueryCommitteeStateCmd !(QueryNoArgCmdArgs era) + | QueryCommitteeMembersStateCmd !(QueryCommitteeMembersStateCmdArgs era) deriving (Generic, Show) data QueryLeadershipScheduleCmdArgs = QueryLeadershipScheduleCmdArgs @@ -199,6 +200,17 @@ data QueryDRepStakeDistributionCmdArgs era = QueryDRepStakeDistributionCmdArgs , mOutFile :: !(Maybe (File () Out)) } deriving Show +data QueryCommitteeMembersStateCmdArgs era = QueryCommitteeMembersStateCmdArgs + { eon :: !(ConwayEraOnwards era) + , nodeSocketPath :: !SocketPath + , consensusModeParams :: !AnyConsensusModeParams + , networkId :: !NetworkId + , committeeColdKeys :: ![VerificationKeyOrHashOrFile CommitteeColdKey] + , committeeHotKeys :: ![VerificationKeyOrHashOrFile CommitteeHotKey] + , memberStatuses :: ![MemberStatus] + , mOutFile :: !(Maybe (File () Out)) + } deriving Show + renderQueryCmds :: QueryCmds era -> Text renderQueryCmds = \case QueryLeadershipScheduleCmd {} -> @@ -239,7 +251,7 @@ renderQueryCmds = \case "drep-state" QueryDRepStakeDistributionCmd {} -> "drep-stake-distribution" - QueryCommitteeStateCmd {} -> + QueryCommitteeMembersStateCmd {} -> "committee-state" renderTxMempoolQuery :: TxMempoolQuery -> Text diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs index ea09c516f6..4bb9bd1da7 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs @@ -15,6 +15,7 @@ import Cardano.CLI.EraBased.Commands.Query import Cardano.CLI.EraBased.Options.Common import Cardano.CLI.Types.Common +import qualified Data.Text as Text (toLower, unpack) import Data.Foldable import Options.Applicative hiding (help, str) import qualified Options.Applicative as Opt @@ -351,8 +352,33 @@ pQueryGetCommitteeStateCmd era envCli = do w <- forEraMaybeEon era pure $ subParser "committee-state" - $ Opt.info (QueryCommitteeStateCmd <$> pQueryNoArgCmdArgs w envCli) + $ Opt.info (QueryCommitteeMembersStateCmd <$> pQueryCommitteeMembersStateArgs w) $ Opt.progDesc "Get the committee state" + where + pQueryCommitteeMembersStateArgs :: ConwayEraOnwards era -> Parser (QueryCommitteeMembersStateCmdArgs era) + pQueryCommitteeMembersStateArgs w = QueryCommitteeMembersStateCmdArgs w + <$> pSocketPath envCli + <*> pConsensusModeParams + <*> pNetworkId envCli + <*> many pCommitteeColdVerificationKeyOrHashOrFile + <*> many pCommitteeHotKeyOrHashOrFile + <*> many pMemberStatus + <*> optional pOutputFile + pMemberStatus :: Parser MemberStatus + pMemberStatus = + Opt.option readerMemberStatus $ mconcat + [ Opt.long "memberstatus" + , Opt.metavar "MEMBER_STATUS" + , Opt.help "Member status filter: active/expired/unrecognized" + ] + readerMemberStatus :: ReadM MemberStatus + readerMemberStatus = do + v <- Opt.str + case Text.toLower v of + "active" -> pure Active + "expired" -> pure Expired + "unrecognized" -> pure Unrecognized + _ -> fail ("Unrecognized status: " <> Text.unpack v) pQueryNoArgCmdArgs :: () => ConwayEraOnwards era diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs index cd8e309272..c983f1bcdd 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs @@ -129,7 +129,7 @@ runQueryCmds = \case Cmd.QueryGovStateCmd args -> runQueryGovState args Cmd.QueryDRepStateCmd args -> runQueryDRepState args Cmd.QueryDRepStakeDistributionCmd args -> runQueryDRepStakeDistribution args - Cmd.QueryCommitteeStateCmd args -> runQueryCommitteeState args + Cmd.QueryCommitteeMembersStateCmd args -> runQueryCommitteeMembersState args runQueryConstitutionHashCmd :: () => Cmd.QueryConstitutionHashCmdArgs @@ -1540,29 +1540,39 @@ runQueryDRepStakeDistribution writeOutput mOutFile $ Map.assocs drepStakeDistribution -runQueryCommitteeState - :: Cmd.QueryNoArgCmdArgs era +runQueryCommitteeMembersState + :: Cmd.QueryCommitteeMembersStateCmdArgs era -> ExceptT QueryCmdError IO () -runQueryCommitteeState - Cmd.QueryNoArgCmdArgs +runQueryCommitteeMembersState + Cmd.QueryCommitteeMembersStateCmdArgs { Cmd.eon , Cmd.nodeSocketPath , Cmd.consensusModeParams = AnyConsensusModeParams cModeParams , Cmd.networkId , Cmd.mOutFile - } - = conwayEraOnwardsConstraints eon $ do + , Cmd.committeeColdKeys = coldCredKeys + , Cmd.committeeHotKeys = hotCredKeys + , Cmd.memberStatuses = memberStatuses + } = conwayEraOnwardsConstraints eon $ do let localNodeConnInfo = LocalNodeConnectInfo cModeParams networkId nodeSocketPath sbe = conwayEraOnwardsToShelleyBasedEra eon cEra = conwayEraOnwardsToCardanoEra eon cMode = consensusModeOnly cModeParams + let coldKeysFromVerKeyHashOrFile = + firstExceptT QueryCmdCommitteeColdKeyError . getCommitteeColdCredentialFromVerKeyHashOrFile + coldKeys <- Set.fromList <$> mapM coldKeysFromVerKeyHashOrFile coldCredKeys + + let hotKeysFromVerKeyHashOrFile = + firstExceptT QueryCmdCommitteeHotKeyError . getCommitteeHotCredentialFromVerKeyHashOrFile + hotKeys <- Set.fromList <$> mapM hotKeysFromVerKeyHashOrFile hotCredKeys + eraInMode <- toEraInMode cEra cMode & hoistMaybe (QueryCmdEraConsensusModeMismatch (AnyConsensusMode cMode) (AnyCardanoEra cEra)) - committeeState <- runQuery localNodeConnInfo $ queryCommitteeState eraInMode sbe - writeOutput mOutFile $ - Map.assocs $ committeeState ^. Ledger.csCommitteeCredsL + committeeState <- runQuery localNodeConnInfo $ + queryCommitteeMembersState eraInMode sbe coldKeys hotKeys (Set.fromList memberStatuses) + writeOutput mOutFile committeeState runQuery :: LocalNodeConnectInfo mode -> LocalStateQueryExpr diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs index 82ddb5605d..de90425795 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/QueryCmdError.hs @@ -56,6 +56,8 @@ data QueryCmdError | QueryCmdUnsupportedNtcVersion !UnsupportedNtcVersionError | QueryCmdProtocolParameterConversionError !ProtocolParametersConversionError | QueryCmdDRepKeyError !(FileError InputDecodeError) + | QueryCmdCommitteeColdKeyError !(FileError InputDecodeError) + | QueryCmdCommitteeHotKeyError !(FileError InputDecodeError) deriving Show renderQueryCmdError :: QueryCmdError -> Text @@ -94,3 +96,7 @@ renderQueryCmdError = \case QueryCmdConvenienceError qce -> renderQueryConvenienceError qce QueryCmdDRepKeyError e -> "Error reading delegation representative key: " <> Text.pack (displayError e) + QueryCmdCommitteeColdKeyError e -> + "Error reading committee cold key: " <> Text.pack (displayError e) + QueryCmdCommitteeHotKeyError e -> + "Error reading committee hot key: " <> Text.pack (displayError e) From 5b2d25dd0d1524d21f90bf6ffbd2355ae709cb29 Mon Sep 17 00:00:00 2001 From: teodanciu Date: Fri, 27 Oct 2023 14:08:01 +0100 Subject: [PATCH 07/11] Parse `MemberStatus` filter as a flag rather than string argument --- .../src/Cardano/CLI/EraBased/Options/Query.hs | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs index 4bb9bd1da7..ca98268c3b 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs @@ -8,6 +8,7 @@ module Cardano.CLI.EraBased.Options.Query ) where import Cardano.Api hiding (QueryInShelleyBasedEra (..)) +import qualified Cardano.Api as MemberStatus (MemberStatus (..)) import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..)) import Cardano.CLI.Environment (EnvCli (..)) @@ -15,7 +16,6 @@ import Cardano.CLI.EraBased.Commands.Query import Cardano.CLI.EraBased.Options.Common import Cardano.CLI.Types.Common -import qualified Data.Text as Text (toLower, unpack) import Data.Foldable import Options.Applicative hiding (help, str) import qualified Options.Applicative as Opt @@ -364,21 +364,23 @@ pQueryGetCommitteeStateCmd era envCli = do <*> many pCommitteeHotKeyOrHashOrFile <*> many pMemberStatus <*> optional pOutputFile + pMemberStatus :: Parser MemberStatus pMemberStatus = - Opt.option readerMemberStatus $ mconcat - [ Opt.long "memberstatus" - , Opt.metavar "MEMBER_STATUS" - , Opt.help "Member status filter: active/expired/unrecognized" - ] - readerMemberStatus :: ReadM MemberStatus - readerMemberStatus = do - v <- Opt.str - case Text.toLower v of - "active" -> pure Active - "expired" -> pure Expired - "unrecognized" -> pure Unrecognized - _ -> fail ("Unrecognized status: " <> Text.unpack v) + asum + [ Opt.flag' MemberStatus.Active $ mconcat + [ Opt.long "active" + , Opt.help "Active committee members (members whose vote will count during ratification)" + ] + , Opt.flag' MemberStatus.Expired $ mconcat + [ Opt.long "expired" + , Opt.help "Expired committee members" + ] + , Opt.flag' MemberStatus.Unrecognized $ mconcat + [ Opt.long "unrecognized" + , Opt.help "Unrecognized committe members: a hot credential for an unknown cold credential" + ] + ] pQueryNoArgCmdArgs :: () => ConwayEraOnwards era From 486d0112b5b8cf91183d7b3f15f59c42b05a4e62 Mon Sep 17 00:00:00 2001 From: teodanciu Date: Fri, 27 Oct 2023 15:52:38 +0100 Subject: [PATCH 08/11] Update golden test files to reflect changes in commands --- .../cardano-cli-golden/files/golden/help.cli | 14 ++++++++++ ...reate-cold-key-resignation-certificate.cli | 7 +++++ .../help/conway_query_committee-state.cli | 26 +++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli index f452e6e020..97942f68a4 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -6467,6 +6467,8 @@ Usage: cardano-cli conway governance committee create-cold-key-resignation-certi | --cold-verification-key-file FILE | --cold-verification-key-hash STRING ) + [--committee-cold-key-resignation-certificate-metadata-url TEXT + --committee-cold-key-resignation-certificate-metadata-hash HASH] --out-file FILE Create cold key resignation certificate for a Constitutional Committee Member @@ -6953,6 +6955,18 @@ Usage: cardano-cli conway query committee-state --socket-path SOCKET_PATH ( --mainnet | --testnet-magic NATURAL ) + [ --cold-verification-key STRING + | --cold-verification-key-file FILE + | --cold-verification-key-hash STRING + ] + [ --hot-key STRING + | --hot-key-file FILE + | --hot-key-hash STRING + ] + [ --active + | --expired + | --unrecognized + ] [--out-file FILE] Get the committee state diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_committee_create-cold-key-resignation-certificate.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_committee_create-cold-key-resignation-certificate.cli index 6e4915aae1..fcb7a10c81 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_committee_create-cold-key-resignation-certificate.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_committee_create-cold-key-resignation-certificate.cli @@ -3,6 +3,8 @@ Usage: cardano-cli conway governance committee create-cold-key-resignation-certi | --cold-verification-key-file FILE | --cold-verification-key-hash STRING ) + [--committee-cold-key-resignation-certificate-metadata-url TEXT + --committee-cold-key-resignation-certificate-metadata-hash HASH] --out-file FILE Create cold key resignation certificate for a Constitutional Committee Member @@ -14,5 +16,10 @@ Available options: Filepath of the Consitutional Committee cold key. --cold-verification-key-hash STRING Constitutional Committee key hash (hex-encoded). + --committee-cold-key-resignation-certificate-metadata-url TEXT + Committee cold key resignation certificate URL + --committee-cold-key-resignation-certificate-metadata-hash HASH + Committee cold key resignation certificate metadata + hash. --out-file FILE The output file. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_query_committee-state.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_query_committee-state.cli index b637bdb3ad..08accb6143 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_query_committee-state.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_query_committee-state.cli @@ -8,6 +8,18 @@ Usage: cardano-cli conway query committee-state --socket-path SOCKET_PATH ( --mainnet | --testnet-magic NATURAL ) + [ --cold-verification-key STRING + | --cold-verification-key-file FILE + | --cold-verification-key-hash STRING + ] + [ --hot-key STRING + | --hot-key-file FILE + | --hot-key-hash STRING + ] + [ --active + | --expired + | --unrecognized + ] [--out-file FILE] Get the committee state @@ -30,5 +42,19 @@ Available options: CARDANO_NODE_NETWORK_ID environment variable --testnet-magic NATURAL Specify a testnet magic id. This overrides the CARDANO_NODE_NETWORK_ID environment variable + --cold-verification-key STRING + Constitutional Committee cold key (hex-encoded). + --cold-verification-key-file FILE + Filepath of the Consitutional Committee cold key. + --cold-verification-key-hash STRING + Constitutional Committee key hash (hex-encoded). + --hot-key STRING Constitutional Committee hot key (hex-encoded). + --hot-key-file FILE Filepath of the Consitutional Committee hot key. + --hot-key-hash STRING Constitutional Committee key hash (hex-encoded). + --active Active committee members (members whose vote will + count during ratification) + --expired Expired committee members + --unrecognized Unrecognized committe members: a hot credential for + an unknown cold credential --out-file FILE The output file. -h,--help Show this help text From eda3544dbeb74b4683d803df2eca1c508c1f9af0 Mon Sep 17 00:00:00 2001 From: John Ky Date: Sat, 28 Oct 2023 04:11:02 +1100 Subject: [PATCH 09/11] Fix CLI support for TxValidityUpperBound --- .../CLI/EraBased/Commands/Transaction.hs | 4 +- .../Cardano/CLI/EraBased/Options/Common.hs | 74 +++++++++++++------ .../CLI/EraBased/Options/Transaction.hs | 10 +-- .../Cardano/CLI/EraBased/Run/Transaction.hs | 11 +-- cardano-cli/src/Cardano/CLI/Json/Friendly.hs | 10 --- cardano-cli/src/Cardano/CLI/Legacy/Options.hs | 4 +- .../src/Cardano/CLI/Legacy/Run/Transaction.hs | 17 ++++- .../files/golden/allegra/transaction-view.out | 3 +- .../files/golden/shelley/transaction-view.out | 3 +- 9 files changed, 84 insertions(+), 52 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs index 3a7a36d7f7..a227a08dd2 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs @@ -62,7 +62,7 @@ data TransactionBuildRawCmdArgs era = TransactionBuildRawCmdArgs -- ^ Multi-Asset value with script witness , mValidityLowerBound :: !(Maybe SlotNo) -- ^ Transaction validity lower bound - , mValidityUpperBound :: !(Maybe SlotNo) + , mValidityUpperBound :: !(TxValidityUpperBound era) -- ^ Transaction validity upper bound , fee :: !(Maybe Lovelace) -- ^ Transaction fee @@ -110,7 +110,7 @@ data TransactionBuildCmdArgs era = TransactionBuildCmdArgs -- ^ Multi-Asset value with script witness , mValidityLowerBound :: !(Maybe SlotNo) -- ^ Transaction validity lower bound - , mValidityUpperBound :: !(Maybe SlotNo) + , mValidityUpperBound :: !(TxValidityUpperBound era) -- ^ Transaction validity upper bound , certificates :: ![(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))] -- ^ Certificates with potential script witness diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs index 0f8f0ff578..8d6763a64f 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs @@ -2077,30 +2077,62 @@ pInvalidBefore = fmap SlotNo $ asum ] ] -pInvalidHereafter :: Parser SlotNo -pInvalidHereafter = +pLegacyInvalidHereafter :: Parser SlotNo +pLegacyInvalidHereafter = fmap SlotNo $ asum - [ Opt.option (bounded "SLOT") $ mconcat - [ Opt.long "invalid-hereafter" - , Opt.metavar "SLOT" - , Opt.help "Time that transaction is valid until (in slots)." - ] - , Opt.option (bounded "SLOT") $ mconcat - [ Opt.long "upper-bound" - , Opt.metavar "SLOT" - , Opt.help $ mconcat - [ "Time that transaction is valid until (in slots) " - , "(deprecated; use --invalid-hereafter instead)." + [ Opt.option (bounded "SLOT") $ mconcat + [ Opt.long "invalid-hereafter" + , Opt.metavar "SLOT" + , Opt.help "Time that transaction is valid until (in slots)." + ] + , Opt.option (bounded "SLOT") $ mconcat + [ Opt.long "upper-bound" + , Opt.metavar "SLOT" + , Opt.help $ mconcat + [ "Time that transaction is valid until (in slots) " + , "(deprecated; use --invalid-hereafter instead)." + ] + , Opt.internal + ] + , Opt.option (bounded "SLOT") $ mconcat + [ Opt.long "ttl" + , Opt.metavar "SLOT" + , Opt.help "Time to live (in slots) (deprecated; use --invalid-hereafter instead)." + , Opt.internal ] - , Opt.internal - ] - , Opt.option (bounded "SLOT") $ mconcat - [ Opt.long "ttl" - , Opt.metavar "SLOT" - , Opt.help "Time to live (in slots) (deprecated; use --invalid-hereafter instead)." - , Opt.internal ] - ] + +pInvalidHereafter :: () + => CardanoEra era + -> Parser (TxValidityUpperBound era) +pInvalidHereafter = + caseByronOrShelleyBasedEra + (pure . TxValidityNoUpperBound) + (\eon -> + fmap (TxValidityUpperBound eon) $ asum + [ fmap (Just . SlotNo) $ Opt.option (bounded "SLOT") $ mconcat + [ Opt.long "invalid-hereafter" + , Opt.metavar "SLOT" + , Opt.help "Time that transaction is valid until (in slots)." + ] + , fmap (Just . SlotNo) $ Opt.option (bounded "SLOT") $ mconcat + [ Opt.long "upper-bound" + , Opt.metavar "SLOT" + , Opt.help $ mconcat + [ "Time that transaction is valid until (in slots) " + , "(deprecated; use --invalid-hereafter instead)." + ] + , Opt.internal + ] + , fmap (Just . SlotNo) $ Opt.option (bounded "SLOT") $ mconcat + [ Opt.long "ttl" + , Opt.metavar "SLOT" + , Opt.help "Time to live (in slots) (deprecated; use --invalid-hereafter instead)." + , Opt.internal + ] + , pure Nothing + ] + ) pTxFee :: Parser Lovelace pTxFee = diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs index 220457b798..13b1211dc4 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs @@ -155,9 +155,9 @@ pTransactionBuildCmd era envCli = do ] where pCmd :: ShelleyBasedEra era -> Parser (TransactionCmds era) - pCmd w = + pCmd sbe = fmap TransactionBuildCmd $ - TransactionBuildCmdArgs w + TransactionBuildCmdArgs sbe <$> pSocketPath envCli <*> pConsensusModeParams <*> pNetworkId envCli @@ -173,7 +173,7 @@ pTransactionBuildCmd era envCli = do <*> pChangeAddress <*> optional (pMintMultiAsset AutoBalance) <*> optional pInvalidBefore - <*> optional pInvalidHereafter + <*> pInvalidHereafter (shelleyBasedToCardanoEra sbe) <*> many (pCertificateFile AutoBalance) <*> many (pWithdrawal AutoBalance) <*> pTxMetadataJsonSchema @@ -182,7 +182,7 @@ pTransactionBuildCmd era envCli = do Nothing "Filepath of auxiliary script(s)") <*> many pMetadataFile - <*> pFeatured (shelleyBasedToCardanoEra w) (optional pUpdateProposalFile) + <*> pFeatured (shelleyBasedToCardanoEra sbe) (optional pUpdateProposalFile) <*> many (pFileInDirection "vote-file" "Filepath of the vote.") <*> many (pFileInDirection "proposal-file" "Filepath of the proposal.") <*> (OutputTxBodyOnly <$> pTxBodyFileOut <|> pCalculatePlutusScriptCost) @@ -209,7 +209,7 @@ pTransactionBuildRaw era = <*> many pTxOut <*> optional (pMintMultiAsset ManualBalance) <*> optional pInvalidBefore - <*> optional pInvalidHereafter + <*> pInvalidHereafter era <*> optional pTxFee <*> many (pCertificateFile ManualBalance ) <*> many (pWithdrawal ManualBalance) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index 3bec842026..437db0bfe4 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -376,7 +376,7 @@ runTxBuildRaw :: () -> [TxOut CtxTx era] -> Maybe SlotNo -- ^ Tx lower bound - -> Maybe SlotNo + -> TxValidityUpperBound era -- ^ Tx upper bound -> Maybe Lovelace -- ^ Tx fee @@ -420,8 +420,6 @@ runTxBuildRaw era <- first TxCmdTxFeeValidationError $ validateTxFee era mFee validatedLowerBound <- first TxCmdTxValidityLowerBoundValidationError (validateTxValidityLowerBound era mLowerBound) - validatedUpperBound - <- first TxCmdTxValidityUpperBoundValidationError (validateTxValidityUpperBound era mUpperBound) validatedReqSigners <- first TxCmdRequiredSignersValidationError $ validateRequiredSigners era reqSigners validatedPParams @@ -446,7 +444,7 @@ runTxBuildRaw era , txReturnCollateral = validatedRetCol , txFee = validatedFee , txValidityLowerBound = validatedLowerBound - , txValidityUpperBound = validatedUpperBound + , txValidityUpperBound = mUpperBound , txMetadata = txMetadata , txAuxScripts = txAuxScripts , txExtraKeyWits = validatedReqSigners @@ -488,7 +486,7 @@ runTxBuild :: () -- ^ Multi-Asset value(s) -> Maybe SlotNo -- ^ Tx lower bound - -> Maybe SlotNo + -> TxValidityUpperBound era -- ^ Tx upper bound -> [(Certificate era, Maybe (ScriptWitness WitCtxStake era))] -- ^ Certificate with potential script witness @@ -532,7 +530,6 @@ runTxBuild <- hoistEither $ first TxCmdReturnCollateralValidationError $ validateTxReturnCollateral era mReturnCollateral dFee <- hoistEither $ first TxCmdTxFeeValidationError $ validateTxFee era dummyFee validatedLowerBound <- hoistEither (first TxCmdTxValidityLowerBoundValidationError (validateTxValidityLowerBound era mLowerBound)) - validatedUpperBound <- hoistEither (first TxCmdTxValidityUpperBoundValidationError (validateTxValidityUpperBound era mUpperBound)) validatedReqSigners <- hoistEither (first TxCmdRequiredSignersValidationError $ validateRequiredSigners era reqSigners) validatedTxWtdrwls <- hoistEither (first TxCmdTxWithdrawalsValidationError $ validateTxWithdrawals era withdrawals) validatedTxCerts <- hoistEither (first TxCmdTxCertificatesValidationError $ validateTxCertificates era certsAndMaybeScriptWits) @@ -583,7 +580,7 @@ runTxBuild , txReturnCollateral = validatedRetCol , txFee = dFee , txValidityLowerBound = validatedLowerBound - , txValidityUpperBound = validatedUpperBound + , txValidityUpperBound = mUpperBound , txMetadata = txMetadata , txAuxScripts = txAuxScripts , txExtraKeyWits = validatedReqSigners diff --git a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs index d4847b5896..4385cb7a60 100644 --- a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs +++ b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs @@ -188,21 +188,11 @@ friendlyExtraKeyWits = \case TxExtraKeyWitnessesNone -> Null TxExtraKeyWitnesses _supported paymentKeyHashes -> toJSON paymentKeyHashes --- | Special case of validity range: --- in Shelley, upper bound is TTL, and no lower bound -pattern ShelleyTtl - :: Maybe SlotNo -> (TxValidityLowerBound era, TxValidityUpperBound era) -pattern ShelleyTtl ttl <- - ( TxValidityNoLowerBound - , TxValidityUpperBound _ ttl - ) - friendlyValidityRange :: CardanoEra era -> (TxValidityLowerBound era, TxValidityUpperBound era) -> Aeson.Value friendlyValidityRange era = \case - ShelleyTtl ttl -> object ["time to live" .= ttl] (lowerBound, upperBound) | isLowerBoundSupported || isUpperBoundSupported -> object diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Options.hs b/cardano-cli/src/Cardano/CLI/Legacy/Options.hs index 96349e0129..95bf1f8eb2 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Options.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Options.hs @@ -324,7 +324,7 @@ pTransaction envCli = <*> pChangeAddress <*> optional (pMintMultiAsset AutoBalance) <*> optional pInvalidBefore - <*> optional pInvalidHereafter + <*> optional pLegacyInvalidHereafter <*> many (pCertificateFile AutoBalance) <*> many (pWithdrawal AutoBalance) <*> pTxMetadataJsonSchema @@ -360,7 +360,7 @@ pTransaction envCli = <*> many pTxOut <*> optional (pMintMultiAsset ManualBalance) <*> optional pInvalidBefore - <*> optional pInvalidHereafter + <*> optional pLegacyInvalidHereafter <*> optional pTxFee <*> many (pCertificateFile ManualBalance ) <*> many (pWithdrawal ManualBalance) diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/Legacy/Run/Transaction.hs index f4f371e0b4..c490945013 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Run/Transaction.hs @@ -104,11 +104,13 @@ runLegacyTransactionBuildCmd & hoistEither & firstExceptT TxCmdTxUpdateProposalValidationError + let upperBound = TxValidityUpperBound sbe mUpperBound + runTransactionBuildCmd ( Cmd.TransactionBuildCmdArgs sbe socketPath consensusModeParams nid mScriptValidity mOverrideWits txins readOnlyRefIns reqSigners txinsc mReturnColl mTotCollateral txouts changeAddr mValue mLowBound - mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mfUpdateProposalFile voteFiles + upperBound certs wdrls metadataSchema scriptFiles metadataFiles mfUpdateProposalFile voteFiles proposalFiles outputOptions ) @@ -136,7 +138,7 @@ runLegacyTransactionBuildRawCmd :: () -> TxBodyFile Out -> ExceptT TxCmdError IO () runLegacyTransactionBuildRawCmd - (AnyCardanoEra era) mScriptValidity txins readOnlyRefIns txinsc mReturnColl + anyEra@(AnyCardanoEra era) mScriptValidity txins readOnlyRefIns txinsc mReturnColl mTotColl reqSigners txouts mValue mLowBound mUpperBound fee certs wdrls metadataSchema scriptFiles metadataFiles mProtocolParamsFile mUpdateProposal outFile = do @@ -146,10 +148,19 @@ runLegacyTransactionBuildRawCmd & hoistEither & firstExceptT TxCmdTxUpdateProposalValidationError + upperBound <- + caseByronOrShelleyBasedEra + (\w -> case mUpperBound of + Nothing -> pure $ TxValidityNoUpperBound w + Just _ -> left $ TxCmdTxValidityUpperBoundValidationError $ TxValidityUpperBoundNotSupported anyEra + ) + (\w -> pure $ TxValidityUpperBound w mUpperBound) + era + runTransactionBuildRawCmd ( Cmd.TransactionBuildRawCmdArgs era mScriptValidity txins readOnlyRefIns txinsc mReturnColl - mTotColl reqSigners txouts mValue mLowBound mUpperBound fee certs wdrls + mTotColl reqSigners txouts mValue mLowBound upperBound fee certs wdrls metadataSchema scriptFiles metadataFiles mProtocolParamsFile mfUpdateProposalFile [] [] outFile ) diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/allegra/transaction-view.out b/cardano-cli/test/cardano-cli-golden/files/golden/allegra/transaction-view.out index 8fe812eff0..b4a82f94d2 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/allegra/transaction-view.out +++ b/cardano-cli/test/cardano-cli-golden/files/golden/allegra/transaction-view.out @@ -22,5 +22,6 @@ return collateral: null total collateral: null update proposal: null validity range: - time to live: 101 + lower bound: null + upper bound: 101 withdrawals: null diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/transaction-view.out b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/transaction-view.out index 774c2780d4..e8f51f0365 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/shelley/transaction-view.out +++ b/cardano-cli/test/cardano-cli-golden/files/golden/shelley/transaction-view.out @@ -72,7 +72,8 @@ update proposal: transaction fee linear per byte: 76 treasury expansion: 87/88 validity range: - time to live: 33 + lower bound: null + upper bound: 33 withdrawals: - address: stake_test1up00fz9lyqs5sjks82k22eqz7a9srym9vysjgp3h2ua2v2cm522kg amount: 42 Lovelace From 10440c064bc6a8fe5612bb4bf1c33be74ec11260 Mon Sep 17 00:00:00 2001 From: teodanciu Date: Fri, 27 Oct 2023 18:36:11 +0100 Subject: [PATCH 10/11] Write the output of CommitteeMembersState query as json. --- cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs index c983f1bcdd..a9db2636a4 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs @@ -1572,7 +1572,7 @@ runQueryCommitteeMembersState committeeState <- runQuery localNodeConnInfo $ queryCommitteeMembersState eraInMode sbe coldKeys hotKeys (Set.fromList memberStatuses) - writeOutput mOutFile committeeState + writeOutput mOutFile $ A.toJSON committeeState runQuery :: LocalNodeConnectInfo mode -> LocalStateQueryExpr From f1928f95e38d869438a7e3934bffa523ad6298a3 Mon Sep 17 00:00:00 2001 From: teodanciu Date: Fri, 27 Oct 2023 20:00:00 +0100 Subject: [PATCH 11/11] Improve command option names based of committee resignation anchor --- .../CLI/EraBased/Options/Governance/Committee.hs | 6 +++--- .../test/cardano-cli-golden/files/golden/help.cli | 4 ++-- ...ee_create-cold-key-resignation-certificate.cli | 15 ++++++++------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs index 72159ba55b..e20d828933 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs @@ -145,12 +145,12 @@ pAnchor = pAnchorUrl :: Parser AnchorUrl pAnchorUrl = AnchorUrl - <$> pUrl "committee-cold-key-resignation-certificate-metadata-url" "Committee cold key resignation certificate URL" + <$> pUrl "resignation-metadata-url" "Constitutional Committee cold key resignation certificate URL" pSafeHash :: Parser (L.SafeHash Crypto.StandardCrypto L.AnchorData) pSafeHash = Opt.option readSafeHash $ mconcat - [ Opt.long "committee-cold-key-resignation-certificate-metadata-hash" + [ Opt.long "resignation-metadata-hash" , Opt.metavar "HASH" - , Opt.help "Committee cold key resignation certificate metadata hash." + , Opt.help "Constitutional Committee cold key resignation certificate metadata hash" ] diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli index 97942f68a4..e523c08067 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -6467,8 +6467,8 @@ Usage: cardano-cli conway governance committee create-cold-key-resignation-certi | --cold-verification-key-file FILE | --cold-verification-key-hash STRING ) - [--committee-cold-key-resignation-certificate-metadata-url TEXT - --committee-cold-key-resignation-certificate-metadata-hash HASH] + [--resignation-metadata-url TEXT + --resignation-metadata-hash HASH] --out-file FILE Create cold key resignation certificate for a Constitutional Committee Member diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_committee_create-cold-key-resignation-certificate.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_committee_create-cold-key-resignation-certificate.cli index fcb7a10c81..6a87a83d97 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_committee_create-cold-key-resignation-certificate.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_committee_create-cold-key-resignation-certificate.cli @@ -3,8 +3,8 @@ Usage: cardano-cli conway governance committee create-cold-key-resignation-certi | --cold-verification-key-file FILE | --cold-verification-key-hash STRING ) - [--committee-cold-key-resignation-certificate-metadata-url TEXT - --committee-cold-key-resignation-certificate-metadata-hash HASH] + [--resignation-metadata-url TEXT + --resignation-metadata-hash HASH] --out-file FILE Create cold key resignation certificate for a Constitutional Committee Member @@ -16,10 +16,11 @@ Available options: Filepath of the Consitutional Committee cold key. --cold-verification-key-hash STRING Constitutional Committee key hash (hex-encoded). - --committee-cold-key-resignation-certificate-metadata-url TEXT - Committee cold key resignation certificate URL - --committee-cold-key-resignation-certificate-metadata-hash HASH - Committee cold key resignation certificate metadata - hash. + --resignation-metadata-url TEXT + Constitutional Committee cold key resignation + certificate URL + --resignation-metadata-hash HASH + Constitutional Committee cold key resignation + certificate metadata hash --out-file FILE The output file. -h,--help Show this help text