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

Remove LedgerPParams #219

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 6 additions & 6 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -939,12 +939,12 @@ genProtocolParameters era = do
genValidProtocolParameters :: ShelleyBasedEra era -> Gen (LedgerProtocolParameters era)
genValidProtocolParameters era =
case era of
ShelleyBasedEraShelley -> LedgerPParams era <$> Q.arbitrary
ShelleyBasedEraAllegra -> LedgerPParams era <$> Q.arbitrary
ShelleyBasedEraMary -> LedgerPParams era <$> Q.arbitrary
ShelleyBasedEraAlonzo -> LedgerPParams era <$> Q.arbitrary
ShelleyBasedEraBabbage -> LedgerPParams era <$> Q.arbitrary
ShelleyBasedEraConway -> LedgerPParams era <$> Q.arbitrary
ShelleyBasedEraShelley -> Q.arbitrary
ShelleyBasedEraAllegra -> Q.arbitrary
ShelleyBasedEraMary -> Q.arbitrary
ShelleyBasedEraAlonzo -> Q.arbitrary
ShelleyBasedEraBabbage -> Q.arbitrary
ShelleyBasedEraConway -> Q.arbitrary


genProtocolParametersUpdate :: CardanoEra era -> Gen ProtocolParametersUpdate
Expand Down
2 changes: 1 addition & 1 deletion cardano-api/internal/Cardano/Api/Convenience/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ queryStateForBalancedTx era allTxIns certs = runExceptT $ do
& onLeft (left . QceUnsupportedNtcVersion)
& onLeft (left . QueryEraMismatch)

pure (utxo, createLedgerProtocolParameters sbe pparams, eraHistory, systemStart, stakePools, stakeDelegDeposits)
pure (utxo, pparams, eraHistory, systemStart, stakePools, stakeDelegDeposits)

