Skip to content

Commit

Permalink
Some experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy authored and palas committed Jul 6, 2024
1 parent 19da63d commit 7f51c12
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 29 deletions.
1 change: 1 addition & 0 deletions cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ library internal
scientific,
serialise,
small-steps ^>=1.1,
some,
sop-core,
stm,
strict-sop-core,
Expand Down
12 changes: 6 additions & 6 deletions cardano-api/internal/Cardano/Api/Eon/ShelleyBasedEra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ shelleyBasedEraConstraints = \case
ShelleyBasedEraBabbage -> id
ShelleyBasedEraConway -> id

data AnyShelleyBasedEra where
AnyShelleyBasedEra
:: Typeable era
=> ShelleyBasedEra era
-> AnyShelleyBasedEra
-- deriving instance Show AnyShelleyBasedEra

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

instance Eq AnyShelleyBasedEra where
AnyShelleyBasedEra sbe == AnyShelleyBasedEra sbe' =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Cardano.Ledger.Core (EraCrypto)
import qualified Cardano.Ledger.Core as L
import Control.Monad (foldM)
import qualified Data.Map as Map
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text.Encoding as Text
Expand Down
4 changes: 2 additions & 2 deletions cardano-api/internal/Cardano/Api/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ data LedgerStateError
-- prior to the termination epoch.
TerminationEpochReached EpochNo
| UnexpectedLedgerState
AnyShelleyBasedEra
(Some ShelleyBasedEra)
-- ^ Expected era
(Consensus.CardanoLedgerState Consensus.StandardCrypto)
-- ^ Ledgerstate from an unexpected era
Expand Down Expand Up @@ -1206,7 +1206,7 @@ getNewEpochState
-> Consensus.CardanoLedgerState Consensus.StandardCrypto
-> Either LedgerStateError (ShelleyAPI.NewEpochState (ShelleyLedgerEra era))
getNewEpochState era x = do
let err = UnexpectedLedgerState (shelleyBasedEraConstraints era $ AnyShelleyBasedEra era) x
let err = UnexpectedLedgerState (shelleyBasedEraConstraints era $ Some era) x
case era of
ShelleyBasedEraShelley ->
case x of
Expand Down
38 changes: 19 additions & 19 deletions cardano-api/internal/Cardano/Api/SerialiseLedgerCddl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,26 @@ deserialiseFromTextEnvelopeCddlAnyOf types teCddl =
-- Parse the text 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.
cddlTypeToEra :: Text -> Either TextEnvelopeCddlError AnyShelleyBasedEra
cddlTypeToEra :: Text -> Either TextEnvelopeCddlError (Some ShelleyBasedEra)
cddlTypeToEra = \case
"Witnessed Tx ShelleyEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraShelley
"Witnessed Tx AllegraEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraAllegra
"Witnessed Tx MaryEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraMary
"Witnessed Tx AlonzoEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraAlonzo
"Witnessed Tx BabbageEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraBabbage
"Witnessed Tx ConwayEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraConway
"Unwitnessed Tx ShelleyEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraShelley
"Unwitnessed Tx AllegraEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraAllegra
"Unwitnessed Tx MaryEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraMary
"Unwitnessed Tx AlonzoEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraAlonzo
"Unwitnessed Tx BabbageEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraBabbage
"Unwitnessed Tx ConwayEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraConway
"TxWitness ShelleyEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraShelley
"TxWitness AllegraEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraAllegra
"TxWitness MaryEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraMary
"TxWitness AlonzoEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraAlonzo
"TxWitness BabbageEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraBabbage
"TxWitness ConwayEra" -> return $ AnyShelleyBasedEra ShelleyBasedEraConway
"Witnessed Tx ShelleyEra" -> return $ Some ShelleyBasedEraShelley
"Witnessed Tx AllegraEra" -> return $ Some ShelleyBasedEraAllegra
"Witnessed Tx MaryEra" -> return $ Some ShelleyBasedEraMary
"Witnessed Tx AlonzoEra" -> return $ Some ShelleyBasedEraAlonzo
"Witnessed Tx BabbageEra" -> return $ Some ShelleyBasedEraBabbage
"Witnessed Tx ConwayEra" -> return $ Some ShelleyBasedEraConway
"Unwitnessed Tx ShelleyEra" -> return $ Some ShelleyBasedEraShelley
"Unwitnessed Tx AllegraEra" -> return $ Some ShelleyBasedEraAllegra
"Unwitnessed Tx MaryEra" -> return $ Some ShelleyBasedEraMary
"Unwitnessed Tx AlonzoEra" -> return $ Some ShelleyBasedEraAlonzo
"Unwitnessed Tx BabbageEra" -> return $ Some ShelleyBasedEraBabbage
"Unwitnessed Tx ConwayEra" -> return $ Some ShelleyBasedEraConway
"TxWitness ShelleyEra" -> return $ Some ShelleyBasedEraShelley
"TxWitness AllegraEra" -> return $ Some ShelleyBasedEraAllegra
"TxWitness MaryEra" -> return $ Some ShelleyBasedEraMary
"TxWitness AlonzoEra" -> return $ Some ShelleyBasedEraAlonzo
"TxWitness BabbageEra" -> return $ Some ShelleyBasedEraBabbage
"TxWitness ConwayEra" -> return $ Some ShelleyBasedEraConway
unknownCddlType -> Left $ TextEnvelopeCddlErrUnknownType unknownCddlType

readFileTextEnvelopeCddlAnyOf
Expand Down
4 changes: 2 additions & 2 deletions cardano-api/test/cardano-api-test/Test/Cardano/Api/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Test.Tasty.Hedgehog (testProperty)
prop_maxBound_CardanoMatchesShelley :: Property
prop_maxBound_CardanoMatchesShelley = property $ do
AnyCardanoEra era <- forAll $ Gen.element [maxBound]
AnyShelleyBasedEra sbe <- forAll $ Gen.element [maxBound]
Some sbe <- forAll $ Gen.element [maxBound]

fromEnum (anyCardanoEra era) === fromEnum (anyCardanoEra (toCardanoEra sbe))

Expand All @@ -43,7 +43,7 @@ prop_toJSON_CardanoMatchesShelley :: Property
prop_toJSON_CardanoMatchesShelley = property $ do
AnyShelleyBasedEra sbe <- forAll $ Gen.element [minBound .. maxBound]

toJSON (AnyShelleyBasedEra sbe) === toJSON (anyCardanoEra (toCardanoEra sbe))
toJSON (Some sbe) === toJSON (anyCardanoEra (toCardanoEra sbe))

tests :: TestTree
tests =
Expand Down

0 comments on commit 7f51c12

Please sign in to comment.