Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete withShelleyBasedEraConstraintsForLedger #297

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cardano-api/internal/Cardano/Api/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions cardano-api/internal/Cardano/Api/Eras/Constraints.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

module Cardano.Api.Eras.Constraints
( cardanoEraConstraints
, withShelleyBasedEraConstraintsForLedger
, shelleyBasedEraConstraints

, CardanoEraConstraints
Expand All @@ -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
Expand Down Expand Up @@ -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
)

Expand All @@ -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
9 changes: 5 additions & 4 deletions cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cardano-api/internal/Cardano/Api/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions cardano-api/internal/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1993,7 +1993,7 @@ createTransactionBody sbe txBodyContent =
case sData of
TxBodyNoScriptData -> pure SNothing
TxBodyScriptData _sDataSupported datums redeemers ->
withShelleyBasedEraConstraintsForLedger sbe
shelleyBasedEraConstraints sbe
$ convPParamsToScriptIntegrityHash
sbe
apiProtocolParameters
Expand Down Expand Up @@ -2027,7 +2027,7 @@ createTransactionBody sbe txBodyContent =
case sData of
TxBodyNoScriptData -> pure SNothing
TxBodyScriptData _sDataSupported datums redeemers ->
withShelleyBasedEraConstraintsForLedger sbe
shelleyBasedEraConstraints sbe
$ convPParamsToScriptIntegrityHash
sbe
apiProtocolParameters
Expand Down Expand Up @@ -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 =
Expand Down
1 change: 0 additions & 1 deletion cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ module Cardano.Api (
cardanoEraStyle,
shelleyBasedToCardanoEra,
shelleyBasedEraConstraints,
withShelleyBasedEraConstraintsForLedger,

-- ** From Allegra

Expand Down