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

New requireShelleyBasedEra function #58

Merged
merged 2 commits into from
Jun 16, 2023
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
16 changes: 6 additions & 10 deletions cardano-api/internal/Cardano/Api/Convenience/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ queryStateForBalancedTx :: ()
, Set PoolId
, Map StakeCredential Lovelace))
queryStateForBalancedTx era allTxIns certs = runExceptT $ do
qSbe <- pure (getSbe $ cardanoEraStyle era)
& onLeft left
sbe <- requireShelleyBasedEra era
& onNothing (left ByronEraNotSupported)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is an improvement on before because we have better control of the error that is thrown.


qeInMode <- pure (toEraInMode era CardanoMode)
& onNothing (left (EraConsensusModeMismatch (AnyConsensusMode CardanoMode) (getIsCardanoEraConstraint era $ AnyCardanoEra era)))
Expand All @@ -93,11 +93,11 @@ queryStateForBalancedTx era allTxIns certs = runExceptT $ do
_ -> Nothing

-- Query execution
utxo <- lift (queryUtxo qeInMode qSbe (QueryUTxOByTxIn (Set.fromList allTxIns)))
utxo <- lift (queryUtxo qeInMode sbe (QueryUTxOByTxIn (Set.fromList allTxIns)))
& onLeft (left . QceUnsupportedNtcVersion)
& onLeft (left . QueryEraMismatch)

pparams <- lift (queryProtocolParameters qeInMode qSbe)
pparams <- lift (queryProtocolParameters qeInMode sbe)
& onLeft (left . QceUnsupportedNtcVersion)
& onLeft (left . QueryEraMismatch)

Expand All @@ -107,15 +107,15 @@ queryStateForBalancedTx era allTxIns certs = runExceptT $ do
systemStart <- lift querySystemStart
& onLeft (left . QceUnsupportedNtcVersion)

stakePools <- lift (queryStakePools qeInMode qSbe)
stakePools <- lift (queryStakePools qeInMode sbe)
& onLeft (left . QceUnsupportedNtcVersion)
& onLeft (left . QueryEraMismatch)

stakeDelegDeposits <-
if null stakeCreds
then pure mempty
else do
lift (queryStakeDelegDeposits qeInMode qSbe stakeCreds)
lift (queryStakeDelegDeposits qeInMode sbe stakeCreds)
& onLeft (left . QceUnsupportedNtcVersion)
& onLeft (left . QueryEraMismatch)

Expand All @@ -134,10 +134,6 @@ determineEra cModeParams localNodeConnInfo =
queryNodeLocalState localNodeConnInfo Nothing
$ QueryCurrentEra CardanoModeIsMultiEra

getSbe :: CardanoEraStyle era -> Either QueryConvenienceError (ShelleyBasedEra era)
getSbe LegacyByronEra = Left ByronEraNotSupported
getSbe (ShelleyBasedEra sbe) = return sbe

-- | Execute a query against the local node. The local
-- node must be in CardanoMode.
executeQueryCardanoMode
Expand Down
12 changes: 12 additions & 0 deletions cardano-api/internal/Cardano/Api/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ module Cardano.Api.Eras
-- * Data family instances
, AsType(AsByronEra, AsShelleyEra, AsAllegraEra, AsMaryEra, AsAlonzoEra, AsBabbageEra, AsConwayEra,
AsByron, AsShelley, AsAllegra, AsMary, AsAlonzo, AsBabbage, AsConway)

-- * Assertions on era
, requireShelleyBasedEra
) where

import Cardano.Api.HasTypeProxy
Expand Down Expand Up @@ -523,3 +526,12 @@ eraProtVerLow era =
ShelleyBasedEraAlonzo -> L.eraProtVerLow @L.Alonzo
ShelleyBasedEraBabbage -> L.eraProtVerLow @L.Babbage
ShelleyBasedEraConway -> L.eraProtVerLow @L.Conway

requireShelleyBasedEra :: ()
=> Applicative m
=> CardanoEra era
-> m (Maybe (ShelleyBasedEra era))
requireShelleyBasedEra era =
case cardanoEraStyle era of
LegacyByronEra -> pure Nothing
ShelleyBasedEra sbe -> pure (Just sbe)
3 changes: 3 additions & 0 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ module Cardano.Api (
cardanoEraStyle,
shelleyBasedToCardanoEra,

-- * Assertions on era
requireShelleyBasedEra,

-- ** IO
File(..),
FileDirection(..),
Expand Down