Skip to content

Commit ee59574

Browse files
committed
Good stopping point
1 parent 50702e6 commit ee59574

File tree

15 files changed

+1201
-56
lines changed

15 files changed

+1201
-56
lines changed

cardano-api/cardano-api.cabal

+7-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ library
7777
Cardano.Api.Internal.Eon.ShelleyBasedEra
7878
Cardano.Api.Internal.Eras
7979
Cardano.Api.Internal.Error
80-
Cardano.Api.Internal.Experimental.Eras
81-
Cardano.Api.Internal.Experimental.Tx
8280
Cardano.Api.Internal.Fees
8381
Cardano.Api.Internal.Genesis
8482
Cardano.Api.Internal.GenesisParameters
@@ -200,6 +198,12 @@ library
200198
Cardano.Api.Internal.Eon.ShelleyToMaryEra
201199
Cardano.Api.Internal.Eras.Case
202200
Cardano.Api.Internal.Eras.Core
201+
Cardano.Api.Internal.Experimental.Eras
202+
Cardano.Api.Internal.Experimental.Plutus.Shim.LegacyScripts
203+
Cardano.Api.Internal.Experimental.Plutus.Script
204+
Cardano.Api.Internal.Experimental.Plutus.ScriptWitness
205+
Cardano.Api.Internal.Experimental.Simple.Script
206+
Cardano.Api.Internal.Experimental.Tx
203207
Cardano.Api.Internal.Feature
204208
Cardano.Api.Internal.Governance.Actions.ProposalProcedure
205209
Cardano.Api.Internal.Governance.Actions.VotingProcedure
@@ -248,6 +252,7 @@ library
248252
Cardano.Api.Internal.SerialiseUsing
249253
Cardano.Api.Internal.SpecialByron
250254
Cardano.Api.Internal.StakePoolMetadata
255+
Cardano.Api.Internal.Tx.BuildTxWith
251256
Cardano.Api.Internal.Tx.UTxO
252257
Cardano.Api.Internal.TxIn
253258
Cardano.Api.Internal.TxMetadata

cardano-api/src/Cardano/Api/Internal/Certificate.hs

