From e19a0e21ab14f105ada95ff0c0d042c7bb03d14b Mon Sep 17 00:00:00 2001 From: John Ky Date: Wed, 4 Oct 2023 23:42:54 +1100 Subject: [PATCH] Delete withShelleyBasedEraConstraintsForLedger. Use shelleyBasedEraConstraints instead --- cardano-api/internal/Cardano/Api/Eras.hs | 2 -- .../internal/Cardano/Api/Eras/Constraints.hs | 11 ----------- cardano-api/internal/Cardano/Api/Fees.hs | 9 +++++---- .../Api/Governance/Actions/ProposalProcedure.hs | 13 ++++++------- cardano-api/internal/Cardano/Api/LedgerState.hs | 2 +- cardano-api/internal/Cardano/Api/TxBody.hs | 8 ++++---- cardano-api/src/Cardano/Api.hs | 1 - 7 files changed, 16 insertions(+), 30 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/Eras.hs b/cardano-api/internal/Cardano/Api/Eras.hs index d4380435a5..0788156076 100644 --- a/cardano-api/internal/Cardano/Api/Eras.hs +++ b/cardano-api/internal/Cardano/Api/Eras.hs @@ -33,8 +33,6 @@ module Cardano.Api.Eras -- * Data family instances , AsType(AsByronEra, AsShelleyEra, AsAllegraEra, AsMaryEra, AsAlonzoEra, AsBabbageEra, AsConwayEra) - , withShelleyBasedEraConstraintsForLedger - -- * Era case handling -- ** Case on CardanoEra diff --git a/cardano-api/internal/Cardano/Api/Eras/Constraints.hs b/cardano-api/internal/Cardano/Api/Eras/Constraints.hs index 910908a891..56d2ec59fa 100644 --- a/cardano-api/internal/Cardano/Api/Eras/Constraints.hs +++ b/cardano-api/internal/Cardano/Api/Eras/Constraints.hs @@ -10,7 +10,6 @@ module Cardano.Api.Eras.Constraints ( cardanoEraConstraints - , withShelleyBasedEraConstraintsForLedger , shelleyBasedEraConstraints , CardanoEraConstraints @@ -21,7 +20,6 @@ import Cardano.Api.Eon.ShelleyBasedEra import Cardano.Api.Eras.Core import Cardano.Api.Modes import Cardano.Api.Orphans () -import Cardano.Api.Query.Types import qualified Cardano.Crypto.Hash.Blake2b as Blake2b import qualified Cardano.Crypto.Hash.Class as C @@ -72,11 +70,9 @@ type ShelleyBasedEraConstraints era = , L.ShelleyEraTxBody (ShelleyLedgerEra era) , L.ShelleyEraTxCert (ShelleyLedgerEra era) , FromCBOR (Consensus.ChainDepState (ConsensusProtocol era)) - , FromCBOR (DebugLedgerState era) , IsCardanoEra era , IsShelleyBasedEra era , ToJSON (Consensus.ChainDepState (ConsensusProtocol era)) - , ToJSON (DebugLedgerState era) , Typeable era ) @@ -91,10 +87,3 @@ shelleyBasedEraConstraints = \case ShelleyBasedEraAlonzo -> id ShelleyBasedEraBabbage -> id ShelleyBasedEraConway -> id - --- Deprecated: Use shelleyBasedEraConstraints instead. -withShelleyBasedEraConstraintsForLedger :: () - => ShelleyBasedEra era - -> (ShelleyBasedEraConstraints era => a) - -> a -withShelleyBasedEraConstraintsForLedger = shelleyBasedEraConstraints diff --git a/cardano-api/internal/Cardano/Api/Fees.hs b/cardano-api/internal/Cardano/Api/Fees.hs index b0cdd7bc98..a7f3c36408 100644 --- a/cardano-api/internal/Cardano/Api/Fees.hs +++ b/cardano-api/internal/Cardano/Api/Fees.hs @@ -4,6 +4,7 @@ {-# LANGUAGE EmptyCase #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -119,7 +120,7 @@ transactionFee txFeeFixed txFeePerByte tx = b = toInteger txFeeFixed in case tx of ShelleyTx _ tx' -> - let x = withShelleyBasedEraConstraintsForLedger (shelleyBasedEra @era) $ tx' ^. L.sizeTxF + let x = shelleyBasedEraConstraints (shelleyBasedEra @era) $ tx' ^. L.sizeTxF in Lovelace (a * x + b) --TODO: This can be made to work for Byron txs too. Do that: fill in this case -- and remove the IsShelleyBasedEra constraint. @@ -224,7 +225,7 @@ evaluateTransactionFee pp txbody keywitcount _byronwitcount = ByronTx{} -> case shelleyBasedEra :: ShelleyBasedEra era of {} --TODO: we could actually support Byron here, it'd be different but simpler - ShelleyTx sbe tx -> withShelleyBasedEraConstraintsForLedger sbe (evalShelleyBasedEra tx) + ShelleyTx sbe tx -> shelleyBasedEraConstraints sbe (evalShelleyBasedEra tx) where evalShelleyBasedEra :: forall ledgerera. ShelleyLedgerEra era ~ ledgerera @@ -522,8 +523,8 @@ evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo (LedgerProtoc fromAlonzoScriptExecutionError :: L.TransactionScriptFailure (ShelleyLedgerEra era) -> ScriptExecutionError - fromAlonzoScriptExecutionError failure = withShelleyBasedEraConstraintsForLedger sbe $ - case failure of + fromAlonzoScriptExecutionError = + shelleyBasedEraConstraints sbe $ \case L.UnknownTxIn txin -> ScriptErrorMissingTxIn txin' where txin' = fromShelleyTxIn txin L.InvalidTxIn txin -> ScriptErrorTxInWithoutDatum txin' diff --git a/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs b/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs index cb456e8d9b..e643c1780c 100644 --- a/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs +++ b/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs @@ -14,7 +14,6 @@ module Cardano.Api.Governance.Actions.ProposalProcedure where import Cardano.Api.Address import Cardano.Api.Eon.ShelleyBasedEra -import Cardano.Api.Eras import Cardano.Api.Eras.Constraints import Cardano.Api.HasTypeProxy import Cardano.Api.Keys.Shelley @@ -133,21 +132,21 @@ newtype Proposal era = Proposal { unProposal :: Gov.ProposalProcedure (ShelleyLe instance IsShelleyBasedEra era => Show (Proposal era) where show (Proposal pp) = do - let ppStr = withShelleyBasedEraConstraintsForLedger (shelleyBasedEra @era) $ show pp + let ppStr = shelleyBasedEraConstraints (shelleyBasedEra @era) $ show pp "Proposal {unProposal = " <> ppStr <> "}" instance IsShelleyBasedEra era => Eq (Proposal era) where - (Proposal pp1) == (Proposal pp2) = withShelleyBasedEraConstraintsForLedger (shelleyBasedEra @era) $ pp1 == pp2 + (Proposal pp1) == (Proposal pp2) = shelleyBasedEraConstraints (shelleyBasedEra @era) $ pp1 == pp2 instance IsShelleyBasedEra era => ToCBOR (Proposal era) where - toCBOR (Proposal vp) = withShelleyBasedEraConstraintsForLedger (shelleyBasedEra @era) $ Shelley.toEraCBOR @Conway.Conway vp + toCBOR (Proposal vp) = shelleyBasedEraConstraints (shelleyBasedEra @era) $ Shelley.toEraCBOR @Conway.Conway vp instance IsShelleyBasedEra era => FromCBOR (Proposal era) where - fromCBOR = Proposal <$> withShelleyBasedEraConstraintsForLedger (shelleyBasedEra @era) (Shelley.fromEraCBOR @Conway.Conway) + fromCBOR = Proposal <$> shelleyBasedEraConstraints (shelleyBasedEra @era) (Shelley.fromEraCBOR @Conway.Conway) instance IsShelleyBasedEra era => SerialiseAsCBOR (Proposal era) where - serialiseToCBOR = withShelleyBasedEraConstraintsForLedger (shelleyBasedEra @era) CBOR.serialize' - deserialiseFromCBOR _proxy = withShelleyBasedEraConstraintsForLedger (shelleyBasedEra @era) CBOR.decodeFull' + serialiseToCBOR = shelleyBasedEraConstraints (shelleyBasedEra @era) CBOR.serialize' + deserialiseFromCBOR _proxy = shelleyBasedEraConstraints (shelleyBasedEra @era) CBOR.decodeFull' instance IsShelleyBasedEra era => HasTextEnvelope (Proposal era) where textEnvelopeType _ = "Governance proposal" diff --git a/cardano-api/internal/Cardano/Api/LedgerState.hs b/cardano-api/internal/Cardano/Api/LedgerState.hs index be11c712d5..663fff7045 100644 --- a/cardano-api/internal/Cardano/Api/LedgerState.hs +++ b/cardano-api/internal/Cardano/Api/LedgerState.hs @@ -1502,7 +1502,7 @@ nextEpochEligibleLeadershipSlots sbe sGen serCurrEpochState ptclState poolid (Vr decodeCurrentEpochState sbe serCurrEpochState let snapshot :: ShelleyAPI.SnapShot Shelley.StandardCrypto - snapshot = ShelleyAPI.ssStakeMark $ withShelleyBasedEraConstraintsForLedger sbe $ ShelleyAPI.esSnapshots cEstate + snapshot = ShelleyAPI.ssStakeMark $ shelleyBasedEraConstraints sbe $ ShelleyAPI.esSnapshots cEstate markSnapshotPoolDistr :: Map (SL.KeyHash 'SL.StakePool Shelley.StandardCrypto) (SL.IndividualPoolStake Shelley.StandardCrypto) markSnapshotPoolDistr = ShelleyAPI.unPoolDistr . ShelleyAPI.calculatePoolDistr $ snapshot diff --git a/cardano-api/internal/Cardano/Api/TxBody.hs b/cardano-api/internal/Cardano/Api/TxBody.hs index 7226b1e224..1cdc530f7f 100644 --- a/cardano-api/internal/Cardano/Api/TxBody.hs +++ b/cardano-api/internal/Cardano/Api/TxBody.hs @@ -1806,7 +1806,7 @@ getTxId (ByronTxBody tx) = error "getTxId: byron and shelley hash sizes do not match" getTxId (ShelleyTxBody sbe tx _ _ _ _) = - withShelleyBasedEraConstraintsForLedger sbe $ getTxIdShelley sbe tx + shelleyBasedEraConstraints sbe $ getTxIdShelley sbe tx getTxIdShelley :: Ledger.EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto @@ -1993,7 +1993,7 @@ createTransactionBody sbe txBodyContent = case sData of TxBodyNoScriptData -> pure SNothing TxBodyScriptData _sDataSupported datums redeemers -> - withShelleyBasedEraConstraintsForLedger sbe + shelleyBasedEraConstraints sbe $ convPParamsToScriptIntegrityHash sbe apiProtocolParameters @@ -2027,7 +2027,7 @@ createTransactionBody sbe txBodyContent = case sData of TxBodyNoScriptData -> pure SNothing TxBodyScriptData _sDataSupported datums redeemers -> - withShelleyBasedEraConstraintsForLedger sbe + shelleyBasedEraConstraints sbe $ convPParamsToScriptIntegrityHash sbe apiProtocolParameters @@ -2729,7 +2729,7 @@ convReturnCollateral convReturnCollateral sbe txReturnCollateral = case txReturnCollateral of TxReturnCollateralNone -> SNothing - TxReturnCollateral _ colTxOut -> SJust $ withShelleyBasedEraConstraintsForLedger sbe $ toShelleyTxOutAny sbe colTxOut + TxReturnCollateral _ colTxOut -> SJust $ shelleyBasedEraConstraints sbe $ toShelleyTxOutAny sbe colTxOut convTotalCollateral :: TxTotalCollateral era -> StrictMaybe Ledger.Coin convTotalCollateral txTotalCollateral = diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index 5dcdbe1200..adb18f6310 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -106,7 +106,6 @@ module Cardano.Api ( cardanoEraStyle, shelleyBasedToCardanoEra, shelleyBasedEraConstraints, - withShelleyBasedEraConstraintsForLedger, -- ** From Allegra