-- | Query the node to determine which era it is in.
determineEra
Expand Down
6 changes: 3 additions & 3 deletions cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ evaluateTransactionExecutionUnitsShelley :: forall era. ()
-> L.Tx (ShelleyLedgerEra era)
-> Either TransactionValidityError
(Map ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo (LedgerPParams _ pp) utxo tx' =
evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo pp utxo tx' =
case sbe of
ShelleyBasedEraShelley -> evalPreAlonzo
ShelleyBasedEraAllegra -> evalPreAlonzo
Expand Down Expand Up @@ -909,7 +909,7 @@ makeTransactionBodyAutoBalance
-> AddressInEra era -- ^ Change address
-> Maybe Word -- ^ Override key witnesses
-> Either TxBodyErrorAutoBalance (BalancedTxBody era)
makeTransactionBodyAutoBalance systemstart history lpp@(LedgerPParams _ pp) poolids stakeDelegDeposits
makeTransactionBodyAutoBalance systemstart history pp poolids stakeDelegDeposits
utxo txbodycontent changeaddr mnkeys = do
-- Our strategy is to:
-- 1. evaluate all the scripts to get the exec units, update with ex units
Expand All @@ -927,7 +927,7 @@ makeTransactionBodyAutoBalance systemstart history lpp@(LedgerPParams _ pp) pool
exUnitsMap <- first TxBodyErrorValidityInterval $
evaluateTransactionExecutionUnits
systemstart history
lpp
pp
utxo
txbody0

Expand Down
25 changes: 3 additions & 22 deletions cardano-api/internal/Cardano/Api/ProtocolParameters.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Cardano.Api.ProtocolParameters (
EpochNo,

-- * The updatable protocol parameters
LedgerProtocolParameters(..),
LedgerProtocolParameters,
EraBasedProtocolParametersUpdate(..),
AlonzoOnwardsPParams(..),
CommonProtocolParametersUpdate(..),
Expand All @@ -43,7 +43,6 @@ module Cardano.Api.ProtocolParameters (
ShelleyToAlonzoPParams'(..),
IntroducedInBabbagePParams(..),
createEraBasedProtocolParamUpdate,
createLedgerProtocolParameters,
convertToLedgerProtocolParameters,
createPParams,

Expand Down Expand Up @@ -149,34 +148,16 @@ import Text.PrettyBy.Default (display)

-- -----------------------------------------------------------------------------
-- Era based ledger protocol parameters
--
data LedgerProtocolParameters era where
LedgerPParams
:: EraPParams (ShelleyLedgerEra era)
=> ShelleyBasedEra era
-> (Ledger.PParams (ShelleyLedgerEra era))
-> LedgerProtocolParameters era


deriving instance Show (LedgerProtocolParameters era )
deriving instance Eq (LedgerProtocolParameters era)

createLedgerProtocolParameters
:: ShelleyBasedEra era
-> Ledger.PParams (ShelleyLedgerEra era)
-> LedgerProtocolParameters era
createLedgerProtocolParameters sbe pp =
shelleyBasedEraConstraints sbe $ LedgerPParams sbe pp

type LedgerProtocolParameters era = Ledger.PParams (ShelleyLedgerEra era)

-- TODO: Conway era - remove me when we begin relying on the JSON
-- instances of Ledger.PParams
convertToLedgerProtocolParameters
:: ShelleyBasedEra era
-> ProtocolParameters
-> Either ProtocolParametersConversionError (LedgerProtocolParameters era)
convertToLedgerProtocolParameters sbe pp =
createLedgerProtocolParameters sbe <$> toLedgerPParams sbe pp
convertToLedgerProtocolParameters = toLedgerPParams

createPParams
:: EraPParams (ShelleyLedgerEra era)
Expand Down
11 changes: 8 additions & 3 deletions cardano-api/internal/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately because of: https://gitlab.haskell.org/ghc/ghc/-/wikis/migration/8.6#undecidableinstances-is-pickier we would need this now for using type families in deriving clauses

{-# LANGUAGE ViewPatterns #-}

{- HLINT ignore "Avoid lambda using `infix`" -}
Expand Down Expand Up @@ -260,6 +261,7 @@ import qualified Data.ByteString.Lazy as LBS
import Data.Foldable (for_, toList)
import Data.Function (on)
import Data.Functor (($>))
import Data.Functor.Identity
import Data.List (intercalate, sortBy)
import qualified Data.List as List
import qualified Data.List.NonEmpty as NonEmpty
Expand Down Expand Up @@ -1763,7 +1765,9 @@ data TxBodyContent build era =
txGovernanceActions :: TxGovernanceActions era,
txVotingProcedures :: Maybe (Featured ConwayEraOnwards era (VotingProcedures era))
}
deriving (Eq, Show)

deriving instance (IsShelleyBasedEra era, Eq (Ledger.PParamsHKD Identity (ShelleyLedgerEra era))) => Eq (TxBodyContent build era)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could create type alias for ledger constraints to avoid using them in the API directly.

deriving instance (IsShelleyBasedEra era, Show (Ledger.PParamsHKD Identity (ShelleyLedgerEra era))) => Show (TxBodyContent build era)

defaultTxBodyContent :: IsCardanoEra era => TxBodyContent BuildTx era
defaultTxBodyContent = TxBodyContent
Expand Down Expand Up @@ -3570,16 +3574,17 @@ convScriptData era txOuts scriptWitnesses =
in TxBodyScriptData scriptDataInEra datums redeemers

convPParamsToScriptIntegrityHash
:: L.AlonzoEraPParams (ShelleyLedgerEra era)
:: forall era. (IsShelleyBasedEra era, L.AlonzoEraPParams (ShelleyLedgerEra era))
=> BuildTxWith BuildTx (Maybe (LedgerProtocolParameters era))
-> Alonzo.Redeemers (ShelleyLedgerEra era)
-> Alonzo.TxDats (ShelleyLedgerEra era)
-> Set Alonzo.Language
-> Either TxBodyError (StrictMaybe (L.ScriptIntegrityHash (Ledger.EraCrypto (ShelleyLedgerEra era))))
convPParamsToScriptIntegrityHash txProtocolParams redeemers datums languages = do
let sbe = shelleyBasedEra @era
lang <- case txProtocolParams of
BuildTxWith Nothing -> return Nothing
BuildTxWith (Just (LedgerPParams sbe pp)) ->
BuildTxWith (Just pp) ->
case sbe of
ShelleyBasedEraShelley ->
return Nothing
Expand Down
3 changes: 1 addition & 2 deletions cardano-api/src/Cardano/Api/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module Cardano.Api.Shelley
fromShelleyMetadatum,

-- * Protocol parameters
LedgerProtocolParameters(..),
LedgerProtocolParameters,
EraBasedProtocolParametersUpdate(..),
CommonProtocolParametersUpdate(..),
AlonzoOnwardsPParams(..),
Expand All @@ -120,7 +120,6 @@ module Cardano.Api.Shelley
IntroducedInBabbagePParams(..),
createEraBasedProtocolParamUpdate,
convertToLedgerProtocolParameters,
createLedgerProtocolParameters,

ProtocolParameters(..),
checkProtocolParameters,
Expand Down