Skip to content

Commit

Permalink
Merge pull request #98 from input-output-hk/newhoggy/rename-ShelleyBa…
Browse files Browse the repository at this point in the history
…sedEra-variables-to-sbe

Rename `era` to `sbe` when type is `ShelleyBasedEra`
  • Loading branch information
newhoggy committed Jul 11, 2023
2 parents 778de65 + cfd789e commit ef0a3be
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 286 deletions.
21 changes: 10 additions & 11 deletions cardano-api/internal/Cardano/Api/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ data AnyShelleyBasedEra where
deriving instance Show AnyShelleyBasedEra

instance Eq AnyShelleyBasedEra where
AnyShelleyBasedEra era == AnyShelleyBasedEra era' =
case testEquality era era' of
AnyShelleyBasedEra sbe == AnyShelleyBasedEra sbe' =
case testEquality sbe sbe' of
Nothing -> False
Just Refl -> True -- since no constructors share types

Expand Down Expand Up @@ -435,7 +435,7 @@ instance Enum AnyShelleyBasedEra where
<> " does not correspond to any known enumerated era."

instance ToJSON AnyShelleyBasedEra where
toJSON (AnyShelleyBasedEra era) = toJSON era
toJSON (AnyShelleyBasedEra sbe) = toJSON sbe

instance FromJSON AnyShelleyBasedEra where
parseJSON = withText "AnyShelleyBasedEra"
Expand Down Expand Up @@ -534,14 +534,13 @@ type family CardanoLedgerEra era where
-- | Lookup the lower major protocol version for the shelley based era. In other words
-- this is the major protocol version that the era has started in.
eraProtVerLow :: ShelleyBasedEra era -> L.Version
eraProtVerLow era =
case era of
ShelleyBasedEraShelley -> L.eraProtVerLow @L.Shelley
ShelleyBasedEraAllegra -> L.eraProtVerLow @L.Allegra
ShelleyBasedEraMary -> L.eraProtVerLow @L.Mary
ShelleyBasedEraAlonzo -> L.eraProtVerLow @L.Alonzo
ShelleyBasedEraBabbage -> L.eraProtVerLow @L.Babbage
ShelleyBasedEraConway -> L.eraProtVerLow @L.Conway
eraProtVerLow = \case
ShelleyBasedEraShelley -> L.eraProtVerLow @L.Shelley
ShelleyBasedEraAllegra -> L.eraProtVerLow @L.Allegra
ShelleyBasedEraMary -> L.eraProtVerLow @L.Mary
ShelleyBasedEraAlonzo -> L.eraProtVerLow @L.Alonzo
ShelleyBasedEraBabbage -> L.eraProtVerLow @L.Babbage
ShelleyBasedEraConway -> L.eraProtVerLow @L.Conway

requireShelleyBasedEra :: ()
=> Applicative m
Expand Down
58 changes: 29 additions & 29 deletions cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ evaluateTransactionFee bpparams txbody keywitcount _byronwitcount =
ByronTx{} -> case shelleyBasedEra :: ShelleyBasedEra era of {}
--TODO: we could actually support Byron here, it'd be different but simpler

