Skip to content

Commit

Permalink
Merge pull request #308 from input-output-hk/newhoggy/delete-EraCast
Browse files Browse the repository at this point in the history
Delete `EraCast` type class
  • Loading branch information
newhoggy authored Oct 11, 2023
2 parents 20a58e1 + f978ed0 commit 3ca2774
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 104 deletions.
1 change: 0 additions & 1 deletion cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ library internal
Cardano.Api.Eon.ShelleyToAlonzoEra
Cardano.Api.Eon.ShelleyToBabbageEra
Cardano.Api.Eon.ShelleyToMaryEra
Cardano.Api.EraCast
Cardano.Api.Eras
Cardano.Api.Eras.Case
Cardano.Api.Eras.Constraints
Expand Down
14 changes: 0 additions & 14 deletions cardano-api/internal/Cardano/Api/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ module Cardano.Api.Address (
) where

import Cardano.Api.Eon.ShelleyBasedEra
import Cardano.Api.EraCast
import Cardano.Api.Eras
import Cardano.Api.Hash
import Cardano.Api.HasTypeProxy
Expand Down Expand Up @@ -378,11 +377,6 @@ instance IsShelleyBasedEra era => FromJSON (AddressInEra era) where
addressAny <- runParsecParser parseAddressAny txt
pure $ anyAddressInShelleyBasedEra addressAny

instance EraCast AddressInEra where
eraCast toEra' (AddressInEra addressTypeInEra address) = AddressInEra
<$> eraCast toEra' addressTypeInEra
<*> pure address

parseAddressAny :: Parsec.Parser AddressAny
parseAddressAny = do
str <- lexPlausibleAddressString
Expand Down Expand Up @@ -469,14 +463,6 @@ instance IsCardanoEra era => SerialiseAddress (AddressInEra era) where
deserialiseAddress _ t =
rightToMaybe . anyAddressInEra cardanoEra =<< deserialiseAddress AsAddressAny t

instance EraCast (AddressTypeInEra addrtype) where
eraCast toEra' v = case v of
ByronAddressInAnyEra -> pure ByronAddressInAnyEra
ShelleyAddressInEra previousEra ->
case cardanoEraStyle toEra' of
LegacyByronEra -> Left $ EraCastError v (shelleyBasedToCardanoEra previousEra) toEra'
ShelleyBasedEra newSbe -> Right $ ShelleyAddressInEra newSbe

byronAddressInEra :: Address ByronAddr -> AddressInEra era
byronAddressInEra = AddressInEra ByronAddressInAnyEra

Expand Down
28 changes: 0 additions & 28 deletions cardano-api/internal/Cardano/Api/EraCast.hs

This file was deleted.

5 changes: 0 additions & 5 deletions cardano-api/internal/Cardano/Api/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ import Cardano.Api.Address
import Cardano.Api.Block
import Cardano.Api.Certificate
import Cardano.Api.Eon.ShelleyBasedEra
import Cardano.Api.EraCast
import Cardano.Api.Eras.Constraints
import Cardano.Api.Eras.Core
import Cardano.Api.GenesisParameters
Expand Down Expand Up @@ -127,7 +126,6 @@ import Ouroboros.Network.Block (Serialised (..))
import Ouroboros.Network.NodeToClient.Version (NodeToClientVersion (..))
import Ouroboros.Network.Protocol.LocalStateQuery.Client (Some (..))

import Control.Monad (forM)
import Control.Monad.Trans.Except
import Data.Aeson (FromJSON (..), ToJSON (..), withObject)
import qualified Data.Aeson as Aeson
Expand Down Expand Up @@ -377,9 +375,6 @@ newtype ByronUpdateState = ByronUpdateState Byron.Update.State
newtype UTxO era = UTxO { unUTxO :: Map TxIn (TxOut CtxUTxO era) }
deriving (Eq, Show)

instance EraCast UTxO where
eraCast toEra' (UTxO m) = UTxO <$> forM m (eraCast toEra')

