{-# LANGUAGE LambdaCase #-}
module PlutusLedgerApi.Common.Versions
( module PlutusLedgerApi.Common.ProtocolVersions
, LedgerPlutusVersion (..)
, languageIntroducedIn
, languagesAvailableIn
, builtinsIntroducedIn
, builtinsAvailableIn
) where
import PlutusCore
import PlutusLedgerApi.Common.ProtocolVersions
import PlutusPrelude
import Data.Map qualified as Map
import Data.Set qualified as Set
import Prettyprinter
data LedgerPlutusVersion =
PlutusV1
| PlutusV2
| PlutusV3
deriving stock (LedgerPlutusVersion -> LedgerPlutusVersion -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LedgerPlutusVersion -> LedgerPlutusVersion -> Bool
$c/= :: LedgerPlutusVersion -> LedgerPlutusVersion -> Bool
== :: LedgerPlutusVersion -> LedgerPlutusVersion -> Bool
$c== :: LedgerPlutusVersion -> LedgerPlutusVersion -> Bool
Eq, Eq LedgerPlutusVersion
LedgerPlutusVersion -> LedgerPlutusVersion -> Bool
LedgerPlutusVersion -> LedgerPlutusVersion -> Ordering
LedgerPlutusVersion -> LedgerPlutusVersion -> LedgerPlutusVersion
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: LedgerPlutusVersion -> LedgerPlutusVersion -> LedgerPlutusVersion
$cmin :: LedgerPlutusVersion -> LedgerPlutusVersion -> LedgerPlutusVersion
max :: LedgerPlutusVersion -> LedgerPlutusVersion -> LedgerPlutusVersion
$cmax :: LedgerPlutusVersion -> LedgerPlutusVersion -> LedgerPlutusVersion
>= :: LedgerPlutusVersion -> LedgerPlutusVersion -> Bool
$c>= :: LedgerPlutusVersion -> LedgerPlutusVersion -> Bool
> :: LedgerPlutusVersion -> LedgerPlutusVersion -> Bool
$c> :: LedgerPlutusVersion -> LedgerPlutusVersion -> Bool
<= :: LedgerPlutusVersion -> LedgerPlutusVersion -> Bool
$c<= :: LedgerPlutusVersion -> LedgerPlutusVersion -> Bool
< :: LedgerPlutusVersion -> LedgerPlutusVersion -> Bool
$c< :: LedgerPlutusVersion -> LedgerPlutusVersion -> Bool
compare :: LedgerPlutusVersion -> LedgerPlutusVersion -> Ordering
$ccompare :: LedgerPlutusVersion -> LedgerPlutusVersion -> Ordering
Ord, Int -> LedgerPlutusVersion -> ShowS
[LedgerPlutusVersion] -> ShowS
LedgerPlutusVersion -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LedgerPlutusVersion] -> ShowS
$cshowList :: [LedgerPlutusVersion] -> ShowS
show :: LedgerPlutusVersion -> String
$cshow :: LedgerPlutusVersion -> String
showsPrec :: Int -> LedgerPlutusVersion -> ShowS
$cshowsPrec :: Int -> LedgerPlutusVersion -> ShowS
Show, forall x. Rep LedgerPlutusVersion x -> LedgerPlutusVersion
forall x. LedgerPlutusVersion -> Rep LedgerPlutusVersion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LedgerPlutusVersion x -> LedgerPlutusVersion
$cfrom :: forall x. LedgerPlutusVersion -> Rep LedgerPlutusVersion x
Generic, Int -> LedgerPlutusVersion
LedgerPlutusVersion -> Int
LedgerPlutusVersion -> [LedgerPlutusVersion]
LedgerPlutusVersion -> LedgerPlutusVersion
LedgerPlutusVersion -> LedgerPlutusVersion -> [LedgerPlutusVersion]
LedgerPlutusVersion
-> LedgerPlutusVersion
-> LedgerPlutusVersion
-> [LedgerPlutusVersion]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: LedgerPlutusVersion
-> LedgerPlutusVersion
-> LedgerPlutusVersion
-> [LedgerPlutusVersion]
$cenumFromThenTo :: LedgerPlutusVersion
-> LedgerPlutusVersion
-> LedgerPlutusVersion
-> [LedgerPlutusVersion]
enumFromTo :: LedgerPlutusVersion -> LedgerPlutusVersion -> [LedgerPlutusVersion]
$cenumFromTo :: LedgerPlutusVersion -> LedgerPlutusVersion -> [LedgerPlutusVersion]
enumFromThen :: LedgerPlutusVersion -> LedgerPlutusVersion -> [LedgerPlutusVersion]
$cenumFromThen :: LedgerPlutusVersion -> LedgerPlutusVersion -> [LedgerPlutusVersion]
enumFrom :: LedgerPlutusVersion -> [LedgerPlutusVersion]
$cenumFrom :: LedgerPlutusVersion -> [LedgerPlutusVersion]
fromEnum :: LedgerPlutusVersion -> Int
$cfromEnum :: LedgerPlutusVersion -> Int
toEnum :: Int -> LedgerPlutusVersion
$ctoEnum :: Int -> LedgerPlutusVersion
pred :: LedgerPlutusVersion -> LedgerPlutusVersion
$cpred :: LedgerPlutusVersion -> LedgerPlutusVersion
succ :: LedgerPlutusVersion -> LedgerPlutusVersion
$csucc :: LedgerPlutusVersion -> LedgerPlutusVersion
Enum, LedgerPlutusVersion
forall a. a -> a -> Bounded a
maxBound :: LedgerPlutusVersion
$cmaxBound :: LedgerPlutusVersion
minBound :: LedgerPlutusVersion
$cminBound :: LedgerPlutusVersion
Bounded)
instance Pretty LedgerPlutusVersion where
pretty :: forall ann. LedgerPlutusVersion -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
viaShow
builtinsIntroducedIn :: Map.Map (LedgerPlutusVersion, ProtocolVersion) (Set.Set DefaultFun)
builtinsIntroducedIn :: Map (LedgerPlutusVersion, ProtocolVersion) (Set DefaultFun)
builtinsIntroducedIn = forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [
((LedgerPlutusVersion
PlutusV1, ProtocolVersion
alonzoPV), forall a. Ord a => [a] -> Set a
Set.fromList [
DefaultFun
AddInteger, DefaultFun
SubtractInteger, DefaultFun
MultiplyInteger, DefaultFun
DivideInteger, DefaultFun
QuotientInteger, DefaultFun
RemainderInteger, DefaultFun
ModInteger, DefaultFun
EqualsInteger, DefaultFun
LessThanInteger, DefaultFun
LessThanEqualsInteger,
DefaultFun
AppendByteString, DefaultFun
ConsByteString, DefaultFun
SliceByteString, DefaultFun
LengthOfByteString, DefaultFun
IndexByteString, DefaultFun
EqualsByteString, DefaultFun
LessThanByteString, DefaultFun
LessThanEqualsByteString,
DefaultFun
Sha2_256, DefaultFun
Sha3_256, DefaultFun
Blake2b_256, DefaultFun
VerifyEd25519Signature,
DefaultFun
AppendString, DefaultFun
EqualsString, DefaultFun
EncodeUtf8, DefaultFun
DecodeUtf8,
DefaultFun
IfThenElse,
DefaultFun
ChooseUnit,
DefaultFun
Trace,
DefaultFun
FstPair, DefaultFun
SndPair,
DefaultFun
ChooseList, DefaultFun
MkCons, DefaultFun
HeadList, DefaultFun
TailList, DefaultFun
NullList,
DefaultFun
ChooseData, DefaultFun
ConstrData, DefaultFun
MapData, DefaultFun
ListData, DefaultFun
IData, DefaultFun
BData, DefaultFun
UnConstrData, DefaultFun
UnMapData, DefaultFun
UnListData, DefaultFun
UnIData, DefaultFun
UnBData, DefaultFun
EqualsData,
DefaultFun
MkPairData, DefaultFun
MkNilData, DefaultFun
MkNilPairData
]),
((LedgerPlutusVersion
PlutusV2, ProtocolVersion
vasilPV), forall a. Ord a => [a] -> Set a
Set.fromList [
DefaultFun
SerialiseData
]),
((LedgerPlutusVersion
PlutusV2, ProtocolVersion
changPV), forall a. Ord a => [a] -> Set a
Set.fromList [
DefaultFun
VerifyEcdsaSecp256k1Signature, DefaultFun
VerifySchnorrSecp256k1Signature
])
]
languageIntroducedIn :: LedgerPlutusVersion -> ProtocolVersion
languageIntroducedIn :: LedgerPlutusVersion -> ProtocolVersion
languageIntroducedIn = \case
LedgerPlutusVersion
PlutusV1 -> ProtocolVersion
alonzoPV
LedgerPlutusVersion
PlutusV2 -> ProtocolVersion
vasilPV
LedgerPlutusVersion
PlutusV3 -> ProtocolVersion
changPV
languagesAvailableIn :: ProtocolVersion -> Set.Set LedgerPlutusVersion
languagesAvailableIn :: ProtocolVersion -> Set LedgerPlutusVersion
languagesAvailableIn ProtocolVersion
searchPv =
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap LedgerPlutusVersion -> Set LedgerPlutusVersion
ledgerVersionToSet forall a. (Enum a, Bounded a) => [a]
enumerate
where
ledgerVersionToSet :: LedgerPlutusVersion -> Set.Set LedgerPlutusVersion
ledgerVersionToSet :: LedgerPlutusVersion -> Set LedgerPlutusVersion
ledgerVersionToSet LedgerPlutusVersion
lv
| LedgerPlutusVersion -> ProtocolVersion
languageIntroducedIn LedgerPlutusVersion
lv forall a. Ord a => a -> a -> Bool
<= ProtocolVersion
searchPv = forall a. a -> Set a
Set.singleton LedgerPlutusVersion
lv
| Bool
otherwise = forall a. Monoid a => a
mempty
builtinsAvailableIn :: LedgerPlutusVersion -> ProtocolVersion -> Set.Set DefaultFun
builtinsAvailableIn :: LedgerPlutusVersion -> ProtocolVersion -> Set DefaultFun
builtinsAvailableIn LedgerPlutusVersion
thisLv ProtocolVersion
thisPv = forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [a]
Map.elems forall a b. (a -> b) -> a -> b
$
forall k a. (k -> Bool) -> Map k a -> Map k a
Map.takeWhileAntitone (LedgerPlutusVersion, ProtocolVersion) -> Bool
builtinAvailableIn Map (LedgerPlutusVersion, ProtocolVersion) (Set DefaultFun)
builtinsIntroducedIn
where
builtinAvailableIn :: (LedgerPlutusVersion, ProtocolVersion) -> Bool
builtinAvailableIn :: (LedgerPlutusVersion, ProtocolVersion) -> Bool
builtinAvailableIn (LedgerPlutusVersion
introducedInLv,ProtocolVersion
introducedInPv) =
LedgerPlutusVersion
introducedInLv forall a. Ord a => a -> a -> Bool
<= LedgerPlutusVersion
thisLv Bool -> Bool -> Bool
&& ProtocolVersion
introducedInPv forall a. Ord a => a -> a -> Bool
<= ProtocolVersion
thisPv