Skip to content

Commit

Permalink
Add sbeToSimpleScriptLanguageInEra
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Nov 19, 2024
1 parent 8987907 commit 0595e7e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
55 changes: 28 additions & 27 deletions cardano-api/internal/Cardano/Api/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module Cardano.Api.Script
-- ** Languages supported in each era
, ScriptLanguageInEra (..)
, scriptLanguageSupportedInEra
, sbeToSimpleScriptLanguageInEra
, languageOfScriptLanguageInEra
, eraOfScriptLanguageInEra

Expand Down Expand Up @@ -167,7 +168,7 @@ import Data.String (IsString)
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Data.Type.Equality (TestEquality (..), type (==), (:~:) (Refl))
import Data.Type.Equality (TestEquality (..), (:~:) (Refl))
import Data.Typeable (Typeable)
import Data.Vector (Vector)
import GHC.Exts (IsList (..))
Expand Down Expand Up @@ -581,18 +582,8 @@ scriptLanguageSupportedInEra
-> Maybe (ScriptLanguageInEra lang era)
scriptLanguageSupportedInEra era lang =
case (era, lang) of
(ShelleyBasedEraShelley, SimpleScriptLanguage) ->
Just SimpleScriptInShelley
(ShelleyBasedEraAllegra, SimpleScriptLanguage) ->
Just SimpleScriptInAllegra
(ShelleyBasedEraMary, SimpleScriptLanguage) ->
Just SimpleScriptInMary
(ShelleyBasedEraAlonzo, SimpleScriptLanguage) ->
Just SimpleScriptInAlonzo
(ShelleyBasedEraBabbage, SimpleScriptLanguage) ->
Just SimpleScriptInBabbage
(ShelleyBasedEraConway, SimpleScriptLanguage) ->
Just SimpleScriptInConway
(sbe, SimpleScriptLanguage) ->
Just $ sbeToSimpleScriptLanguageInEra sbe
(ShelleyBasedEraAlonzo, PlutusScriptLanguage PlutusScriptV1) ->
Just PlutusScriptV1InAlonzo
(ShelleyBasedEraBabbage, PlutusScriptLanguage PlutusScriptV1) ->
Expand Down Expand Up @@ -625,23 +616,33 @@ languageOfScriptLanguageInEra langInEra =
PlutusScriptV2InConway -> PlutusScriptLanguage PlutusScriptV2
PlutusScriptV3InConway -> PlutusScriptLanguage PlutusScriptV3

sbeToSimpleScriptLanguageInEra
:: ShelleyBasedEra era
-> ScriptLanguageInEra SimpleScript' era
sbeToSimpleScriptLanguageInEra = \case
ShelleyBasedEraShelley -> SimpleScriptInShelley
ShelleyBasedEraAllegra -> SimpleScriptInAllegra
ShelleyBasedEraMary -> SimpleScriptInMary
ShelleyBasedEraAlonzo -> SimpleScriptInAlonzo
ShelleyBasedEraBabbage -> SimpleScriptInBabbage
ShelleyBasedEraConway -> SimpleScriptInConway

eraOfScriptLanguageInEra
:: ScriptLanguageInEra lang era
-> ShelleyBasedEra era
eraOfScriptLanguageInEra langInEra =
case langInEra of
SimpleScriptInShelley -> ShelleyBasedEraShelley
SimpleScriptInAllegra -> ShelleyBasedEraAllegra
SimpleScriptInMary -> ShelleyBasedEraMary
SimpleScriptInAlonzo -> ShelleyBasedEraAlonzo
SimpleScriptInBabbage -> ShelleyBasedEraBabbage
SimpleScriptInConway -> ShelleyBasedEraConway
PlutusScriptV1InAlonzo -> ShelleyBasedEraAlonzo
PlutusScriptV1InBabbage -> ShelleyBasedEraBabbage
PlutusScriptV1InConway -> ShelleyBasedEraConway
PlutusScriptV2InBabbage -> ShelleyBasedEraBabbage
PlutusScriptV2InConway -> ShelleyBasedEraConway
PlutusScriptV3InConway -> ShelleyBasedEraConway
eraOfScriptLanguageInEra = \case
SimpleScriptInShelley -> ShelleyBasedEraShelley
SimpleScriptInAllegra -> ShelleyBasedEraAllegra
SimpleScriptInMary -> ShelleyBasedEraMary
SimpleScriptInAlonzo -> ShelleyBasedEraAlonzo
SimpleScriptInBabbage -> ShelleyBasedEraBabbage
SimpleScriptInConway -> ShelleyBasedEraConway
PlutusScriptV1InAlonzo -> ShelleyBasedEraAlonzo
PlutusScriptV1InBabbage -> ShelleyBasedEraBabbage
PlutusScriptV1InConway -> ShelleyBasedEraConway
PlutusScriptV2InBabbage -> ShelleyBasedEraBabbage
PlutusScriptV2InConway -> ShelleyBasedEraConway
PlutusScriptV3InConway -> ShelleyBasedEraConway

-- | Given a target era and a script in some language, check if the language is
-- supported in that era, and if so return a 'ScriptInEra'.
Expand Down
1 change: 0 additions & 1 deletion cardano-api/internal/Cardano/Api/Tx/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,6 @@ validateTxBodyContent
, txInsCollateral
, txOuts
, txProtocolParams
, txMintValue
, txMetadata
} =
let witnesses = collectTxBodyScriptWitnesses sbe txBodContent
Expand Down
1 change: 1 addition & 0 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ module Cardano.Api
-- ** Languages supported in each era
, ScriptLanguageInEra (..)
, scriptLanguageSupportedInEra
, sbeToSimpleScriptLanguageInEra
, languageOfScriptLanguageInEra
, eraOfScriptLanguageInEra

Expand Down

0 comments on commit 0595e7e

Please sign in to comment.