diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 962dbbaee2..30a434b616 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -200,7 +200,7 @@ library , binary , bytestring , canonical-json - , cardano-api ^>= 8.22 + , cardano-api ^>= 8.23.1 , cardano-binary , cardano-crypto , cardano-crypto-class ^>= 2.1.2 diff --git a/cardano-cli/src/Cardano/CLI/Byron/Tx.hs b/cardano-cli/src/Cardano/CLI/Byron/Tx.hs index 843f4cf8a9..1f4788ddcb 100644 --- a/cardano-cli/src/Cardano/CLI/Byron/Tx.hs +++ b/cardano-cli/src/Cardano/CLI/Byron/Tx.hs @@ -160,7 +160,7 @@ txSpendGenesisUTxOByronPBFT gc nId sk (ByronAddress bAddr) outs = do , txFee = TxFeeImplicit ByronEraOnlyByron , txValidityRange = ( TxValidityNoLowerBound - , TxValidityNoUpperBound ValidityNoUpperBoundInByronEra + , defaultTxValidityUpperBound ) , txMetadata = TxMetadataNone , txAuxScripts = TxAuxScriptsNone @@ -209,7 +209,7 @@ txSpendUTxOByronPBFT nId sk txIns outs = do , txFee = TxFeeImplicit ByronEraOnlyByron , txValidityRange = ( TxValidityNoLowerBound - , TxValidityNoUpperBound ValidityNoUpperBoundInByronEra + , defaultTxValidityUpperBound ) , txMetadata = TxMetadataNone , txAuxScripts = TxAuxScriptsNone diff --git a/cardano-cli/src/Cardano/CLI/Environment.hs b/cardano-cli/src/Cardano/CLI/Environment.hs index 932bdf71eb..a93b2d3465 100644 --- a/cardano-cli/src/Cardano/CLI/Environment.hs +++ b/cardano-cli/src/Cardano/CLI/Environment.hs @@ -11,9 +11,9 @@ module Cardano.CLI.Environment , getEnvSocketPath ) where -import Cardano.Api (AnyCardanoEra (..), AnyShelleyBasedEra (..), - AnyShelleyToBabbageEra (..), CardanoEra (..), NetworkId (..), NetworkMagic (..), - ShelleyBasedEra (..), ShelleyToBabbageEra (..)) +import Cardano.Api (AnyCardanoEra (..), AnyEraInEon (..), CardanoEra (..), NetworkId (..), + NetworkMagic (..), ShelleyBasedEra (..), ShelleyToBabbageEra (..), + forEraInEonMaybe) import Data.Word (Word32) import qualified System.Environment as IO @@ -38,31 +38,15 @@ getEnvCli = do , envCliAnyCardanoEra = mCardanoEra } -envCliAnyShelleyBasedEra :: EnvCli -> Maybe AnyShelleyBasedEra +envCliAnyShelleyBasedEra :: EnvCli -> Maybe (AnyEraInEon ShelleyBasedEra) envCliAnyShelleyBasedEra envCli = do AnyCardanoEra era <- envCliAnyCardanoEra envCli + forEraInEonMaybe era AnyEraInEon - case era of - ByronEra -> Nothing - ShelleyEra -> Just $ AnyShelleyBasedEra ShelleyBasedEraShelley - AllegraEra -> Just $ AnyShelleyBasedEra ShelleyBasedEraAllegra - MaryEra -> Just $ AnyShelleyBasedEra ShelleyBasedEraMary - AlonzoEra -> Just $ AnyShelleyBasedEra ShelleyBasedEraAlonzo - BabbageEra -> Just $ AnyShelleyBasedEra ShelleyBasedEraBabbage - ConwayEra -> Just $ AnyShelleyBasedEra ShelleyBasedEraConway - -envCliAnyShelleyToBabbageEra :: EnvCli -> Maybe AnyShelleyToBabbageEra +envCliAnyShelleyToBabbageEra :: EnvCli -> Maybe (AnyEraInEon ShelleyToBabbageEra) envCliAnyShelleyToBabbageEra envCli = do AnyCardanoEra era <- envCliAnyCardanoEra envCli - - case era of - ByronEra -> Nothing - ShelleyEra -> Just $ AnyShelleyToBabbageEra ShelleyToBabbageEraShelley - AllegraEra -> Just $ AnyShelleyToBabbageEra ShelleyToBabbageEraAllegra - MaryEra -> Just $ AnyShelleyToBabbageEra ShelleyToBabbageEraMary - AlonzoEra -> Just $ AnyShelleyToBabbageEra ShelleyToBabbageEraAlonzo - BabbageEra -> Just $ AnyShelleyToBabbageEra ShelleyToBabbageEraBabbage - ConwayEra -> Nothing + forEraInEonMaybe era AnyEraInEon -- | If the environment variable @CARDANO_NODE_NETWORK_ID@ is set, then return the network id therein. -- Otherwise, return 'Nothing'. diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs index 9e0c3fa266..59ee2e42f8 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs @@ -58,11 +58,11 @@ import qualified Text.Parsec.String as Parsec import qualified Text.Parsec.Token as Parsec import Text.Read (readEither, readMaybe) -defaultShelleyBasedEra :: AnyShelleyBasedEra -defaultShelleyBasedEra = AnyShelleyBasedEra ShelleyBasedEraBabbage +defaultShelleyBasedEra :: AnyEraInEon ShelleyBasedEra +defaultShelleyBasedEra = AnyEraInEon ShelleyBasedEraBabbage -defaultShelleyToBabbageEra :: AnyShelleyToBabbageEra -defaultShelleyToBabbageEra = AnyShelleyToBabbageEra ShelleyToBabbageEraBabbage +defaultShelleyToBabbageEra :: AnyEraInEon ShelleyToBabbageEra +defaultShelleyToBabbageEra = AnyEraInEon ShelleyToBabbageEraBabbage command' :: String -> String -> Parser a -> Mod CommandFields a command' c descr p = @@ -301,113 +301,113 @@ subInfoParser name i mps = case catMaybes mps of [] -> Nothing parsers -> Just $ subParser name $ Opt.info (asum parsers) i -pAnyShelleyBasedEra :: EnvCli -> Parser AnyShelleyBasedEra +pAnyShelleyBasedEra :: EnvCli -> Parser (AnyEraInEon ShelleyBasedEra) pAnyShelleyBasedEra envCli = asum $ mconcat - [ [ Opt.flag' (AnyShelleyBasedEra ShelleyBasedEraShelley) + [ [ Opt.flag' (AnyEraInEon ShelleyBasedEraShelley) $ mconcat [Opt.long "shelley-era", Opt.help "Specify the Shelley era"] - , Opt.flag' (AnyShelleyBasedEra ShelleyBasedEraAllegra) + , Opt.flag' (AnyEraInEon ShelleyBasedEraAllegra) $ mconcat [Opt.long "allegra-era", Opt.help "Specify the Allegra era"] - , Opt.flag' (AnyShelleyBasedEra ShelleyBasedEraMary) + , Opt.flag' (AnyEraInEon ShelleyBasedEraMary) $ mconcat [Opt.long "mary-era", Opt.help "Specify the Mary era"] - , Opt.flag' (AnyShelleyBasedEra ShelleyBasedEraAlonzo) + , Opt.flag' (AnyEraInEon ShelleyBasedEraAlonzo) $ mconcat [Opt.long "alonzo-era", Opt.help "Specify the Alonzo era"] - , Opt.flag' (AnyShelleyBasedEra ShelleyBasedEraBabbage) + , Opt.flag' (AnyEraInEon ShelleyBasedEraBabbage) $ mconcat [Opt.long "babbage-era", Opt.help "Specify the Babbage era (default)"] - , Opt.flag' (AnyShelleyBasedEra ShelleyBasedEraConway) + , Opt.flag' (AnyEraInEon ShelleyBasedEraConway) $ mconcat [Opt.long "conway-era", Opt.help "Specify the Conway era"] ] , maybeToList $ pure <$> envCliAnyShelleyBasedEra envCli , pure $ pure defaultShelleyBasedEra ] -pAnyShelleyToBabbageEra :: EnvCli -> Parser AnyShelleyToBabbageEra +pAnyShelleyToBabbageEra :: EnvCli -> Parser (AnyEraInEon ShelleyToBabbageEra) pAnyShelleyToBabbageEra envCli = asum $ mconcat - [ [ Opt.flag' (AnyShelleyToBabbageEra ShelleyToBabbageEraShelley) + [ [ Opt.flag' (AnyEraInEon ShelleyToBabbageEraShelley) $ mconcat [Opt.long "shelley-era", Opt.help "Specify the Shelley era"] - , Opt.flag' (AnyShelleyToBabbageEra ShelleyToBabbageEraAllegra) + , Opt.flag' (AnyEraInEon ShelleyToBabbageEraAllegra) $ mconcat [Opt.long "allegra-era", Opt.help "Specify the Allegra era"] - , Opt.flag' (AnyShelleyToBabbageEra ShelleyToBabbageEraMary) + , Opt.flag' (AnyEraInEon ShelleyToBabbageEraMary) $ mconcat [Opt.long "mary-era", Opt.help "Specify the Mary era"] - , Opt.flag' (AnyShelleyToBabbageEra ShelleyToBabbageEraAlonzo) + , Opt.flag' (AnyEraInEon ShelleyToBabbageEraAlonzo) $ mconcat [Opt.long "alonzo-era", Opt.help "Specify the Alonzo era"] - , Opt.flag' (AnyShelleyToBabbageEra ShelleyToBabbageEraBabbage) + , Opt.flag' (AnyEraInEon ShelleyToBabbageEraBabbage) $ mconcat [Opt.long "babbage-era", Opt.help "Specify the Babbage era (default)"] ] , maybeToList $ pure <$> envCliAnyShelleyToBabbageEra envCli , pure $ pure defaultShelleyToBabbageEra ] -pShelleyBasedShelley :: EnvCli -> Parser AnyShelleyBasedEra +pShelleyBasedShelley :: EnvCli -> Parser (AnyEraInEon ShelleyBasedEra) pShelleyBasedShelley envCli = asum $ mconcat - [ [ Opt.flag' (AnyShelleyBasedEra ShelleyBasedEraShelley) + [ [ Opt.flag' (AnyEraInEon ShelleyBasedEraShelley) $ mconcat [Opt.long "shelley-era", Opt.help "Specify the Shelley era"] ] , maybeToList $ fmap pure - $ mfilter (== AnyShelleyBasedEra ShelleyBasedEraShelley) + $ mfilter (== AnyEraInEon ShelleyBasedEraShelley) $ envCliAnyShelleyBasedEra envCli ] -pShelleyBasedAllegra :: EnvCli -> Parser AnyShelleyBasedEra +pShelleyBasedAllegra :: EnvCli -> Parser (AnyEraInEon ShelleyBasedEra) pShelleyBasedAllegra envCli = asum $ mconcat - [ [ Opt.flag' (AnyShelleyBasedEra ShelleyBasedEraAllegra) + [ [ Opt.flag' (AnyEraInEon ShelleyBasedEraAllegra) $ mconcat [Opt.long "allegra-era", Opt.help "Specify the Allegra era"] ] , maybeToList $ fmap pure - $ mfilter (== AnyShelleyBasedEra ShelleyBasedEraAllegra) + $ mfilter (== AnyEraInEon ShelleyBasedEraAllegra) $ envCliAnyShelleyBasedEra envCli ] -pShelleyBasedMary :: EnvCli -> Parser AnyShelleyBasedEra +pShelleyBasedMary :: EnvCli -> Parser (AnyEraInEon ShelleyBasedEra) pShelleyBasedMary envCli = asum $ mconcat - [ [ Opt.flag' (AnyShelleyBasedEra ShelleyBasedEraMary) + [ [ Opt.flag' (AnyEraInEon ShelleyBasedEraMary) $ mconcat [Opt.long "mary-era", Opt.help "Specify the Mary era"] ] , maybeToList $ fmap pure - $ mfilter (== AnyShelleyBasedEra ShelleyBasedEraMary) + $ mfilter (== AnyEraInEon ShelleyBasedEraMary) $ envCliAnyShelleyBasedEra envCli ] -pShelleyBasedAlonzo :: EnvCli -> Parser AnyShelleyBasedEra +pShelleyBasedAlonzo :: EnvCli -> Parser (AnyEraInEon ShelleyBasedEra) pShelleyBasedAlonzo envCli = asum $ mconcat - [ [ Opt.flag' (AnyShelleyBasedEra ShelleyBasedEraAlonzo) + [ [ Opt.flag' (AnyEraInEon ShelleyBasedEraAlonzo) $ mconcat [Opt.long "alonzo-era", Opt.help "Specify the Alonzo era"] ] , maybeToList $ fmap pure - $ mfilter (== AnyShelleyBasedEra ShelleyBasedEraAlonzo) + $ mfilter (== AnyEraInEon ShelleyBasedEraAlonzo) $ envCliAnyShelleyBasedEra envCli ] -pShelleyBasedBabbage :: EnvCli -> Parser AnyShelleyBasedEra +pShelleyBasedBabbage :: EnvCli -> Parser (AnyEraInEon ShelleyBasedEra) pShelleyBasedBabbage envCli = asum $ mconcat - [ [ Opt.flag' (AnyShelleyBasedEra ShelleyBasedEraBabbage) + [ [ Opt.flag' (AnyEraInEon ShelleyBasedEraBabbage) $ mconcat [Opt.long "babbage-era", Opt.help "Specify the Babbage era (default)"] ] , maybeToList $ fmap pure - $ mfilter (== AnyShelleyBasedEra ShelleyBasedEraBabbage) + $ mfilter (== AnyEraInEon ShelleyBasedEraBabbage) $ envCliAnyShelleyBasedEra envCli ] -pShelleyBasedConway :: EnvCli -> Parser AnyShelleyBasedEra +pShelleyBasedConway :: EnvCli -> Parser (AnyEraInEon ShelleyBasedEra) pShelleyBasedConway envCli = asum $ mconcat - [ [ Opt.flag' (AnyShelleyBasedEra ShelleyBasedEraConway) + [ [ Opt.flag' (AnyEraInEon ShelleyBasedEraConway) $ mconcat [Opt.long "conway-era", Opt.help "Specify the Conway era"] ] , maybeToList $ fmap pure - $ mfilter (== AnyShelleyBasedEra ShelleyBasedEraConway) + $ mfilter (== AnyEraInEon ShelleyBasedEraConway) $ envCliAnyShelleyBasedEra envCli ] diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs index 2014204e37..09ac10b52a 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs @@ -44,7 +44,7 @@ pGovernanceCmds era envCli = pCreateMirCertificatesCmds :: CardanoEra era -> Maybe (Parser (GovernanceCmds era)) pCreateMirCertificatesCmds era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "create-mir-certificate" $ Opt.info (pMIRPayStakeAddresses w <|> mirCertParsers w) 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 9627cbeef4..3c36629a2a 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs @@ -43,7 +43,7 @@ pGovernanceActionNewInfoCmd :: CardanoEra era -> Maybe (Parser (GovernanceActionCmds era)) pGovernanceActionNewInfoCmd era = do - cOn <- maybeEonInEra era + cOn <- forEraMaybeEon era pure $ subParser "create-info" $ Opt.info @@ -63,7 +63,7 @@ pGovernanceActionNewConstitutionCmd :: CardanoEra era -> Maybe (Parser (GovernanceActionCmds era)) pGovernanceActionNewConstitutionCmd era = do - cOn <- maybeEonInEra era + cOn <- forEraMaybeEon era pure $ subParser "create-constitution" $ Opt.info @@ -85,7 +85,7 @@ pGovernanceActionNewCommitteeCmd :: CardanoEra era -> Maybe (Parser (GovernanceActionCmds era)) pGovernanceActionNewCommitteeCmd era = do - cOn <- maybeEonInEra era + cOn <- forEraMaybeEon era pure $ subParser "create-new-committee" $ Opt.info @@ -116,7 +116,7 @@ pGovernanceActionNoConfidenceCmd :: CardanoEra era -> Maybe (Parser (GovernanceActionCmds era)) pGovernanceActionNoConfidenceCmd era = do - cOn <- maybeEonInEra era + cOn <- forEraMaybeEon era pure $ subParser "create-no-confidence" $ Opt.info @@ -145,7 +145,7 @@ pGovernanceActionProtocolParametersUpdateCmd :: () => CardanoEra era -> Maybe (Parser (GovernanceActionCmds era)) pGovernanceActionProtocolParametersUpdateCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "create-protocol-parameters-update" $ Opt.info @@ -280,7 +280,7 @@ dpGovActionProtocolParametersUpdate = \case pGovernanceActionTreasuryWithdrawalCmd :: CardanoEra era -> Maybe (Parser (GovernanceActionCmds era)) pGovernanceActionTreasuryWithdrawalCmd era = do - cOn <- maybeEonInEra era + cOn <- forEraMaybeEon era pure $ subParser "create-treasury-withdrawal" $ Opt.info 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 8ab2f8212a..71d91c1c76 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs @@ -33,7 +33,7 @@ pGovernanceCommitteeKeyGenColdCmd :: () => CardanoEra era -> Maybe (Parser (GovernanceCommitteeCmds era)) pGovernanceCommitteeKeyGenColdCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "key-gen-cold" $ Opt.info (pCmd w) @@ -54,7 +54,7 @@ pGovernanceCommitteeKeyGenHotCmd :: () => CardanoEra era -> Maybe (Parser (GovernanceCommitteeCmds era)) pGovernanceCommitteeKeyGenHotCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "key-gen-hot" $ Opt.info (pCmd w) @@ -75,7 +75,7 @@ pGovernanceCommitteeKeyHashCmd :: () => CardanoEra era -> Maybe (Parser (GovernanceCommitteeCmds era)) pGovernanceCommitteeKeyHashCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "key-hash" $ Opt.info @@ -91,7 +91,7 @@ pGovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd :: () => CardanoEra era -> Maybe (Parser (GovernanceCommitteeCmds era)) pGovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "create-hot-key-authorization-certificate" $ Opt.info @@ -109,7 +109,7 @@ pGovernanceCommitteeCreateColdKeyResignationCertificateCmd :: () => CardanoEra era -> Maybe (Parser (GovernanceCommitteeCmds era)) pGovernanceCommitteeCreateColdKeyResignationCertificateCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "create-cold-key-resignation-certificate" $ Opt.info diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/DRep.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/DRep.hs index f238e5732a..98df4e65ea 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/DRep.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/DRep.hs @@ -42,7 +42,7 @@ pGovernanceDRepKeyGenCmd :: () => CardanoEra era -> Maybe (Parser (GovernanceDRepCmds era)) pGovernanceDRepKeyGenCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "key-gen" $ Opt.info @@ -56,7 +56,7 @@ pGovernanceDRepKeyIdCmd :: () => CardanoEra era -> Maybe (Parser (GovernanceDRepCmds era)) pGovernanceDRepKeyIdCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "id" $ Opt.info @@ -85,7 +85,7 @@ pRegistrationCertificateCmd :: () => CardanoEra era -> Maybe (Parser (GovernanceDRepCmds era)) pRegistrationCertificateCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "registration-certificate" $ Opt.info (mkParser w) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Query.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Query.hs index 941b3397cb..d47eb8e0c0 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Query.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Query.hs @@ -33,7 +33,7 @@ pGovernanceQueryGetConstitutionCmd :: () -> EnvCli -> Maybe (Parser (GovernanceQueryCmds era)) pGovernanceQueryGetConstitutionCmd era env = do - cOn <- maybeEonInEra era + cOn <- forEraMaybeEon era pure $ subParser "constitution" $ Opt.info (GovernanceQueryConstitutionCmd cOn <$> pNoArgQueryCmd env) @@ -44,7 +44,7 @@ pGovernanceQueryGetGovStateCmd :: () -> EnvCli -> Maybe (Parser (GovernanceQueryCmds era)) pGovernanceQueryGetGovStateCmd era env = do - cOn <- maybeEonInEra era + cOn <- forEraMaybeEon era pure $ subParser "gov-state" $ Opt.info (GovernanceQueryGovStateCmd cOn <$> pNoArgQueryCmd env) @@ -60,7 +60,7 @@ pGovernanceQueryDRepStateCmd :: () -> EnvCli -> Maybe (Parser (GovernanceQueryCmds era)) pGovernanceQueryDRepStateCmd era env = do - cOn <- maybeEonInEra era + cOn <- forEraMaybeEon era pure $ subParser "drep-state" $ Opt.info (GovernanceQueryDRepStateCmd cOn <$> pDRepStateQueryCmd) @@ -79,7 +79,7 @@ pGovernanceQueryDRepStakeDistributionCmd :: () -> EnvCli -> Maybe (Parser (GovernanceQueryCmds era)) pGovernanceQueryDRepStakeDistributionCmd era env = do - cOn <- maybeEonInEra era + cOn <- forEraMaybeEon era pure $ subParser "drep-stake-distribution" $ Opt.info (GovernanceQueryDRepStakeDistributionCmd cOn <$> pDRepStakeDistributionQueryCmd) @@ -98,7 +98,7 @@ pGovernanceQueryGetCommitteeStateCmd :: () -> EnvCli -> Maybe (Parser (GovernanceQueryCmds era)) pGovernanceQueryGetCommitteeStateCmd era env = do - cOn <- maybeEonInEra era + cOn <- forEraMaybeEon era pure $ subParser "committee-state" $ Opt.info (GovernanceQueryCommitteeStateCmd cOn <$> pNoArgQueryCmd env) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Vote.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Vote.hs index a3c8b54658..4c286afbb4 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Vote.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Vote.hs @@ -32,7 +32,7 @@ pGovernanceVoteCreateCmd :: () => CardanoEra era -> Maybe (Parser (GovernanceVoteCmds era)) pGovernanceVoteCreateCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "create" $ Opt.info diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs index 309a243029..be0d1a6ec3 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/StakeAddress.hs @@ -39,7 +39,7 @@ pStakeAddressKeyGenCmd :: () => CardanoEra era -> Maybe (Parser (StakeAddressCmds era)) pStakeAddressKeyGenCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "key-gen" $ Opt.info @@ -54,7 +54,7 @@ pStakeAddressKeyHashCmd :: () => CardanoEra era -> Maybe (Parser (StakeAddressCmds era)) pStakeAddressKeyHashCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "key-hash" $ Opt.info @@ -69,7 +69,7 @@ pStakeAddressBuildCmd :: () -> EnvCli -> Maybe (Parser (StakeAddressCmds era)) pStakeAddressBuildCmd era envCli = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "build" $ Opt.info @@ -84,7 +84,7 @@ pStakeAddressRegistrationCertificateCmd :: () => CardanoEra era -> Maybe (Parser (StakeAddressCmds era)) pStakeAddressRegistrationCertificateCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "registration-certificate" $ Opt.info @@ -99,7 +99,7 @@ pStakeAddressDeregistrationCertificateCmd :: () => CardanoEra era -> Maybe (Parser (StakeAddressCmds era)) pStakeAddressDeregistrationCertificateCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "deregistration-certificate" $ Opt.info @@ -114,7 +114,7 @@ pStakeAddressStakeDelegationCertificateCmd :: () => CardanoEra era -> Maybe (Parser (StakeAddressCmds era)) pStakeAddressStakeDelegationCertificateCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "stake-delegation-certificate" $ Opt.info @@ -133,7 +133,7 @@ pStakeAddressStakeAndVoteDelegationCertificateCmd :: () => CardanoEra era -> Maybe (Parser (StakeAddressCmds era)) pStakeAddressStakeAndVoteDelegationCertificateCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "stake-and-vote-delegation-certificate" $ Opt.info @@ -153,7 +153,7 @@ pStakeAddressVoteDelegationCertificateCmd :: () => CardanoEra era -> Maybe (Parser (StakeAddressCmds era)) pStakeAddressVoteDelegationCertificateCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "vote-delegation-certificate" $ Opt.info diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/StakePool.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/StakePool.hs index 2a019776ce..7625a641e3 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/StakePool.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/StakePool.hs @@ -57,7 +57,7 @@ pStakePoolMetadataHashCmd = pStakePoolRegistrationCertificateCmd :: CardanoEra era -> EnvCli -> Maybe (Parser (StakePoolCmds era)) pStakePoolRegistrationCertificateCmd era envCli = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "registration-certificate" $ Opt.info @@ -78,7 +78,7 @@ pStakePoolRegistrationCertificateCmd era envCli = do pStakePoolDeregistrationCertificateCmd :: CardanoEra era -> Maybe (Parser (StakePoolCmds era)) pStakePoolDeregistrationCertificateCmd era = do - w <- maybeEonInEra era + w <- forEraMaybeEon era pure $ subParser "deregistration-certificate" $ Opt.info diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index dc6c0b9450..e40774de03 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -203,17 +203,15 @@ runTxBuildCmd let filteredTxinsc = Set.toList $ Set.fromList txinsc -- We need to construct the txBodycontent outside of runTxBuild - BalancedTxBody txBodycontent balancedTxBody _ _ <- + BalancedTxBody txBodyContent balancedTxBody _ _ <- runTxBuild era socketPath consensusModeParams nid mScriptValidity inputsAndMaybeScriptWits readOnlyRefIns filteredTxinsc mReturnCollateral mTotCollateral txOuts changeAddr valuesWithScriptWits mLowBound mUpperBound certsAndMaybeScriptWits withdrawalsAndMaybeScriptWits requiredSigners txAuxScripts txMetadata mProp mOverrideWits votes proposals outputOptions - mScriptWits <- - case cardanoEraStyle era of - LegacyByronEra -> return [] - ShelleyBasedEra sbe -> return $ collectTxBodyScriptWitnesses sbe txBodycontent + let mScriptWits = + forEraInEon era [] $ \sbe -> collectTxBodyScriptWitnesses sbe txBodyContent let allReferenceInputs = getAllReferenceInputs inputsAndMaybeScriptWits @@ -230,7 +228,7 @@ runTxBuildCmd -- the script cost vs having to build the tx body each time case outputOptions of OutputScriptCostOnly fp -> do - let BuildTxWith mTxProtocolParams = txProtocolParams txBodycontent + let BuildTxWith mTxProtocolParams = txProtocolParams txBodyContent pparams <- pure mTxProtocolParams & onNothing (left TxCmdProtocolParametersNotPresentInTxBody) executionUnitPrices <- pure (getExecutionUnitPrices era pparams) & onNothing (left TxCmdPParamExecutionUnitsNotAvailable) @@ -595,8 +593,8 @@ runTxBuild , txUpdateProposal = validatedTxUpProp , txMintValue = validatedMintValue , txScriptValidity = validatedTxScriptValidity - , txProposalProcedures = inEraEonMaybe era (`Featured` validatedTxProposalProcedures) - , txVotingProcedures = inEraEonMaybe era (`Featured` validatedTxVotes) + , txProposalProcedures = forEraInEonMaybe era (`Featured` validatedTxProposalProcedures) + , txVotingProcedures = forEraInEonMaybe era (`Featured` validatedTxVotes) } firstExceptT TxCmdTxInsDoNotExist @@ -661,21 +659,20 @@ validateTxInsCollateral :: CardanoEra era -> [TxIn] -> Either TxCmdError (TxInsCollateral era) validateTxInsCollateral _ [] = return TxInsCollateralNone -validateTxInsCollateral era txins = - case collateralSupportedInEra era of - Nothing -> txFeatureMismatchPure era TxFeatureCollateral - Just supported -> return (TxInsCollateral supported txins) +validateTxInsCollateral era txins = do + supported <- forEraMaybeEon era + & maybe (txFeatureMismatchPure era TxFeatureCollateral) Right + pure $ TxInsCollateral supported txins validateTxInsReference :: CardanoEra era -> [TxIn] -> Either TxCmdError (TxInsReference BuildTx era) validateTxInsReference _ [] = return TxInsReferenceNone -validateTxInsReference era allRefIns = - caseByronToAlonzoOrBabbageEraOnwards - (const $ txFeatureMismatchPure era TxFeatureReferenceInputs) - (\w -> return $ TxInsReference w allRefIns) - era +validateTxInsReference era allRefIns = do + supported <- forEraMaybeEon era + & maybe (txFeatureMismatchPure era TxFeatureReferenceInputs) Right + pure $ TxInsReference supported allRefIns getAllReferenceInputs :: [(TxIn, Maybe (ScriptWitness WitCtxTxIn era))] @@ -733,24 +730,6 @@ toTxOutValueInAnyEra era val = (\w -> return (TxOutValue w val)) era --- TODO move this to cardano-api -caseAlonzoOnlyOrBabbageEraOnwards :: () - => (AlonzoEraOnly era -> a) - -> (BabbageEraOnwards era -> a) - -> AlonzoEraOnwards era - -> a -caseAlonzoOnlyOrBabbageEraOnwards l r = \case - AlonzoEraOnwardsAlonzo -> l AlonzoEraOnlyAlonzo - AlonzoEraOnwardsBabbage -> r BabbageEraOnwardsBabbage - AlonzoEraOnwardsConway -> r BabbageEraOnwardsConway - --- TODO move this to cardano-api -alonzoEraOnlyToAlonzoEraOnwards :: () - => AlonzoEraOnly era - -> AlonzoEraOnwards era -alonzoEraOnlyToAlonzoEraOnwards = \case - AlonzoEraOnlyAlonzo -> AlonzoEraOnwardsAlonzo - toTxOutInAnyEra :: CardanoEra era -> TxOutAnyEra -> ExceptT TxCmdError IO (TxOut CtxTx era) diff --git a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs index 4036bb1084..e2f316119a 100644 --- a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs +++ b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs @@ -128,7 +128,7 @@ pattern ShelleyTtl :: SlotNo -> (TxValidityLowerBound era, TxValidityUpperBound era) pattern ShelleyTtl ttl <- ( TxValidityNoLowerBound - , TxValidityUpperBound ValidityUpperBoundInShelleyEra ttl + , TxValidityUpperBound _ ttl ) friendlyValidityRange @@ -151,8 +151,8 @@ friendlyValidityRange era = \case ] | otherwise -> Null where - isLowerBoundSupported = isJust $ validityLowerBoundSupportedInEra era - isUpperBoundSupported = isJust $ validityUpperBoundSupportedInEra era + isLowerBoundSupported = isJust $ inEonForEraMaybe TxValidityLowerBound era + isUpperBoundSupported = isJust $ inEonForEraMaybe TxValidityUpperBound era friendlyWithdrawals :: TxWithdrawals ViewTx era -> Aeson.Value friendlyWithdrawals TxWithdrawalsNone = Null diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs b/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs index f992246456..de02b24a27 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs @@ -14,18 +14,18 @@ import Data.Text (Text) data LegacyGovernanceCmds = GovernanceMIRPayStakeAddressesCertificate - AnyShelleyToBabbageEra + (AnyEraInEon ShelleyToBabbageEra) MIRPot [StakeAddress] [Lovelace] (File () Out) | GovernanceMIRTransfer - AnyShelleyToBabbageEra + (AnyEraInEon ShelleyToBabbageEra) Lovelace (File () Out) TransferDirection | GovernanceGenesisKeyDelegationCertificate - AnyShelleyBasedEra + (AnyEraInEon ShelleyBasedEra) (VerificationKeyOrHashOrFile GenesisKey) (VerificationKeyOrHashOrFile GenesisDelegateKey) (VerificationKeyOrHashOrFile VrfKey) diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Commands/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/Legacy/Commands/StakeAddress.hs index 00d33d86be..f5b665f3bc 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Commands/StakeAddress.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Commands/StakeAddress.hs @@ -29,17 +29,17 @@ data LegacyStakeAddressCmds NetworkId (Maybe (File () Out)) | StakeAddressRegistrationCertificateCmd - AnyShelleyBasedEra + (AnyEraInEon ShelleyBasedEra) StakeIdentifier (Maybe Lovelace) (File () Out) | StakeAddressDelegationCertificateCmd - AnyShelleyBasedEra + (AnyEraInEon ShelleyBasedEra) StakeIdentifier (VerificationKeyOrHashOrFile StakePoolKey) (File () Out) | StakeAddressDeregistrationCertificateCmd - AnyShelleyBasedEra + (AnyEraInEon ShelleyBasedEra) StakeIdentifier (Maybe Lovelace) (File () Out) diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Commands/StakePool.hs b/cardano-cli/src/Cardano/CLI/Legacy/Commands/StakePool.hs index 9824f098cb..453176cef4 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Commands/StakePool.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Commands/StakePool.hs @@ -17,7 +17,7 @@ import Data.Text (Text) data LegacyStakePoolCmds = StakePoolDeregistrationCertificateCmd - AnyShelleyBasedEra + (AnyEraInEon ShelleyBasedEra) -- ^ Era in which to retire the stake pool. (VerificationKeyOrFile StakePoolKey) -- ^ Stake pool verification key. @@ -32,7 +32,7 @@ data LegacyStakePoolCmds (StakePoolMetadataFile In) (Maybe (File () Out)) | StakePoolRegistrationCertificateCmd - AnyShelleyBasedEra + (AnyEraInEon ShelleyBasedEra) -- ^ Era in which to register the stake pool. (VerificationKeyOrFile StakePoolKey) -- ^ Stake pool verification key. diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Options.hs b/cardano-cli/src/Cardano/CLI/Legacy/Options.hs index f27e4d78fa..5ea8b4df51 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Options.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Options.hs @@ -1463,5 +1463,6 @@ pLegacyCardanoEra envCli = , pure $ pure defaultCardanoEra ] where - defaultCardanoEra = defaultShelleyBasedEra & \(AnyShelleyBasedEra era) -> - AnyCardanoEra (shelleyBasedToCardanoEra era) + defaultCardanoEra = defaultShelleyBasedEra & \(AnyEraInEon era) -> + let cera = toCardanoEra era + in cardanoEraConstraints cera (AnyCardanoEra cera) diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Run/Governance.hs b/cardano-cli/src/Cardano/CLI/Legacy/Run/Governance.hs index 7e4f1e05a7..21e896cf31 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Run/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Run/Governance.hs @@ -56,32 +56,32 @@ runLegacyGovernanceCmds = \case runLegacyGovernanceVerifyPoll poll metadata mOutFile runLegacyGovernanceMIRCertificatePayStakeAddrs - :: AnyShelleyToBabbageEra + :: AnyEraInEon ShelleyToBabbageEra -> Ledger.MIRPot -> [StakeAddress] -- ^ Stake addresses -> [Lovelace] -- ^ Corresponding reward amounts (same length) -> File () Out -> ExceptT GovernanceCmdError IO () -runLegacyGovernanceMIRCertificatePayStakeAddrs (AnyShelleyToBabbageEra w) = +runLegacyGovernanceMIRCertificatePayStakeAddrs (AnyEraInEon w) = runGovernanceMIRCertificatePayStakeAddrs w runLegacyGovernanceMIRCertificateTransfer - :: AnyShelleyToBabbageEra + :: AnyEraInEon ShelleyToBabbageEra -> Lovelace -> File () Out -> TransferDirection -> ExceptT GovernanceCmdError IO () -runLegacyGovernanceMIRCertificateTransfer (AnyShelleyToBabbageEra w) = +runLegacyGovernanceMIRCertificateTransfer (AnyEraInEon w) = runGovernanceMIRCertificateTransfer w runLegacyGovernanceGenesisKeyDelegationCertificate - :: AnyShelleyBasedEra + :: AnyEraInEon ShelleyBasedEra -> VerificationKeyOrHashOrFile GenesisKey -> VerificationKeyOrHashOrFile GenesisDelegateKey -> VerificationKeyOrHashOrFile VrfKey -> File () Out -> ExceptT GovernanceCmdError IO () -runLegacyGovernanceGenesisKeyDelegationCertificate (AnyShelleyBasedEra sbe) +runLegacyGovernanceGenesisKeyDelegationCertificate (AnyEraInEon sbe) genVkOrHashOrFp genDelVkOrHashOrFp vrfVkOrHashOrFp @@ -102,6 +102,7 @@ runLegacyGovernanceGenesisKeyDelegationCertificate (AnyShelleyBasedEra sbe) firstExceptT GovernanceCmdTextEnvWriteError . newExceptT $ writeLazyByteStringFile oFp + $ shelleyBasedEraConstraints sbe $ textEnvelopeToJSON (Just genKeyDelegCertDesc) genKeyDelegCert where genKeyDelegCertDesc :: TextEnvelopeDescr diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Run/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/Legacy/Run/StakeAddress.hs index c537e57ee2..a1e06d244c 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Run/StakeAddress.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Run/StakeAddress.hs @@ -57,16 +57,16 @@ runLegacyStakeAddressBuildCmd = runStakeAddressBuildCmd runLegacyStakeAddressRegistrationCertificateCmd :: () - => AnyShelleyBasedEra + => AnyEraInEon ShelleyBasedEra -> StakeIdentifier -> Maybe Lovelace -- ^ Deposit required in conway era -> File () Out -> ExceptT StakeAddressCmdError IO () -runLegacyStakeAddressRegistrationCertificateCmd (AnyShelleyBasedEra sbe) = +runLegacyStakeAddressRegistrationCertificateCmd (AnyEraInEon sbe) = runStakeAddressRegistrationCertificateCmd sbe runLegacyStakeAddresslDelegationCertificateCmd :: () - => AnyShelleyBasedEra + => AnyEraInEon ShelleyBasedEra -> StakeIdentifier -- ^ Delegator stake verification key, verification key file or script file. -> VerificationKeyOrHashOrFile StakePoolKey @@ -74,14 +74,14 @@ runLegacyStakeAddresslDelegationCertificateCmd :: () -- verification key hash. -> File () Out -> ExceptT StakeAddressCmdError IO () -runLegacyStakeAddresslDelegationCertificateCmd (AnyShelleyBasedEra sbe) = +runLegacyStakeAddresslDelegationCertificateCmd (AnyEraInEon sbe) = runStakeAddressStakeDelegationCertificateCmd sbe runLegacyStakeAddressDeregistrationCertificateCmd :: () - => AnyShelleyBasedEra + => AnyEraInEon ShelleyBasedEra -> StakeIdentifier -> Maybe Lovelace -- ^ Deposit required in conway era -> File () Out -> ExceptT StakeAddressCmdError IO () -runLegacyStakeAddressDeregistrationCertificateCmd (AnyShelleyBasedEra sbe) = +runLegacyStakeAddressDeregistrationCertificateCmd (AnyEraInEon sbe) = runStakeAddressDeregistrationCertificateCmd sbe diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Run/StakePool.hs b/cardano-cli/src/Cardano/CLI/Legacy/Run/StakePool.hs index 61044cdf3f..841113972a 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Run/StakePool.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Run/StakePool.hs @@ -35,7 +35,7 @@ runLegacyStakePoolCmds = \case -- TODO: Metadata and more stake pool relay support to be -- added in the future. runLegacyStakePoolRegistrationCertificateCmd :: () - => AnyShelleyBasedEra + => AnyEraInEon ShelleyBasedEra -> VerificationKeyOrFile StakePoolKey -- ^ Stake pool verification key. -> VerificationKeyOrFile VrfKey @@ -58,17 +58,17 @@ runLegacyStakePoolRegistrationCertificateCmd :: () -> File () Out -> ExceptT StakePoolCmdError IO () runLegacyStakePoolRegistrationCertificateCmd = \case - AnyShelleyBasedEra sbe -> + AnyEraInEon sbe -> runStakePoolRegistrationCertificateCmd sbe runLegacyStakePoolDeregistrationCertificateCmd :: () - => AnyShelleyBasedEra + => AnyEraInEon ShelleyBasedEra -> VerificationKeyOrFile StakePoolKey -> Shelley.EpochNo -> File () Out -> ExceptT StakePoolCmdError IO () runLegacyStakePoolDeregistrationCertificateCmd = \case - AnyShelleyBasedEra sbe -> + AnyEraInEon sbe -> runStakePoolRetirementCertificateCmd sbe runLegacyStakePoolIdCmd :: () diff --git a/cardano-cli/src/Cardano/CLI/Read.hs b/cardano-cli/src/Cardano/CLI/Read.hs index 65e186e8ed..ca5491fc8f 100644 --- a/cardano-cli/src/Cardano/CLI/Read.hs +++ b/cardano-cli/src/Cardano/CLI/Read.hs @@ -176,7 +176,7 @@ readTxMetadata :: CardanoEra era -> IO (Either MetadataError (TxMetadataInEra era)) readTxMetadata _ _ [] = return $ Right TxMetadataNone readTxMetadata era schema files = cardanoEraConstraints era $ runExceptT $ do - supported <- maybeEonInEra era + supported <- forEraMaybeEon era & hoistMaybe (MetadataErrorNotAvailableInEra $ AnyCardanoEra era) metadata <- mapM (readFileTxMetadata schema) files pure $ TxMetadataInEra supported $ mconcat metadata @@ -796,7 +796,7 @@ readTxGovernanceActions -> IO (Either ConstitutionError [Proposal era]) readTxGovernanceActions _ [] = return $ Right [] readTxGovernanceActions era files = runExceptT $ do - w <- maybeEonInEra era + w <- forEraMaybeEon era & hoistMaybe (ConstitutionNotSupportedInEra $ cardanoEraConstraints era $ AnyCardanoEra era) newExceptT $ sequence <$> mapM (readProposal w) files diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressDelegationError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressDelegationError.hs index 8de937f6b0..cc5ab81f7e 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressDelegationError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/StakeAddressDelegationError.hs @@ -1,6 +1,5 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeApplications #-} module Cardano.CLI.Types.Errors.StakeAddressDelegationError ( StakeAddressDelegationError(..) @@ -10,12 +9,11 @@ import Cardano.Api import qualified Data.Text as Text -newtype StakeAddressDelegationError = VoteDelegationNotSupported AnyShelleyToBabbageEra deriving Show +newtype StakeAddressDelegationError = VoteDelegationNotSupported (AnyEraInEon ShelleyToBabbageEra) deriving Show instance Error StakeAddressDelegationError where displayError = \case - VoteDelegationNotSupported (AnyShelleyToBabbageEra stbe) -> "Vote delegation not supported in " <> eraTxt stbe <> " era." + VoteDelegationNotSupported (AnyEraInEon eraInEon) -> "Vote delegation not supported in " <> eraTxt <> " era." where - eraTxt :: forall era. ShelleyToBabbageEra era -> String - eraTxt stbe' = shelleyToBabbageEraConstraints stbe' $ - Text.unpack . renderEra $ AnyCardanoEra (cardanoEra @era) + cEra = toCardanoEra eraInEon + eraTxt = cardanoEraConstraints cEra $ Text.unpack . renderEra $ AnyCardanoEra cEra diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs index 068a634b45..952870dfe9 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs @@ -6,6 +6,7 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeApplications #-} module Cardano.CLI.Types.Errors.TxValidationError ( TxAuxScriptsValidationError(..) @@ -41,7 +42,6 @@ import Cardano.Api.Shelley import Prelude import Data.Bifunctor (first) -import Data.Function import qualified Data.Map.Strict as Map import Data.Maybe import qualified Data.Text as Text @@ -104,12 +104,9 @@ validateTxTotalCollateral :: CardanoEra era -> Maybe Lovelace -> Either TxTotalCollateralValidationError (TxTotalCollateral era) validateTxTotalCollateral _ Nothing = return TxTotalCollateralNone -validateTxTotalCollateral era (Just coll) = - case totalAndReturnCollateralSupportedInEra era of - Just supp -> return $ TxTotalCollateral supp coll - Nothing -> Left $ TxTotalCollateralNotSupported - $ cardanoEraConstraints era - $ AnyCardanoEra era +validateTxTotalCollateral era (Just coll) = do + supported <- conjureWitness era TxTotalCollateralNotSupported + pure $ TxTotalCollateral supported coll newtype TxReturnCollateralValidationError = TxReturnCollateralNotSupported AnyCardanoEra @@ -124,11 +121,8 @@ validateTxReturnCollateral :: CardanoEra era -> Either TxReturnCollateralValidationError (TxReturnCollateral CtxTx era) validateTxReturnCollateral _ Nothing = return TxReturnCollateralNone validateTxReturnCollateral era (Just retColTxOut) = do - case totalAndReturnCollateralSupportedInEra era of - Just supp -> return $ TxReturnCollateral supp retColTxOut - Nothing -> Left $ TxReturnCollateralNotSupported - $ cardanoEraConstraints era - $ AnyCardanoEra era + supported <- conjureWitness era TxReturnCollateralNotSupported + pure $ TxReturnCollateral supported retColTxOut newtype TxValidityLowerBoundValidationError = TxValidityLowerBoundNotSupported AnyCardanoEra @@ -143,12 +137,9 @@ validateTxValidityLowerBound :: CardanoEra era -> Maybe SlotNo -> Either TxValidityLowerBoundValidationError (TxValidityLowerBound era) validateTxValidityLowerBound _ Nothing = return TxValidityNoLowerBound -validateTxValidityLowerBound era (Just slot) = - case validityLowerBoundSupportedInEra era of - Nothing -> Left $ TxValidityLowerBoundNotSupported - $ cardanoEraConstraints era - $ AnyCardanoEra era - Just supported -> return (TxValidityLowerBound supported slot) +validateTxValidityLowerBound era (Just slot) = do + supported <- conjureWitness era TxValidityLowerBoundNotSupported + pure $ TxValidityLowerBound supported slot newtype TxValidityUpperBoundValidationError = TxValidityUpperBoundNotSupported AnyCardanoEra @@ -162,18 +153,13 @@ validateTxValidityUpperBound :: CardanoEra era -> Maybe SlotNo -> Either TxValidityUpperBoundValidationError (TxValidityUpperBound era) -validateTxValidityUpperBound era Nothing = - case validityNoUpperBoundSupportedInEra era of - Nothing -> Left $ TxValidityUpperBoundNotSupported - $ cardanoEraConstraints era - $ AnyCardanoEra era - Just supported -> return (TxValidityNoUpperBound supported) -validateTxValidityUpperBound era (Just slot) = - case validityUpperBoundSupportedInEra era of - Nothing -> Left $ TxValidityUpperBoundNotSupported - $ cardanoEraConstraints era - $ AnyCardanoEra era - Just supported -> return (TxValidityUpperBound supported slot) +validateTxValidityUpperBound era = \case + Just slot -> do + supported <- conjureWitness era TxValidityUpperBoundNotSupported + pure $ TxValidityUpperBound supported slot + Nothing -> do + supported <- conjureWitness era TxValidityUpperBoundNotSupported + pure $ TxValidityNoUpperBound supported data TxAuxScriptsValidationError = TxAuxScriptsNotSupportedInEra AnyCardanoEra @@ -191,14 +177,10 @@ validateTxAuxScripts -> [ScriptInAnyLang] -> Either TxAuxScriptsValidationError (TxAuxScripts era) validateTxAuxScripts _ [] = return TxAuxScriptsNone -validateTxAuxScripts era scripts = - case auxScriptsSupportedInEra era of - Nothing -> Left $ TxAuxScriptsNotSupportedInEra - $ cardanoEraConstraints era - $ AnyCardanoEra era - Just supported -> do - scriptsInEra <- mapM (first TxAuxScriptsLanguageError . validateScriptSupportedInEra era) scripts - return $ TxAuxScripts supported scriptsInEra +validateTxAuxScripts era scripts = do + supported <- conjureWitness era TxAuxScriptsNotSupportedInEra + scriptsInEra <- mapM (first TxAuxScriptsLanguageError . validateScriptSupportedInEra era) scripts + pure $ TxAuxScripts supported scriptsInEra newtype TxRequiredSignersValidationError = TxRequiredSignersValidationError AnyCardanoEra @@ -213,12 +195,9 @@ validateRequiredSigners -> [Hash PaymentKey] -> Either TxRequiredSignersValidationError (TxExtraKeyWitnesses era) validateRequiredSigners _ [] = return TxExtraKeyWitnessesNone -validateRequiredSigners era reqSigs = - case extraKeyWitnessesSupportedInEra era of - Nothing -> Left $ TxRequiredSignersValidationError - $ cardanoEraConstraints era - $ AnyCardanoEra era - Just supported -> return $ TxExtraKeyWitnesses supported reqSigs +validateRequiredSigners era reqSigs = do + supported <- conjureWitness era TxRequiredSignersValidationError + pure $ TxExtraKeyWitnesses supported reqSigs newtype TxWithdrawalsValidationError = TxWithdrawalsNotSupported AnyCardanoEra @@ -235,8 +214,7 @@ validateTxWithdrawals -> Either TxWithdrawalsValidationError (TxWithdrawals BuildTx era) validateTxWithdrawals _ [] = return TxWithdrawalsNone validateTxWithdrawals era withdrawals = do - supported <- maybeEonInEra era - & maybe (cardanoEraConstraints era $ Left . TxWithdrawalsNotSupported $ AnyCardanoEra era) Right + supported <- conjureWitness era TxWithdrawalsNotSupported let convWithdrawals = map convert withdrawals pure $ TxWithdrawals supported convWithdrawals where @@ -264,8 +242,7 @@ validateTxCertificates -> Either TxCertificatesValidationError (TxCertificates BuildTx era) validateTxCertificates _ [] = return TxCertificatesNone validateTxCertificates era certsAndScriptWitnesses = cardanoEraConstraints era $ do - supported <- maybeEonInEra era - & maybe (Left . TxCertificatesValidationNotSupported $ AnyCardanoEra era) Right + supported <- conjureWitness era TxCertificatesValidationNotSupported let certs = map fst certsAndScriptWitnesses reqWits = Map.fromList $ mapMaybe convert certsAndScriptWitnesses pure $ TxCertificates supported certs $ BuildTxWith reqWits @@ -308,12 +285,9 @@ validateProtocolParameters -> Maybe (LedgerProtocolParameters era) -> Either TxProtocolParametersValidationError (BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))) validateProtocolParameters _ Nothing = return (BuildTxWith Nothing) -validateProtocolParameters era (Just pparams) = - case cardanoEraStyle era of - LegacyByronEra -> Left $ ProtocolParametersNotSupported - $ cardanoEraConstraints era - $ AnyCardanoEra era - ShelleyBasedEra _ -> return . BuildTxWith $ Just pparams +validateProtocolParameters era (Just pparams) = do + _ <- conjureWitness @ShelleyBasedEra era ProtocolParametersNotSupported + pure . BuildTxWith $ Just pparams newtype TxUpdateProposalValidationError = TxUpdateProposalNotSupported AnyCardanoEra @@ -329,8 +303,7 @@ validateTxUpdateProposal -> Either TxUpdateProposalValidationError (TxUpdateProposal era) validateTxUpdateProposal _ Nothing = return TxUpdateProposalNone validateTxUpdateProposal era (Just prop) = do - supported <- maybeEonInEra era - & maybe (cardanoEraConstraints era $ Left . TxUpdateProposalNotSupported $ AnyCardanoEra era) Right + supported <- conjureWitness era TxUpdateProposalNotSupported pure $ TxUpdateProposal supported prop newtype TxScriptValidityValidationError @@ -346,9 +319,15 @@ validateTxScriptValidity -> Maybe ScriptValidity -> Either TxScriptValidityValidationError (TxScriptValidity era) validateTxScriptValidity _ Nothing = pure TxScriptValidityNone -validateTxScriptValidity era (Just scriptValidity) = - case txScriptValiditySupportedInCardanoEra era of - Nothing -> Left $ ScriptValidityNotSupported - $ cardanoEraConstraints era - $ AnyCardanoEra era - Just supported -> pure $ TxScriptValidity supported scriptValidity +validateTxScriptValidity era (Just scriptValidity) = do + supported <- conjureWitness era ScriptValidityNotSupported + pure $ TxScriptValidity supported scriptValidity + + +conjureWitness :: Eon eon + => CardanoEra era -- ^ era to try to conjure eon from + -> (AnyCardanoEra -> e) -- ^ error wrapper function + -> Either e (eon era) -- ^ eon if it includes the era, an error otherwise +conjureWitness era errF = + maybe (cardanoEraConstraints era $ Left . errF $ AnyCardanoEra era) Right $ + forEraMaybeEon era