@@ -276,6 +276,7 @@ getAnyWitnessScriptData eon (AnyPlutusScriptWitness (PlutusScriptWitness l _ scr
276
276
Nothing -> alonzoEraOnwardsConstraints eon mempty
277
277
Just d -> alonzoEraOnwardsConstraints eon $ L. TxDats $ fromList [(L. hashData d, d)]
278
278
279
+ -- | This type collects all the requirements for script witnesses in a transaction.
279
280
data TxScriptWitnessRequirements era
280
281
= TxScriptWitnessRequirements
281
282
(Set L. Language )
@@ -331,10 +332,6 @@ obtainMonoidConstraint eon = case eon of
331
332
AlonzoEraOnwardsBabbage -> id
332
333
AlonzoEraOnwardsConway -> id
333
334
334
- -- So how would the new api look? We would paramterize on data Era and
335
- -- always have two cases instead of multipl cases
336
- -- We could also parameterize on the IsEra era type class for exposed functions
337
-
338
335
getAnyWitnessScript
339
336
:: ShelleyBasedEra era -> AnyWitness (ShelleyLedgerEra era ) -> Maybe (L. Script (ShelleyLedgerEra era ))
340
337
getAnyWitnessScript _ AnyKeyWitness = Nothing
@@ -361,38 +358,37 @@ fromPlutusRunnable
361
358
-> AlonzoEraOnwards era
362
359
-> L. PlutusRunnable lang
363
360
-> Maybe (L. PlutusScript (ShelleyLedgerEra era ))
364
- fromPlutusRunnable l @ L. SPlutusV1 eon runnable =
361
+ fromPlutusRunnable L. SPlutusV1 eon runnable =
365
362
case eon of
366
363
AlonzoEraOnwardsAlonzo ->
367
- let plutusScript = plutusFromRunnableAssist l runnable
364
+ let plutusScript = L. plutusFromRunnable runnable
368
365
in Just $ L. AlonzoPlutusV1 plutusScript
369
366
AlonzoEraOnwardsBabbage ->
370
- let plutusScript = plutusFromRunnableAssist l runnable
367
+ let plutusScript = L. plutusFromRunnable runnable
371
368
in Just $ L. BabbagePlutusV1 plutusScript
372
369
AlonzoEraOnwardsConway ->
373
- let plutusScript = plutusFromRunnableAssist l runnable
370
+ let plutusScript = L. plutusFromRunnable runnable
374
371
in Just $ L. ConwayPlutusV1 plutusScript
375
- fromPlutusRunnable l @ L. SPlutusV2 eon runnable =
372
+ fromPlutusRunnable L. SPlutusV2 eon runnable =
376
373
case eon of
377
374
AlonzoEraOnwardsAlonzo -> Nothing
378
375
AlonzoEraOnwardsBabbage ->
379
- let plutusScript = plutusFromRunnableAssist l runnable
376
+ let plutusScript = L. plutusFromRunnable runnable
380
377
in Just $ L. BabbagePlutusV2 plutusScript
381
378
AlonzoEraOnwardsConway ->
382
- let plutusScript = plutusFromRunnableAssist l runnable
379
+ let plutusScript = L. plutusFromRunnable runnable
383
380
in Just $ L. ConwayPlutusV2 plutusScript
384
- fromPlutusRunnable l @ L. SPlutusV3 eon runnable =
381
+ fromPlutusRunnable L. SPlutusV3 eon runnable =
385
382
case eon of
386
383
AlonzoEraOnwardsAlonzo -> Nothing
387
384
AlonzoEraOnwardsBabbage -> Nothing
388
385
AlonzoEraOnwardsConway ->
389
- let plutusScript = plutusFromRunnableAssist l runnable
386
+ let plutusScript = L. plutusFromRunnable runnable
390
387
in Just $ L. ConwayPlutusV3 plutusScript
391
388
392
- -- Created purely to help type inference
393
- plutusFromRunnableAssist :: L. SLanguage lang -> L. PlutusRunnable lang -> L. Plutus lang
394
- plutusFromRunnableAssist _ = L. plutusFromRunnable
395
-
389
+ -- | These are all of the "things" a plutus script can witness. We include the relevant
390
+ -- type class constraint to avoid boilerplate when creating the 'PlutusPurpose' in
391
+ -- the 'GetPlutusScriptPurpose' instances.
396
392
data Witnessable thing era where
397
393
WitTxIn :: L. AlonzoEraScript era => TxIn -> Witnessable TxIn era
398
394
WitTxCert :: L. AlonzoEraScript era => Cert -> Witnessable Cert era
@@ -418,14 +414,16 @@ type Voter = Api.AnyVoter
418
414
419
415
type Proposal = Api. AnyProposal
420
416
421
- -- | In order to reduce boilerplate we reuse cardano-ledger's PlutusPurpose type. This
422
- -- type is used in the construction of the redeemer pointers map. The redeemer pointers map
423
- -- connects the redeemer and execution units to the thing being witnessed. The map is
424
- -- indexed by redeemer pointer!
425
- -- So the natural question is how do the Plutus script witnesses know what
426
- -- execution units and redeemer is paired with it? The ledger constructs a pointer
427
- -- for every Plutus script and this pointer corresponds to the pointer constructed
428
- -- in the redeemer pointer map. See 'collectPlutusScriptsWithContext' in 'cardano-ledger'.
417
+ -- | To reduce boilerplate, we reuse the `PlutusPurpose` type from `cardano-ledger`.
418
+ -- This type is utilized in constructing the redeemer pointers map, which
419
+ -- links the redeemer and execution units with the entity being witnessed.
420
+ -- The map is indexed by the redeemer pointer.
421
+ --
422
+ -- A natural question arises: How do Plutus scripts determine which
423
+ -- execution units and redeemer are paired with them? The ledger constructs a redeemer pointer
424
+ -- for every Plutus script, and this pointer corresponds to the one in the transaction's
425
+ -- redeemer pointers map. For more details, refer to `collectPlutusScriptsWithContext`
426
+ -- in `cardano-ledger`.
429
427
class GetPlutusScriptPurpose era where
430
428
toPlutusScriptPurpose
431
429
:: Word32
@@ -466,17 +464,8 @@ createIndexedPlutusScriptWitnesses witnessableThings =
466
464
| (index, (thing, AnyPlutusScriptWitness sWit)) <- zip [0 .. ] witnessableThings
467
465
]
468
466
469
- {-
470
- The transaction redeemer pointer map allows the ledger to connect a redeemer and execution unit pairing to the relevant
471
- script. The ledger basically reconstructs the indicies of this map can then look up the relevant pairing.
472
- -}
473
- -- This is the smoking gun. The truth is in Conway votes and proposals were introduced.
474
- -- Therefore only in conway we should be allowed to get votes and props being paired with
475
- -- witnesses. Can we express this in the type system? Witnessable will have to be parameterized
476
- -- on era and we would need a type family to enforce this relation ship
477
- -- Witnessable era witnessable -> AnyWitness era -> (Witnessable era witnessable, AnyWitness era)
478
- -- And we can be explict about the pairings! We would need the result type of the family to be CanBePaired era witnessable
479
-
467
+ -- | The transaction redeemer pointer map allows the ledger to connect a redeemer and execution unit pairing to the relevant
468
+ -- script. The ledger basically reconstructs the indicies of this map can then look up the relevant pairing.
480
469
getAnyWitnessRedeemerPointerMap
481
470
:: AlonzoEraOnwards era
482
471
-> (Witnessable witnessable (ShelleyLedgerEra era ), AnyWitness (ShelleyLedgerEra era ))
@@ -505,10 +494,6 @@ constructRedeemerPointer eon (AnyIndexedPlutusScriptWitness (IndexedPlutusScript
505
494
L. Redeemers $
506
495
fromList [(purpose, (toAlonzoData redeemer, toAlonzoExUnits execUnits))]
507
496
508
- ----------------------------------------------
509
- -- TEST
510
- ----------------------------------------------
511
-
512
497
mkPlutusScriptWitness
513
498
:: AlonzoEraOnwards era
514
499
-> L. SLanguage plutuslang
@@ -524,8 +509,3 @@ mkPlutusScriptWitness _ l plutusScriptRunnable datum scriptRedeemer execUnits =
524
509
datum
525
510
scriptRedeemer
526
511
execUnits
527
-
528
- -- PROPOSED REPLACEMENT
529
- -----------------------------------------------
530
-
531
- ------------------------------------------------
0 commit comments