data UTxOInAnyEra where
UTxOInAnyEra :: CardanoEra era
-> UTxO era
Expand Down
10 changes: 0 additions & 10 deletions cardano-api/internal/Cardano/Api/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ module Cardano.Api.Script (

import Cardano.Api.Eon.BabbageEraOnwards
import Cardano.Api.Eon.ShelleyBasedEra
import Cardano.Api.EraCast
import Cardano.Api.Eras.Case
import Cardano.Api.Eras.Core
import Cardano.Api.Error
Expand Down Expand Up @@ -1400,15 +1399,6 @@ instance IsCardanoEra era => FromJSON (ReferenceScript era) where
(\w -> ReferenceScript w <$> o .: "referenceScript")
(cardanoEra :: CardanoEra era)

instance EraCast ReferenceScript where
eraCast toEra = \case
ReferenceScriptNone -> pure ReferenceScriptNone
v@(ReferenceScript ws scriptInAnyLang) ->
caseByronToAlonzoOrBabbageEraOnwards
(const (Left $ EraCastError v (babbageEraOnwardsToCardanoEra ws) toEra))
(\wt -> Right $ ReferenceScript wt scriptInAnyLang)
toEra

refScriptToShelleyScript
:: CardanoEra era
-> ReferenceScript era
Expand Down
41 changes: 0 additions & 41 deletions cardano-api/internal/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ import Cardano.Api.Eon.MaryEraOnwards
import Cardano.Api.Eon.ShelleyBasedEra
import Cardano.Api.Eon.ShelleyEraOnly
import Cardano.Api.Eon.ShelleyToBabbageEra
import Cardano.Api.EraCast
import Cardano.Api.Eras.Case
import Cardano.Api.Eras.Constraints
import Cardano.Api.Eras.Core
Expand Down Expand Up @@ -327,14 +326,6 @@ data TxOut ctx era = TxOut (AddressInEra era)
deriving instance Eq (TxOut ctx era)
deriving instance Show (TxOut ctx era)

instance EraCast (TxOut ctx) where
eraCast toEra (TxOut addressInEra txOutValue txOutDatum referenceScript) =
TxOut
<$> eraCast toEra addressInEra
<*> eraCast toEra txOutValue
<*> eraCast toEra txOutDatum
<*> eraCast toEra referenceScript

data TxOutInAnyEra where
TxOutInAnyEra :: CardanoEra era
-> TxOut CtxTx era
Expand Down Expand Up @@ -895,19 +886,6 @@ data TxOutValue era where

TxOutValue :: MaryEraOnwards era -> Value -> TxOutValue era

instance EraCast TxOutValue where
eraCast toEra v = case v of
TxOutAdaOnly _previousEra lovelace ->
caseByronToAllegraOrMaryEraOnwards
(\w -> Right $ TxOutAdaOnly w lovelace)
(\w -> Right $ TxOutValue w $ lovelaceToValue lovelace)
toEra
TxOutValue (_ :: MaryEraOnwards fromEra) value ->
caseByronToAllegraOrMaryEraOnwards
(const (Left $ EraCastError v (cardanoEra @fromEra) toEra))
(\w -> Right $ TxOutValue w value)
toEra

deriving instance Eq (TxOutValue era)
deriving instance Show (TxOutValue era)
deriving instance Generic (TxOutValue era)
Expand Down Expand Up @@ -1045,25 +1023,6 @@ data TxOutDatum ctx era where
deriving instance Eq (TxOutDatum ctx era)
deriving instance Show (TxOutDatum ctx era)

instance EraCast (TxOutDatum ctx) where
eraCast toEra v = case v of
TxOutDatumNone -> pure TxOutDatumNone
TxOutDatumHash ws hash ->
caseByronToMaryOrAlonzoEraOnwards
(const (Left $ EraCastError v (alonzoEraOnwardsToCardanoEra ws) toEra))
(\wt -> Right $ TxOutDatumHash wt hash)
toEra
TxOutDatumInTx' ws scriptData hash ->
caseByronToMaryOrAlonzoEraOnwards
(const (Left $ EraCastError v (alonzoEraOnwardsToCardanoEra ws) toEra))
(\wt -> Right $ TxOutDatumInTx' wt scriptData hash)
toEra
TxOutDatumInline ws scriptData ->
caseByronToAlonzoOrBabbageEraOnwards
(const (Left $ EraCastError v (babbageEraOnwardsToCardanoEra ws) toEra))
(\wt -> Right $ TxOutDatumInline wt scriptData)
toEra

pattern TxOutDatumInTx
:: AlonzoEraOnwards era
-> HashableScriptData
Expand Down
5 changes: 0 additions & 5 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -934,10 +934,6 @@ module Cardano.Api (
parseFilePath,
writeSecrets,

-- ** Cast functions
EraCast (..),
EraCastError (..),

-- * Convenience functions

-- ** Transaction construction
Expand Down Expand Up @@ -1037,7 +1033,6 @@ import Cardano.Api.Eon.ShelleyToAllegraEra
import Cardano.Api.Eon.ShelleyToAlonzoEra
import Cardano.Api.Eon.ShelleyToBabbageEra
import Cardano.Api.Eon.ShelleyToMaryEra
import Cardano.Api.EraCast
import Cardano.Api.Eras
import Cardano.Api.Eras.Case
import Cardano.Api.Eras.Constraints
Expand Down

0 comments on commit 3ca2774

Please sign in to comment.