+36-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
{-# LANGUAGE StandaloneDeriving #-}
1111
{-# LANGUAGE TypeApplications #-}
1212
{-# LANGUAGE TypeFamilies #-}
13+
{-# LANGUAGE TypeOperators #-}
1314

1415
-- | Certificates embedded in transactions
1516
module Cardano.Api.Internal.Certificate
@@ -111,6 +112,7 @@ import Data.Maybe
111112
import Data.Text (Text)
112113
import Data.Text qualified as Text
113114
import Data.Text.Encoding qualified as Text
115+
import Data.Type.Equality (TestEquality (..))
114116
import Data.Typeable
115117
import GHC.Exts (IsList (..), fromString)
116118
import Network.Socket (PortNumber)
@@ -129,13 +131,15 @@ data Certificate era where
129131
-- 6. Genesis delegation
130132
-- 7. MIR certificates
131133
ShelleyRelatedCertificate
132-
:: ShelleyToBabbageEra era
134+
:: Typeable era
135+
=> ShelleyToBabbageEra era
133136
-> Ledger.ShelleyTxCert (ShelleyLedgerEra era)
134137
-> Certificate era
135138
-- Conway onwards
136139
-- TODO: Add comments about the new types of certificates
137140
ConwayCertificate
138-
:: ConwayEraOnwards era
141+
:: Typeable era
142+
=> ConwayEraOnwards era
139143
-> Ledger.ConwayTxCert (ShelleyLedgerEra era)
140144
-> Certificate era
141145
deriving anyclass SerialiseAsCBOR
@@ -146,6 +150,27 @@ deriving instance Ord (Certificate era)
146150

147151
deriving instance Show (Certificate era)
148152

153+
instance TestEquality Certificate where
154+
testEquality (ShelleyRelatedCertificate _ c) (ShelleyRelatedCertificate _ c') =
155+
shelleyCertTypeEquality c c'
156+
testEquality (ConwayCertificate _ c) (ConwayCertificate _ c') =
157+
conwayCertTypeEquality c c'
158+
testEquality _ _ = Nothing
159+
160+
conwayCertTypeEquality
161+
:: (Typeable eraA, Typeable eraB)
162+
=> Ledger.ConwayTxCert (ShelleyLedgerEra eraA)
163+
-> Ledger.ConwayTxCert (ShelleyLedgerEra eraB)
164+
-> Maybe (eraA :~: eraB)
165+
conwayCertTypeEquality _ _ = eqT
166+
167+
shelleyCertTypeEquality
168+
:: (Typeable eraA, Typeable eraB)
169+
=> Ledger.ShelleyTxCert (ShelleyLedgerEra eraA)
170+
-> Ledger.ShelleyTxCert (ShelleyLedgerEra eraB)
171+
-> Maybe (eraA :~: eraB)
172+
shelleyCertTypeEquality _ _ = eqT
173+
149174
instance Typeable era => HasTypeProxy (Certificate era) where
150175
data AsType (Certificate era) = AsCertificate
151176
proxyToAsType _ = AsCertificate
@@ -373,7 +398,8 @@ data GenesisKeyDelegationRequirements era where
373398
-> Hash VrfKey
374399
-> GenesisKeyDelegationRequirements era
375400

376-
makeGenesisKeyDelegationCertificate :: GenesisKeyDelegationRequirements era -> Certificate era
401+
makeGenesisKeyDelegationCertificate
402+
:: Typeable era => GenesisKeyDelegationRequirements era -> Certificate era
377403
makeGenesisKeyDelegationCertificate
378404
( GenesisKeyDelegationRequirements
379405
atMostEra
@@ -394,7 +420,7 @@ data MirCertificateRequirements era where
394420
-> MirCertificateRequirements era
395421

396422
makeMIRCertificate
397-
:: ()
423+
:: Typeable era
398424
=> MirCertificateRequirements era
399425
-> Certificate era
400426
makeMIRCertificate (MirCertificateRequirements atMostEra mirPot mirTarget) =
@@ -410,7 +436,7 @@ data DRepRegistrationRequirements era where
410436
-> DRepRegistrationRequirements era
411437

412438
makeDrepRegistrationCertificate
413-
:: ()
439+
:: Typeable era
414440
=> DRepRegistrationRequirements era
415441
-> Maybe (Ledger.Anchor (EraCrypto (ShelleyLedgerEra era)))
416442
-> Certificate era
@@ -427,7 +453,7 @@ data CommitteeHotKeyAuthorizationRequirements era where
427453
-> CommitteeHotKeyAuthorizationRequirements era
428454

429455
makeCommitteeHotKeyAuthorizationCertificate
430-
:: ()
456+
:: Typeable era
431457
=> CommitteeHotKeyAuthorizationRequirements era
432458
-> Certificate era
433459
makeCommitteeHotKeyAuthorizationCertificate (CommitteeHotKeyAuthorizationRequirements cOnwards coldKeyCredential hotKeyCredential) =
@@ -443,7 +469,7 @@ data CommitteeColdkeyResignationRequirements era where
443469
-> CommitteeColdkeyResignationRequirements era
444470

445471
makeCommitteeColdkeyResignationCertificate
446-
:: ()
472+
:: Typeable era
447473
=> CommitteeColdkeyResignationRequirements era
448474
-> Certificate era
449475
makeCommitteeColdkeyResignationCertificate (CommitteeColdkeyResignationRequirements cOnwards coldKeyCred anchor) =
@@ -461,7 +487,7 @@ data DRepUnregistrationRequirements era where
461487
-> DRepUnregistrationRequirements era
462488

463489
makeDrepUnregistrationCertificate
464-
:: ()
490+
:: Typeable era
465491
=> DRepUnregistrationRequirements era
466492
-> Certificate era
467493
makeDrepUnregistrationCertificate (DRepUnregistrationRequirements conwayOnwards vcred deposit) =
@@ -488,7 +514,8 @@ data DRepUpdateRequirements era where
488514
-> DRepUpdateRequirements era
489515

490516
makeDrepUpdateCertificate
491-
:: DRepUpdateRequirements era
517+
:: Typeable era
518+
=> DRepUpdateRequirements era
492519
-> Maybe (Ledger.Anchor (EraCrypto (ShelleyLedgerEra era)))
493520
-> Certificate era
494521
makeDrepUpdateCertificate (DRepUpdateRequirements conwayOnwards vcred) mAnchor =

cardano-api/src/Cardano/Api/Internal/Eon/AlonzoEraOnwards.hs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import Cardano.Binary
2929
import Cardano.Crypto.Hash.Blake2b qualified as Blake2b
3030
import Cardano.Crypto.Hash.Class qualified as C
3131
import Cardano.Crypto.VRF qualified as C
32+
import Cardano.Ledger.Allegra.Scripts qualified as L
3233
import Cardano.Ledger.Alonzo.Plutus.Context qualified as Plutus
3334
import Cardano.Ledger.Alonzo.Scripts qualified as L
3435
import Cardano.Ledger.Alonzo.Tx qualified as L
@@ -103,6 +104,7 @@ type AlonzoEraOnwardsConstraints era =
103104
, L.EraUTxO (ShelleyLedgerEra era)
104105
, L.HashAnnotated (L.TxBody (ShelleyLedgerEra era)) L.EraIndependentTxBody L.StandardCrypto
105106
, L.MaryEraTxBody (ShelleyLedgerEra era)
107+
, L.NativeScript (ShelleyLedgerEra era) ~ L.Timelock (ShelleyLedgerEra era)
106108
, Plutus.EraPlutusContext (ShelleyLedgerEra era)
107109
, L.Script (ShelleyLedgerEra era) ~ L.AlonzoScript (ShelleyLedgerEra era)
108110
, L.ScriptsNeeded (ShelleyLedgerEra era) ~ L.AlonzoScriptsNeeded (ShelleyLedgerEra era)

cardano-api/src/Cardano/Api/Internal/Experimental/Eras.hs

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module Cardano.Api.Internal.Experimental.Eras
3232
)
3333
where
3434

35+
import Cardano.Api.Internal.Eon.AlonzoEraOnwards
3536
import Cardano.Api.Internal.Eon.BabbageEraOnwards
3637
import Cardano.Api.Internal.Eon.Convert
3738
import Cardano.Api.Internal.Eon.ShelleyBasedEra (ShelleyBasedEra (..), ShelleyLedgerEra)
@@ -206,6 +207,11 @@ instance Convert Era ShelleyBasedEra where
206207
BabbageEra -> ShelleyBasedEraBabbage
207208
ConwayEra -> ShelleyBasedEraConway
208209

210+
instance Convert Era AlonzoEraOnwards where
211+
convert = \case
212+
BabbageEra -> AlonzoEraOnwardsBabbage
213+
ConwayEra -> AlonzoEraOnwardsConway
214+
209215
instance Convert Era BabbageEraOnwards where
210216
convert = \case
211217
BabbageEra -> BabbageEraOnwardsBabbage
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE FlexibleContexts #-}
3+
{-# LANGUAGE GADTs #-}
4+
{-# LANGUAGE KindSignatures #-}
5+
{-# LANGUAGE StandaloneDeriving #-}
6+
7+
module Cardano.Api.Internal.Experimental.Plutus.Script
8+
( PlutusScriptInEra (..)
9+
, PlutusScriptOrReferenceInput (..)
10+
)
11+
where
12+
13+
import Cardano.Api.Internal.TxIn (TxIn)
14+
15+
import Cardano.Ledger.Plutus.Language (PlutusRunnable)
16+
import Cardano.Ledger.Plutus.Language qualified as L
17+
18+
-- | A Plutus script in a particular era.
19+
-- Why PlutusRunnable? Mainly for deserialization benefits.
20+
-- The deserialization of this type looks at the
21+
-- major protocol version and the script language to determine if
22+
-- indeed the script is runnable. This is a dramatic improvement over the old api
23+
-- which essentially read a 'ByteString'. Any failures due to malformed/invalid scripts
24+
-- were caught upon transaction submission or running the script when attempting to
25+
-- predict the necessary execution units.
26+
--
27+
-- Where do we get the major protocol version from?
28+
-- In order to access the major protocol version we pass in an 'era` type parameter which
29+
-- can be translated to the major protocol version.
30+
--
31+
-- Where do we get the script language from?
32+
-- The serialized version of 'PlutusRunnable' encodes the script language.
33+
-- See `DecCBOR (PlutusRunnable l)` in cardano-ledger for more details.
34+
data PlutusScriptInEra (lang :: L.Language) era where
35+
PlutusScriptInEra
36+
:: PlutusRunnable lang -> PlutusScriptInEra lang era
37+
38+
deriving instance Show (PlutusScriptInEra lang era)
39+
40+
-- :: IsEra era => PlutusRunnable lang -> PlutusScriptInEra lang era
41+
42+
-- | You can provide the plutus script directly in the transaction
43+
-- or a reference input that points to the script in the UTxO.
44+
-- Using a reference script saves space in your transaction.
45+
data PlutusScriptOrReferenceInput lang era
46+
= PScript (PlutusScriptInEra lang era)
47+
| PReferenceScript TxIn
48+
deriving Show

0 commit comments

Comments
 (0)