@@ -283,38 +283,47 @@ could be either of them.
283283
284284<!--
285285```agda
286+ -- Level-Dependent Type Classes --
286287 record HasTxBody {txLevel} {a} (A : Type a) : Type a where
287288 field TxBodyOf : A → TxBody txLevel
288289 open HasTxBody ⦃...⦄ public
289290
290- record HasTxId {a} (A : Type a) : Type a where
291- field TxIdOf : A → TxId
292- open HasTxId ⦃...⦄ public
293-
294- record HasFees? {a} (A : Type a) : Type a where
295- field FeesOf? : A → Maybe Fees
296- open HasFees? ⦃...⦄ public
297-
298- record HasDCerts {a} (A : Type a) : Type a where
299- field DCertsOf : A → List DCert
300- open HasDCerts ⦃...⦄ public
301-
302- record HasData {a} (A : Type a) : Type a where
303- field DataOf : A → ℙ Datum
304- open HasData ⦃...⦄ public
305-
306291 record HasTxWitnesses {txLevel} {a} (A : Type a) : Type a where
307292 field TxWitnessesOf : A → TxWitnesses txLevel
308293 open HasTxWitnesses ⦃...⦄ public
309294
310- record HasValue {a} (A : Type a) : Type a where
311- field ValueOf : A → Value
312- open HasValue ⦃...⦄ public
295+ record HasRedeemers {txLevel} {a} (A : Type a) : Type a where
296+ field RedeemersOf : A → RedeemerPtr txLevel ⇀ Redeemer × ExUnits
297+ open HasRedeemers ⦃...⦄ public
298+
299+ -- (top-level only) --
300+ record HasCollateralInputs {txLevel} {a} (A : Type a) : Type a where
301+ field CollateralInputsOf : A → InTopLevel txLevel (ℙ TxIn)
302+ open HasCollateralInputs ⦃...⦄ public
303+
304+ record HasTxFees {txLevel} {a} (A : Type a) : Type a where
305+ field TxFeesOf : A → InTopLevel txLevel Fees
306+ open HasTxFees ⦃...⦄ public
313307
314308 record HasSubTransactions {txLevel} {a} (A : Type a) : Type a where
315309 field SubTransactionsOf : A → InTopLevel txLevel (List (Tx TxLevelSub))
316310 open HasSubTransactions ⦃...⦄ public
317311
312+ -- (sub-level only) --
313+ record HasTopLevelGuards {txLevel} {a} (A : Type a) : Type a where
314+ field TopLevelGuardsOf : A → InSubLevel txLevel (ℙ (Credential × Maybe Datum))
315+ open HasTopLevelGuards ⦃...⦄ public
316+
317+
318+ -- Level-Independent Type Classes --
319+ record HasTxId {a} (A : Type a) : Type a where
320+ field TxIdOf : A → TxId
321+ open HasTxId ⦃...⦄ public
322+
323+ record HasSize {a} (A : Type a) : Type a where
324+ field SizeOf : A → ℕ
325+ open HasSize ⦃...⦄ public
326+
318327 record HasSpendInputs {a} (A : Type a) : Type a where
319328 field SpendInputsOf : A → ℙ TxIn
320329 open HasSpendInputs ⦃...⦄ public
@@ -323,6 +332,26 @@ could be either of them.
323332 field ReferenceInputsOf : A → ℙ TxIn
324333 open HasReferenceInputs ⦃...⦄ public
325334
335+ record HasIndexedOutputs {a} (A : Type a) : Type a where
336+ field IndexedOutputsOf : A → Ix ⇀ TxOut
337+ open HasIndexedOutputs ⦃...⦄ public
338+
339+ record HasMintedValue {a} (A : Type a) : Type a where
340+ field MintedValueOf : A → Value
341+ open HasMintedValue ⦃...⦄ public
342+
343+ record HasFees? {a} (A : Type a) : Type a where
344+ field FeesOf? : A → Maybe Fees
345+ open HasFees? ⦃...⦄ public
346+
347+ record HasDCerts {a} (A : Type a) : Type a where
348+ field DCertsOf : A → List DCert
349+ open HasDCerts ⦃...⦄ public
350+
351+ record HasData {a} (A : Type a) : Type a where
352+ field DataOf : A → ℙ Datum
353+ open HasData ⦃...⦄ public
354+
326355 record HasGovProposals {a} (A : Type a) : Type a where
327356 field GovProposalsOf : A → List GovProposal
328357 open HasGovProposals ⦃...⦄ public
@@ -331,16 +360,45 @@ could be either of them.
331360 field GovVotesOf : A → List GovVote
332361 open HasGovVotes ⦃...⦄ public
333362
363+ record HasGuards {a} (A : Type a) : Type a where
364+ field GuardsOf : A → ℙ Credential
365+ open HasGuards ⦃...⦄ public
366+
367+ record HasScripts {a} (A : Type a) : Type a where
368+ field ScriptsOf : A → ℙ Script
369+ open HasScripts ⦃...⦄ public
370+
334371 instance
335372 HasTxBody-Tx : HasTxBody (Tx txLevel)
336373 HasTxBody-Tx .TxBodyOf = Tx.txBody
337374
338375 HasTxWitnesses-Tx : HasTxWitnesses (Tx txLevel)
339376 HasTxWitnesses-Tx .TxWitnessesOf = Tx.txWitnesses
340377
378+ HasRedeemers-TxWitnesses : HasRedeemers (TxWitnesses txLevel)
379+ HasRedeemers-TxWitnesses .RedeemersOf = TxWitnesses.txRedeemers
380+
381+ HasRedeemers-Tx : HasRedeemers (Tx txLevel)
382+ HasRedeemers-Tx .RedeemersOf = RedeemersOf ∘ TxWitnessesOf
383+
384+ HasCollateralInputs-TopLevelTx : HasCollateralInputs TopLevelTx
385+ HasCollateralInputs-TopLevelTx .CollateralInputsOf = TxBody.collateralInputs ∘ TxBodyOf
386+
387+ HasTxFees-TopLevelTx : HasTxFees TopLevelTx
388+ HasTxFees-TopLevelTx .TxFeesOf = TxBody.txFee ∘ TxBodyOf
389+
390+ HasSubTransactions-TopLevelTx : HasSubTransactions TopLevelTx
391+ HasSubTransactions-TopLevelTx .SubTransactionsOf = TxBody.txSubTransactions ∘ TxBodyOf
392+
393+ HasTopLevelGuards-SubLevelTx : HasTopLevelGuards SubLevelTx
394+ HasTopLevelGuards-SubLevelTx .TopLevelGuardsOf = TxBody.txRequiredTopLevelGuards ∘ TxBodyOf
395+
341396 HasDCerts-TxBody : HasDCerts (TxBody txLevel)
342397 HasDCerts-TxBody .DCertsOf = TxBody.txCerts
343398
399+ HasDCerts-Tx : HasDCerts (Tx txLevel)
400+ HasDCerts-Tx .DCertsOf = DCertsOf ∘ TxBodyOf
401+
344402 HasWithdrawals-TxBody : HasWithdrawals (TxBody txLevel)
345403 HasWithdrawals-TxBody .WithdrawalsOf = TxBody.txWithdrawals
346404
@@ -359,8 +417,17 @@ could be either of them.
359417 HasReferenceInputs-Tx : HasReferenceInputs (Tx txLevel)
360418 HasReferenceInputs-Tx .ReferenceInputsOf = ReferenceInputsOf ∘ TxBodyOf
361419
362- HasValue-TxBody : HasValue (TxBody txLevel)
363- HasValue-TxBody .ValueOf = TxBody.mint
420+ HasIndexedOutputs-TxBody : HasIndexedOutputs (TxBody txLevel)
421+ HasIndexedOutputs-TxBody .IndexedOutputsOf = TxBody.txOuts
422+
423+ HasIndexedOutputs-Tx : HasIndexedOutputs (Tx txLevel)
424+ HasIndexedOutputs-Tx .IndexedOutputsOf = IndexedOutputsOf ∘ TxBodyOf
425+
426+ HasMintedValue-TxBody : HasMintedValue (TxBody txLevel)
427+ HasMintedValue-TxBody .MintedValueOf = TxBody.mint
428+
429+ HasMintedValue-Tx : HasMintedValue (Tx txLevel)
430+ HasMintedValue-Tx .MintedValueOf = MintedValueOf ∘ TxBodyOf
364431
365432 HasGovVotes-TxBody : HasGovVotes (TxBody txLevel)
366433 HasGovVotes-TxBody .GovVotesOf = TxBody.txGovVotes
@@ -381,11 +448,17 @@ could be either of them.
381448 HasFees?-Tx : HasFees? (Tx txLevel)
382449 HasFees?-Tx .FeesOf? = FeesOf? ∘ TxBodyOf
383450
384- HasSubTransactions-TopLevelTx : HasSubTransactions TopLevelTx
385- HasSubTransactions-TopLevelTx .SubTransactionsOf = TxBody.txSubTransactions ∘ TxBodyOf
451+ HasTxId-TxBody : HasTxId (TxBody txLevel)
452+ HasTxId-TxBody .TxIdOf = TxBody.txId
386453
387454 HasTxId-Tx : HasTxId (Tx txLevel)
388- HasTxId-Tx .TxIdOf = TxBody.txId ∘ TxBodyOf
455+ HasTxId-Tx .TxIdOf = TxIdOf ∘ TxBodyOf
456+
457+ HasDonations-TxBody : HasDonations (TxBody txLevel)
458+ HasDonations-TxBody .DonationsOf = TxBody.txDonation
459+
460+ HasDonations-Tx : HasDonations (Tx txLevel)
461+ HasDonations-Tx .DonationsOf = DonationsOf ∘ TxBodyOf
389462
390463 HasCoin-TxOut : HasCoin TxOut
391464 HasCoin-TxOut .getCoin = coin ∘ proj₁ ∘ proj₂
@@ -395,6 +468,18 @@ could be either of them.
395468
396469 HasData-Tx : HasData (Tx txLevel)
397470 HasData-Tx .DataOf = DataOf ∘ TxWitnessesOf
471+
472+ HasGuards-TxBody : HasGuards (TxBody txLevel)
473+ HasGuards-TxBody .GuardsOf = TxBody.txGuards
474+
475+ HasGuards-Tx : HasGuards (Tx txLevel)
476+ HasGuards-Tx .GuardsOf = GuardsOf ∘ TxBodyOf
477+
478+ HasScripts-TxWitnesses : HasScripts (TxWitnesses txLevel)
479+ HasScripts-TxWitnesses .ScriptsOf = TxWitnesses.scripts
480+
481+ HasScripts-Tx : HasScripts (Tx txLevel)
482+ HasScripts-Tx .ScriptsOf = ScriptsOf ∘ TxWitnessesOf
398483```
399484-->
400485
@@ -426,47 +511,46 @@ This section collects some unimportant but useful helper and accessor functions.
426511```
427512
428513In the Dijkstra era, * spending* inputs must exist in the initial UTxO snapshot, while
429- * reference* inputs may see earlier outputs, so we need two UTxO views:
514+ * reference* inputs may come from earlier outputs, so we will need two to keep track
515+ of two UTxOs; we'll denote these as follows:
430516
431- + ` utxoSpend ₀` {.AgdaBound}, the initial snapshot, used for ` txIns ` {.AgdaField},
432- + ` utxoRefView ` {.AgdaBound}, the evolving view , used for ` refInputs ` {.AgdaField} .
517+ + ` utxo ₀` {.AgdaBound}, the initial UTxO snapshot, used for ` txIns ` {.AgdaField};
518+ + ` utxoRef ` {.AgdaBound}, the evolving UTxO , used for reference input lookups .
433519
434- Thus functions like ` refScripts ` {.AgdaFunction}, ` txscripts ` {.AgdaFunction},
435- and ` lookupScriptHash ` {.AgdaFunction} (defined below) will take * two* UTxO arguments.
520+ We now define some functions for scripts. Some of these will take two UTxO
521+ arguments, denoting the initial UTxO snapshot and an evolving UTxO, which evolves as
522+ a batch of subtransactions is processed. (Later, when the functions below are used,
523+ the two UTxO arguments may come from the UTxO environment and an evolving UTxO state;
524+ types for these are defined in the ` Utxo ` {.AgdaModule} module, which depends
525+ on the present module; thus, we cannot bind the UTxO arguments to a particular
526+ UTxO environment and state at this point.)
436527
437528``` agda
438529 refScripts : Tx txLevel → UTxO → UTxO → List Script
439- refScripts tx utxoSpend₀ utxoRefView =
440- mapMaybe (proj₂ ∘ proj₂ ∘ proj₂) ( setToList (range (utxoSpend₀ ∣ txIns))
441- ++ setToList (range (utxoRefView ∣ refInputs))
442- )
443- where open Tx tx; open TxBody (TxBodyOf tx)
530+ refScripts tx utxo₀ utxoRef =
531+ mapMaybe (proj₂ ∘ proj₂ ∘ proj₂)
532+ ( setToList (range (utxo₀ ∣ SpendInputsOf tx))
533+ ++ setToList (range (utxoRef ∣ ReferenceInputsOf tx)) )
444534
445535 txscripts : Tx txLevel → UTxO → UTxO → ℙ Script
446- txscripts tx utxoSpend₀ utxoRefView =
447- scripts (tx .txWitnesses) ∪ fromList (refScripts tx utxoSpend₀ utxoRefView)
448- where open Tx; open TxWitnesses
536+ txscripts tx utxo₀ utxoRef = ScriptsOf tx ∪ fromList (refScripts tx utxo₀ utxoRef)
449537
450538 lookupScriptHash : ScriptHash → Tx txLevel → UTxO → UTxO → Maybe Script
451- lookupScriptHash sh tx utxoSpend₀ utxoRefView =
539+ lookupScriptHash sh tx utxo₀ utxoRef =
452540 if sh ∈ mapˢ proj₁ (m ˢ) then just (lookupᵐ m sh) else nothing
453- where m = setToMap (mapˢ < hash , id > (txscripts tx utxoSpend₀ utxoRefView))
454-
455- -- TODO: implement the actual evolving `utxoRefView` (issue #1006)
541+ where m = setToMap (mapˢ < hash , id > (txscripts tx utxo₀ utxoRef))
456542
457543 getSubTxScripts : SubLevelTx → ℙ (TxId × ScriptHash)
458544 getSubTxScripts subtx = mapˢ (λ hash → (TxIdOf subtx , hash)) (ScriptHashes subtx)
459545 where
460546 ScriptHashes : Tx TxLevelSub → ℙ ScriptHash
461- ScriptHashes tx = -- `txRequiredTopLevelGuards`
462- mapPartial (isScriptObj ∘ proj₁) -- has key creds too, but only
463- (TxBody.txRequiredTopLevelGuards (TxBodyOf tx)) -- `ScriptObj hash` contributes
464- -- a phase-2 script hash.
547+ ScriptHashes tx = mapPartial (isScriptObj ∘ proj₁) (TopLevelGuardsOf tx)
548+ -- `txRequiredTopLevelGuards` has key creds too, but only
549+ -- `ScriptObj hash` contributes a phase-2 script hash.
465550
466551 getTxScripts : {ℓ : TxLevel} → Tx ℓ → ℙ (TxId × ScriptHash)
467552 getTxScripts {TxLevelSub} = getSubTxScripts
468- getTxScripts {TxLevelTop} =
469- concatMapˢ getSubTxScripts ∘ fromList ∘ TxBody.txSubTransactions ∘ TxBodyOf
553+ getTxScripts {TxLevelTop} = concatMapˢ getSubTxScripts ∘ fromList ∘ SubTransactionsOf
470554```
471555
472556CIP-0118 models "required top-level guards" as a list of requirements coming
@@ -524,17 +608,16 @@ remaining helper functions of this section.
524608
525609 subTxTaggedGuards : SubLevelTx → ℙ TaggedTopLevelGuard
526610 subTxTaggedGuards subtx =
527- mapˢ (λ (cred , md) → (TxIdOf subtx , cred , md))
528- (TxBody.txRequiredTopLevelGuards (TxBodyOf subtx))
611+ mapˢ (λ (cred , md) → (TxIdOf subtx , cred , md)) (TopLevelGuardsOf subtx)
529612
530613 -- Turn a subTx body's `txRequiredTopLevelGuards` into a set of guard credentials.
531614 subTxGuardCredentials : SubLevelTx → ℙ Credential
532- subTxGuardCredentials = (mapˢ proj₁) ∘ (TxBody.txRequiredTopLevelGuards ∘ TxBodyOf)
615+ subTxGuardCredentials = (mapˢ proj₁) ∘ TopLevelGuardsOf
533616
534617 -- Phase-1 condition (CIP-0118):
535618 -- every credential required by a subTx body must appear in the top-level txGuards set.
536619 requiredTopLevelGuardsSatisfied : TopLevelTx → List SubLevelTx → Type
537- requiredTopLevelGuardsSatisfied topTx subTxs = requiredCreds ⊆ TxBody.txGuards (TxBodyOf topTx)
620+ requiredTopLevelGuardsSatisfied topTx subTxs = requiredCreds ⊆ GuardsOf topTx
538621 where
539622 concatMapˡ : {A B : Type} → (A → ℙ B) → List A → ℙ B
540623 concatMapˡ f as = proj₁ $ unions (fromList (map f as))
0 commit comments