-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Classy versions of Era witness functions
- Loading branch information
1 parent
0c3c7af
commit 058936a
Showing
8 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
cardano-api/internal/Cardano/Api/Class/HasScriptLanguageInEra.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
|
||
module Cardano.Api.Class.HasScriptLanguageInEra where | ||
|
||
import Cardano.Api.Eras (AlonzoEra, BabbageEra, ConwayEra) | ||
import Cardano.Api.Script (PlutusScriptV1, PlutusScriptV2, PlutusScriptV3, ScriptLanguageInEra (..)) | ||
|
||
-- | Smart-constructor for 'ScriptLanguageInEra' to write functions | ||
-- manipulating scripts that do not commit to a particular era. | ||
class HasScriptLanguageInEra lang era where | ||
scriptLanguageInEra :: ScriptLanguageInEra lang era | ||
|
||
instance HasScriptLanguageInEra PlutusScriptV1 AlonzoEra where | ||
scriptLanguageInEra = PlutusScriptV1InAlonzo | ||
|
||
instance HasScriptLanguageInEra PlutusScriptV1 BabbageEra where | ||
scriptLanguageInEra = PlutusScriptV1InBabbage | ||
|
||
instance HasScriptLanguageInEra PlutusScriptV2 BabbageEra where | ||
scriptLanguageInEra = PlutusScriptV2InBabbage | ||
|
||
instance HasScriptLanguageInEra PlutusScriptV1 ConwayEra where | ||
scriptLanguageInEra = PlutusScriptV1InConway | ||
|
||
instance HasScriptLanguageInEra PlutusScriptV2 ConwayEra where | ||
scriptLanguageInEra = PlutusScriptV2InConway | ||
|
||
instance HasScriptLanguageInEra PlutusScriptV3 ConwayEra where | ||
scriptLanguageInEra = PlutusScriptV3InConway |
24 changes: 24 additions & 0 deletions
24
cardano-api/internal/Cardano/Api/Class/IsAllegraEraOnwards.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Cardano.Api.Class.IsAllegraEraOnwards where | ||
|
||
import Cardano.Api.Eon.AllegraEraOnwards (AllegraEraOnwards (..)) | ||
import Cardano.Api.Eras (AllegraEra, AlonzoEra, BabbageEra, ConwayEra, MaryEra) | ||
|
||
-- | Type class to produce 'AllegraEraOnwards' witness values while staying | ||
-- parameterized by era. | ||
class IsAllegraEraOnwards era where | ||
allegraEraOnwards :: AllegraEraOnwards era | ||
|
||
instance IsAllegraEraOnwards AllegraEra where | ||
allegraEraOnwards = AllegraEraOnwardsAllegra | ||
|
||
instance IsAllegraEraOnwards MaryEra where | ||
allegraEraOnwards = AllegraEraOnwardsMary | ||
|
||
instance IsAllegraEraOnwards AlonzoEra where | ||
allegraEraOnwards = AllegraEraOnwardsAlonzo | ||
|
||
instance IsAllegraEraOnwards BabbageEra where | ||
allegraEraOnwards = AllegraEraOnwardsBabbage | ||
|
||
instance IsAllegraEraOnwards ConwayEra where | ||
allegraEraOnwards = AllegraEraOnwardsConway |
18 changes: 18 additions & 0 deletions
18
cardano-api/internal/Cardano/Api/Class/IsAlonzoEraOnwards.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Cardano.Api.Class.IsAlonzoEraOnwards where | ||
|
||
import Cardano.Api.Eon.AlonzoEraOnwards (AlonzoEraOnwards (..)) | ||
import Cardano.Api.Eras (AlonzoEra, BabbageEra, ConwayEra) | ||
|
||
-- | Type class to produce 'AlonzoEraOnwards' witness values while staying | ||
-- parameterized by era. | ||
class IsAlonzoEraOnwards era where | ||
alonzoEraOnwards :: AlonzoEraOnwards era | ||
|
||
instance IsAlonzoEraOnwards AlonzoEra where | ||
alonzoEraOnwards = AlonzoEraOnwardsAlonzo | ||
|
||
instance IsAlonzoEraOnwards BabbageEra where | ||
alonzoEraOnwards = AlonzoEraOnwardsBabbage | ||
|
||
instance IsAlonzoEraOnwards ConwayEra where | ||
alonzoEraOnwards = AlonzoEraOnwardsConway |
15 changes: 15 additions & 0 deletions
15
cardano-api/internal/Cardano/Api/Class/IsBabbageEraOnwards.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Cardano.Api.Class.IsBabbageEraOnwards where | ||
|
||
import Cardano.Api.Eon.BabbageEraOnwards (BabbageEraOnwards (..)) | ||
import Cardano.Api.Eras (BabbageEra, ConwayEra) | ||
|
||
-- | Type class to produce 'BabbageEraOnwards' witness values while staying | ||
-- parameterized by era. | ||
class IsBabbageEraOnwards era where | ||
babbageEraOnwards :: BabbageEraOnwards era | ||
|
||
instance IsBabbageEraOnwards BabbageEra where | ||
babbageEraOnwards = BabbageEraOnwardsBabbage | ||
|
||
instance IsBabbageEraOnwards ConwayEra where | ||
babbageEraOnwards = BabbageEraOnwardsConway |
21 changes: 21 additions & 0 deletions
21
cardano-api/internal/Cardano/Api/Class/IsMaryEraOnwards.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Cardano.Api.Class.IsMaryEraOnwards where | ||
|
||
import Cardano.Api.Eras (AlonzoEra, BabbageEra, ConwayEra, MaryEra) | ||
import Cardano.Api.Eon.MaryEraOnwards (MaryEraOnwards (..)) | ||
|
||
-- | Type class to produce 'MaryEraOnwards' witness values while staying | ||
-- parameterized by era. | ||
class IsMaryEraOnwards era where | ||
maryEraOnwards :: MaryEraOnwards era | ||
|
||
instance IsMaryEraOnwards MaryEra where | ||
maryEraOnwards = MaryEraOnwardsMary | ||
|
||
instance IsMaryEraOnwards AlonzoEra where | ||
maryEraOnwards = MaryEraOnwardsAlonzo | ||
|
||
instance IsMaryEraOnwards BabbageEra where | ||
maryEraOnwards = MaryEraOnwardsBabbage | ||
|
||
instance IsMaryEraOnwards ConwayEra where | ||
maryEraOnwards = MaryEraOnwardsConway |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
module Cardano.Api.Class.ToAlonzoScript where | ||
|
||
import Cardano.Api.Eras (BabbageEra, ConwayEra) | ||
import Cardano.Api.Eon.ShelleyBasedEra (ShelleyLedgerEra) | ||
import Cardano.Api.Script as Script (PlutusScriptV1, PlutusScriptV2, PlutusScriptV3, PlutusScript(..)) | ||
import Cardano.Ledger.Alonzo.Scripts (AlonzoScript (..)) | ||
import Cardano.Ledger.Conway.Scripts (PlutusScript (..)) | ||
import Cardano.Ledger.Plutus.Language (Plutus (..), PlutusBinary (..)) | ||
|
||
class ToAlonzoScript lang era where | ||
toLedgerScript :: | ||
Script.PlutusScript lang -> | ||
AlonzoScript (ShelleyLedgerEra era) | ||
|
||
instance ToAlonzoScript PlutusScriptV1 BabbageEra where | ||
toLedgerScript (PlutusScriptSerialised bytes) = | ||
PlutusScript $ BabbagePlutusV1 $ Plutus $ PlutusBinary bytes | ||
|
||
instance ToAlonzoScript PlutusScriptV2 BabbageEra where | ||
toLedgerScript (PlutusScriptSerialised bytes) = | ||
PlutusScript $ BabbagePlutusV2 $ Plutus $ PlutusBinary bytes | ||
|
||
instance ToAlonzoScript PlutusScriptV1 ConwayEra where | ||
toLedgerScript (PlutusScriptSerialised bytes) = | ||
PlutusScript $ ConwayPlutusV1 $ Plutus $ PlutusBinary bytes | ||
|
||
instance ToAlonzoScript PlutusScriptV2 ConwayEra where | ||
toLedgerScript (PlutusScriptSerialised bytes) = | ||
PlutusScript $ ConwayPlutusV2 $ Plutus $ PlutusBinary bytes | ||
|
||
instance ToAlonzoScript PlutusScriptV3 ConwayEra where | ||
toLedgerScript (PlutusScriptSerialised bytes) = | ||
PlutusScript $ ConwayPlutusV3 $ Plutus $ PlutusBinary bytes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters