-
Notifications
You must be signed in to change notification settings - Fork 155
/
Scripts.hs
65 lines (57 loc) · 2.14 KB
/
Scripts.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-orphans #-}
-- | Figure 3: Functions related to scripts
-- Babbage Specification
module Cardano.Ledger.Babbage.Scripts (
AlonzoScript (..),
isPlutusScript,
babbageScriptPrefixTag,
)
where
import Cardano.Ledger.Allegra.Scripts (Timelock)
import Cardano.Ledger.Alonzo.Language
import Cardano.Ledger.Alonzo.Scripts (AlonzoScript (..))
import Cardano.Ledger.Alonzo.TxAuxData (
AlonzoTxAuxData,
hashAlonzoTxAuxData,
validateAlonzoTxAuxData,
)
import Cardano.Ledger.Babbage.Era
import Cardano.Ledger.Core
import qualified Cardano.Ledger.Crypto as CC
import Cardano.Ledger.Shelley.Scripts (nativeMultiSigTag)
import Data.ByteString (ByteString)
import Data.ByteString.Short (ShortByteString)
babbageScriptPrefixTag ::
Script era ~ AlonzoScript era => Script era -> ByteString
babbageScriptPrefixTag script =
case script of
TimelockScript _ -> nativeMultiSigTag -- "\x00"
PlutusScript PlutusV1 _ -> "\x01"
PlutusScript PlutusV2 _ -> "\x02"
PlutusScript PlutusV3 _ -> "\x03"
type instance SomeScript 'PhaseOne (BabbageEra c) = Timelock (BabbageEra c)
type instance SomeScript 'PhaseTwo (BabbageEra c) = (Language, ShortByteString)
instance CC.Crypto c => EraScript (BabbageEra c) where
type Script (BabbageEra c) = AlonzoScript (BabbageEra c)
scriptPrefixTag = babbageScriptPrefixTag
phaseScript PhaseOneRep (TimelockScript s) = Just (Phase1Script s)
phaseScript PhaseTwoRep (PlutusScript lang bytes) = Just (Phase2Script lang bytes)
phaseScript _ _ = Nothing
isPlutusScript :: forall era. EraScript era => Script era -> Bool
isPlutusScript x =
case phaseScript @era PhaseTwoRep x of
Just _ -> True
Nothing -> False
instance CC.Crypto c => EraTxAuxData (BabbageEra c) where
type TxAuxData (BabbageEra c) = AlonzoTxAuxData (BabbageEra c)
hashTxAuxData = hashAlonzoTxAuxData
validateTxAuxData = validateAlonzoTxAuxData