ShelleyTx era tx -> withShelleyBasedEraConstraintsForLedger era (evalShelleyBasedEra tx)
ShelleyTx sbe tx -> withShelleyBasedEraConstraintsForLedger sbe (evalShelleyBasedEra tx)
where
evalShelleyBasedEra :: forall ledgerera.
ShelleyLedgerEra era ~ ledgerera
Expand Down Expand Up @@ -527,11 +527,11 @@ evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo bpp utxo tx'
-> Either TransactionValidityError
(Map ScriptWitnessIndex
(Either ScriptExecutionError ExecutionUnits))
evalAlonzo era tx = do
evalAlonzo sbe' tx = do
case L.evalTxExUnits
(unbundleLedgerShelleyBasedProtocolParams era bpp)
(unbundleLedgerShelleyBasedProtocolParams sbe' bpp)
tx
(toLedgerUTxO era utxo)
(toLedgerUTxO sbe' utxo)
ledgerEpochInfo
systemstart
of Left err -> Left (TransactionValidityTranslationError err)
Expand All @@ -544,11 +544,11 @@ evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo bpp utxo tx'
-> Either TransactionValidityError
(Map ScriptWitnessIndex
(Either ScriptExecutionError ExecutionUnits))
evalBabbage era tx = do
evalBabbage sbe' tx = do
case L.evalTxExUnits
(unbundleLedgerShelleyBasedProtocolParams era bpp)
(unbundleLedgerShelleyBasedProtocolParams sbe' bpp)
tx
(toLedgerUTxO era utxo)
(toLedgerUTxO sbe' utxo)
ledgerEpochInfo
systemstart
of Left err -> Left (TransactionValidityTranslationError err)
Expand All @@ -563,11 +563,11 @@ evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo bpp utxo tx'
-> Either TransactionValidityError
(Map ScriptWitnessIndex
(Either ScriptExecutionError ExecutionUnits))
evalConway era tx = do
evalConway sbe' tx = do
case L.evalTxExUnits
(unbundleLedgerShelleyBasedProtocolParams era bpp)
(unbundleLedgerShelleyBasedProtocolParams sbe' bpp)
tx
(toLedgerUTxO era utxo)
(toLedgerUTxO sbe' utxo)
ledgerEpochInfo
systemstart
of Left err -> Left (TransactionValidityTranslationError err)
Expand Down Expand Up @@ -648,11 +648,11 @@ evaluateTransactionBalance _ _ _ _ (ByronTxBody _) =
--TODO: we could actually support Byron here, it'd be different but simpler

evaluateTransactionBalance bpp poolids stakeDelegDeposits utxo
(ShelleyTxBody era txbody _ _ _ _) =
(ShelleyTxBody sbe txbody _ _ _ _) =
withLedgerConstraints
era
(getShelleyEraTxBodyConstraint era evalAdaOnly)
(getShelleyEraTxBodyConstraint era evalMultiAsset)
sbe
(getShelleyEraTxBodyConstraint sbe evalAdaOnly)
(getShelleyEraTxBodyConstraint sbe evalMultiAsset)
where
getShelleyEraTxBodyConstraint
:: forall era' a.
Expand Down Expand Up @@ -685,10 +685,10 @@ evaluateTransactionBalance bpp poolids stakeDelegDeposits utxo
evalMultiAsset evidence =
TxOutValue evidence . fromMaryValue $
L.evalBalanceTxBody
(unbundleLedgerShelleyBasedProtocolParams era bpp)
(unbundleLedgerShelleyBasedProtocolParams sbe bpp)
lookupDelegDeposit
isRegPool
(toLedgerUTxO era utxo)
(toLedgerUTxO sbe utxo)
txbody

evalAdaOnly :: forall ledgerera.
Expand All @@ -701,10 +701,10 @@ evaluateTransactionBalance bpp poolids stakeDelegDeposits utxo
evalAdaOnly evidence =
TxOutAdaOnly evidence . fromShelleyLovelace
$ L.evalBalanceTxBody
(unbundleLedgerShelleyBasedProtocolParams era bpp)
(unbundleLedgerShelleyBasedProtocolParams sbe bpp)
lookupDelegDeposit
isRegPool
(toLedgerUTxO era utxo)
(toLedgerUTxO sbe utxo)
txbody

-- Conjur up all the necessary class instances and evidence
Expand Down Expand Up @@ -1122,8 +1122,8 @@ makeTransactionBodyAutoBalance systemstart history pparams poolids stakeDelegDep
)
else (TxReturnCollateralNone, TxTotalCollateralNone)

era :: ShelleyBasedEra era
era = shelleyBasedEra
sbe :: ShelleyBasedEra era
sbe = shelleyBasedEra

era' :: CardanoEra era
era' = cardanoEra
Expand Down Expand Up @@ -1165,7 +1165,7 @@ makeTransactionBodyAutoBalance systemstart history pparams poolids stakeDelegDep
-> BundledProtocolParameters era
-> Either TxBodyErrorAutoBalance ()
checkMinUTxOValue txout@(TxOut _ v _ _) bpp = do
let minUTxO = calculateMinimumUTxO era txout bpp
let minUTxO = calculateMinimumUTxO sbe txout bpp
if txOutValueToLovelace v >= minUTxO
then Right ()
else Left $ TxBodyErrorMinUTxONotMet
Expand Down Expand Up @@ -1328,20 +1328,20 @@ calculateMinimumUTxO
-> TxOut CtxTx era
-> BundledProtocolParameters era
-> Lovelace
calculateMinimumUTxO era txout bpp =
case era of
calculateMinimumUTxO sbe txout bpp =
case sbe of
ShelleyBasedEraShelley ->
calcMinUTxO (unbundleLedgerShelleyBasedProtocolParams era bpp) (toShelleyTxOutAny era txout)
calcMinUTxO (unbundleLedgerShelleyBasedProtocolParams sbe bpp) (toShelleyTxOutAny sbe txout)
ShelleyBasedEraAllegra ->
calcMinUTxO (unbundleLedgerShelleyBasedProtocolParams era bpp) (toShelleyTxOutAny era txout)
calcMinUTxO (unbundleLedgerShelleyBasedProtocolParams sbe bpp) (toShelleyTxOutAny sbe txout)
ShelleyBasedEraMary ->
calcMinUTxO (unbundleLedgerShelleyBasedProtocolParams era bpp) (toShelleyTxOutAny era txout)
calcMinUTxO (unbundleLedgerShelleyBasedProtocolParams sbe bpp) (toShelleyTxOutAny sbe txout)
ShelleyBasedEraAlonzo ->
calcMinUTxO (unbundleLedgerShelleyBasedProtocolParams era bpp) (toShelleyTxOutAny era txout)
calcMinUTxO (unbundleLedgerShelleyBasedProtocolParams sbe bpp) (toShelleyTxOutAny sbe txout)
ShelleyBasedEraBabbage ->
calcMinUTxO (unbundleLedgerShelleyBasedProtocolParams era bpp) (toShelleyTxOutAny era txout)
calcMinUTxO (unbundleLedgerShelleyBasedProtocolParams sbe bpp) (toShelleyTxOutAny sbe txout)
ShelleyBasedEraConway ->
calcMinUTxO (unbundleLedgerShelleyBasedProtocolParams era bpp) (toShelleyTxOutAny era txout)
calcMinUTxO (unbundleLedgerShelleyBasedProtocolParams sbe bpp) (toShelleyTxOutAny sbe txout)
where
calcMinUTxO :: L.EraTxOut ledgerera => L.PParams ledgerera -> L.TxOut ledgerera -> Lovelace
calcMinUTxO pp txOut =
Expand Down
16 changes: 8 additions & 8 deletions cardano-api/internal/Cardano/Api/ProtocolParameters.hs
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,8 @@ toLedgerUpdate :: forall era ledgerera.
=> ShelleyBasedEra era
-> UpdateProposal
-> Either ProtocolParametersConversionError (Ledger.Update ledgerera)
toLedgerUpdate era (UpdateProposal ppup epochno) =
(`Ledger.Update` epochno) <$> toLedgerProposedPPUpdates era ppup
toLedgerUpdate sbe (UpdateProposal ppup epochno) =
(`Ledger.Update` epochno) <$> toLedgerProposedPPUpdates sbe ppup


toLedgerProposedPPUpdates :: forall era ledgerera.
Expand All @@ -938,8 +938,8 @@ toLedgerProposedPPUpdates :: forall era ledgerera.
=> ShelleyBasedEra era
-> Map (Hash GenesisKey) ProtocolParametersUpdate
-> Either ProtocolParametersConversionError (Ledger.ProposedPPUpdates ledgerera)
toLedgerProposedPPUpdates era m =
Ledger.ProposedPPUpdates . Map.mapKeysMonotonic (\(GenesisKeyHash kh) -> kh) <$> traverse (toLedgerPParamsUpdate era) m
toLedgerProposedPPUpdates sbe m =
Ledger.ProposedPPUpdates . Map.mapKeysMonotonic (\(GenesisKeyHash kh) -> kh) <$> traverse (toLedgerPParamsUpdate sbe) m

toLedgerPParamsUpdate :: ShelleyBasedEra era
-> ProtocolParametersUpdate
Expand Down Expand Up @@ -1120,8 +1120,8 @@ fromLedgerUpdate :: forall era ledgerera.
=> ShelleyBasedEra era
-> Ledger.Update ledgerera
-> UpdateProposal
fromLedgerUpdate era (Ledger.Update ppup epochno) =
UpdateProposal (fromLedgerProposedPPUpdates era ppup) epochno
fromLedgerUpdate sbe (Ledger.Update ppup epochno) =
UpdateProposal (fromLedgerProposedPPUpdates sbe ppup) epochno


fromLedgerProposedPPUpdates :: forall era ledgerera.
Expand All @@ -1130,8 +1130,8 @@ fromLedgerProposedPPUpdates :: forall era ledgerera.
=> ShelleyBasedEra era
-> Ledger.ProposedPPUpdates ledgerera
-> Map (Hash GenesisKey) ProtocolParametersUpdate
fromLedgerProposedPPUpdates era =
Map.map (fromLedgerPParamsUpdate era)
fromLedgerProposedPPUpdates sbe =
Map.map (fromLedgerPParamsUpdate sbe)
. Map.mapKeysMonotonic GenesisKeyHash
. (\(Ledger.ProposedPPUpdates ppup) -> ppup)

Expand Down
46 changes: 23 additions & 23 deletions cardano-api/internal/Cardano/Api/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,10 @@ toLedgerUTxO :: ShelleyLedgerEra era ~ ledgerera
=> ShelleyBasedEra era
-> UTxO era
-> Shelley.UTxO ledgerera
toLedgerUTxO era (UTxO utxo) =
toLedgerUTxO sbe (UTxO utxo) =
Shelley.UTxO
. Map.fromList
. map (bimap toShelleyTxIn (toShelleyTxOut era))
. map (bimap toShelleyTxIn (toShelleyTxOut sbe))
. Map.toList
$ utxo

Expand All @@ -533,10 +533,10 @@ fromLedgerUTxO :: ShelleyLedgerEra era ~ ledgerera
=> ShelleyBasedEra era
-> Shelley.UTxO ledgerera
-> UTxO era
fromLedgerUTxO era (Shelley.UTxO utxo) =
fromLedgerUTxO sbe (Shelley.UTxO utxo) =
UTxO
. Map.fromList
. map (bimap fromShelleyTxIn (fromShelleyTxOut era))
. map (bimap fromShelleyTxIn (fromShelleyTxOut sbe))
. Map.toList
$ utxo

Expand Down Expand Up @@ -606,11 +606,11 @@ toConsensusQuery (QueryInEra ByronEraInCardanoMode QueryByronUpdateState) =
Consensus.QueryIfCurrentByron
Consensus.GetUpdateInterfaceState

toConsensusQuery (QueryInEra erainmode (QueryInShelleyBasedEra era q)) =
toConsensusQuery (QueryInEra erainmode (QueryInShelleyBasedEra sbe q)) =
case erainmode of
ByronEraInByronMode -> case era of {}
ByronEraInByronMode -> case sbe of {}
ShelleyEraInShelleyMode -> toConsensusQueryShelleyBased erainmode q
ByronEraInCardanoMode -> case era of {}
ByronEraInCardanoMode -> case sbe of {}
ShelleyEraInCardanoMode -> toConsensusQueryShelleyBased erainmode q
AllegraEraInCardanoMode -> toConsensusQueryShelleyBased erainmode q
MaryEraInCardanoMode -> toConsensusQueryShelleyBased erainmode q
Expand Down Expand Up @@ -781,11 +781,11 @@ fromConsensusQueryResult (QueryInEra ByronEraInCardanoMode
_ -> fromConsensusQueryResultMismatch

fromConsensusQueryResult (QueryInEra ByronEraInByronMode
(QueryInShelleyBasedEra era _)) _ _ =
case era of {}
(QueryInShelleyBasedEra sbe _)) _ _ =
case sbe of {}

fromConsensusQueryResult (QueryInEra ShelleyEraInShelleyMode
(QueryInShelleyBasedEra _era q)) q' r' =
(QueryInShelleyBasedEra _sbe q)) q' r' =
case (q', r') of
(Consensus.BlockQuery (Consensus.DegenQuery q''),
Consensus.DegenQueryResult r'')
Expand All @@ -794,11 +794,11 @@ fromConsensusQueryResult (QueryInEra ShelleyEraInShelleyMode
_ -> fromConsensusQueryResultMismatch

fromConsensusQueryResult (QueryInEra ByronEraInCardanoMode
(QueryInShelleyBasedEra era _)) _ _ =
case era of {}
(QueryInShelleyBasedEra sbe _)) _ _ =
case sbe of {}

fromConsensusQueryResult (QueryInEra ShelleyEraInCardanoMode
(QueryInShelleyBasedEra _era q)) q' r' =
(QueryInShelleyBasedEra _sbe q)) q' r' =
case q' of
Consensus.BlockQuery (Consensus.QueryIfCurrentShelley q'')
-> bimap fromConsensusEraMismatch
Expand Down Expand Up @@ -883,34 +883,34 @@ fromConsensusQueryResultShelleyBased _ QueryGenesisParameters q' r' =
(Consensus.getCompactGenesis r')
_ -> fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased era QueryProtocolParameters q' r' =
fromConsensusQueryResultShelleyBased sbe QueryProtocolParameters q' r' =
case q' of
Consensus.GetCurrentPParams -> fromLedgerPParams era r'
Consensus.GetCurrentPParams -> fromLedgerPParams sbe r'
_ -> fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased era QueryProtocolParametersUpdate q' r' =
fromConsensusQueryResultShelleyBased sbe QueryProtocolParametersUpdate q' r' =
case q' of
Consensus.GetProposedPParamsUpdates -> fromLedgerProposedPPUpdates era r'
Consensus.GetProposedPParamsUpdates -> fromLedgerProposedPPUpdates sbe r'
_ -> fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased _ QueryStakeDistribution q' r' =
case q' of
Consensus.GetStakeDistribution -> fromShelleyPoolDistr r'
_ -> fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased era (QueryUTxO QueryUTxOWhole) q' utxo' =
fromConsensusQueryResultShelleyBased sbe (QueryUTxO QueryUTxOWhole) q' utxo' =
case q' of
Consensus.GetUTxOWhole -> fromLedgerUTxO era utxo'
Consensus.GetUTxOWhole -> fromLedgerUTxO sbe utxo'
_ -> fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased era (QueryUTxO QueryUTxOByAddress{}) q' utxo' =
fromConsensusQueryResultShelleyBased sbe (QueryUTxO QueryUTxOByAddress{}) q' utxo' =
case q' of
Consensus.GetUTxOByAddress{} -> fromLedgerUTxO era utxo'
Consensus.GetUTxOByAddress{} -> fromLedgerUTxO sbe utxo'
_ -> fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased era (QueryUTxO QueryUTxOByTxIn{}) q' utxo' =
fromConsensusQueryResultShelleyBased sbe (QueryUTxO QueryUTxOByTxIn{}) q' utxo' =
case q' of
Consensus.GetUTxOByTxIn{} -> fromLedgerUTxO era utxo'
Consensus.GetUTxOByTxIn{} -> fromLedgerUTxO sbe utxo'
_ -> fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased _ (QueryStakeAddresses _ nId) q' r' =
Expand Down
4 changes: 2 additions & 2 deletions cardano-api/internal/Cardano/Api/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,8 @@ toShelleyScript (ScriptInEra langInEra (PlutusScript PlutusScriptV3
fromShelleyBasedScript :: ShelleyBasedEra era
-> Ledger.Script (ShelleyLedgerEra era)
-> ScriptInEra era
fromShelleyBasedScript era script =
case era of
fromShelleyBasedScript sbe script =
case sbe of
ShelleyBasedEraShelley ->
ScriptInEra SimpleScriptInShelley
. SimpleScript $ fromShelleyMultiSig script
Expand Down
10 changes: 5 additions & 5 deletions cardano-api/internal/Cardano/Api/SerialiseLedgerCddl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,21 @@ deserialiseWitnessLedgerCddl
:: ShelleyBasedEra era
-> TextEnvelopeCddl
-> Either TextEnvelopeCddlError (KeyWitness era)
deserialiseWitnessLedgerCddl era TextEnvelopeCddl{teCddlRawCBOR,teCddlDescription} =
deserialiseWitnessLedgerCddl sbe TextEnvelopeCddl{teCddlRawCBOR,teCddlDescription} =
--TODO: Parse these into types because this will increase code readability and
-- will make it easier to keep track of the different Cddl descriptions via
-- a single sum data type.
case teCddlDescription of
"Key BootstrapWitness ShelleyEra" -> do
w <- first TextEnvelopeCddlErrCBORDecodingError
$ CBOR.decodeFullAnnotator
(eraProtVerLow era) "Shelley Witness" CBOR.decCBOR (LBS.fromStrict teCddlRawCBOR)
Right $ ShelleyBootstrapWitness era w
(eraProtVerLow sbe) "Shelley Witness" CBOR.decCBOR (LBS.fromStrict teCddlRawCBOR)
Right $ ShelleyBootstrapWitness sbe w
"Key Witness ShelleyEra" -> do
w <- first TextEnvelopeCddlErrCBORDecodingError
$ CBOR.decodeFullAnnotator
(eraProtVerLow era) "Shelley Witness" CBOR.decCBOR (LBS.fromStrict teCddlRawCBOR)
Right $ ShelleyKeyWitness era w
(eraProtVerLow sbe) "Shelley Witness" CBOR.decCBOR (LBS.fromStrict teCddlRawCBOR)
Right $ ShelleyKeyWitness sbe w
_ -> Left TextEnvelopeCddlUnknownKeyWitness

writeTxFileTextEnvelopeCddl
Expand Down
Loading

0 comments on commit ef0a3be

Please sign in to comment.