Skip to content

Commit 71d47f1

Browse files
committed
rename and fix some guard functions
1 parent 7e565ee commit 71d47f1

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/Ledger/Dijkstra/Specification/Transaction.lagda.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -459,34 +459,29 @@ remaining helper functions of this section.
459459
... | yes _ = (c , (tid , md) ∷ xs) ∷ rest
460460
... | no _ = (c , xs) ∷ insertGuard (tid , cred , md) rest
461461
462-
subTxTopLevelGuards : SubLevelTx → ℙ TaggedTopLevelGuard
463-
subTxTopLevelGuards subtx =
462+
subTxTaggedGuards : SubLevelTx → ℙ TaggedTopLevelGuard
463+
subTxTaggedGuards subtx =
464464
mapˢ (λ (cred , md) → (TxIdOf subtx , cred , md))
465465
(TxBody.txRequiredTopLevelGuards (TxBodyOf subtx))
466466
467-
-- Phase-1 condition (CIP-0118):
468-
-- every credential requested by subTx bodies must appear in the top-level txGuards set.
469-
requiredTopLevelGuardsSatisfiedᵇ : TopLevelTx → List SubLevelTx → Bool
470-
requiredTopLevelGuardsSatisfiedᵇ topTx subTxs =
471-
all (λ req → (requestedCred req ∈ᵇ topGuards))
472-
(concatMap subTxRequiredTopLevelGuardRequests subTxs)
473-
where
474-
topGuards : ℙ Credential
475-
topGuards = TxBody.txGuards (TxBodyOf topTx)
476-
requestedCred : RequiredTopLevelGuardRequest → Credential
477-
requestedCred = proj₁ ∘ proj₂
467+
-- Turn a subTx body's `txRequiredTopLevelGuards` into a set of guard credentials.
468+
subTxGuardCredentials : SubLevelTx → ℙ Credential
469+
subTxGuardCredentials = (mapˢ proj₁) ∘ (TxBody.txRequiredTopLevelGuards ∘ TxBodyOf)
478470
471+
-- Phase-1 condition (CIP-0118):
472+
-- every credential required by a subTx body must appear in the top-level txGuards set.
479473
requiredTopLevelGuardsSatisfied : TopLevelTx → List SubLevelTx → Type
480474
requiredTopLevelGuardsSatisfied topTx subTxs = requiredCreds ⊆ topGuards
481-
-- (could just use `T (requiredTopLevelGuardsSatisfiedᵇ topTx subTxs)` here instead)
482475
where
483476
topGuards : ℙ Credential
484477
topGuards = TxBody.txGuards (TxBodyOf topTx)
485478
479+
concatMapˡ : {A B : Type} → (A → ℙ B) → List A → ℙ B
480+
concatMapˡ f as = proj₁ $ unions (fromList (map f as))
481+
-- (maybe move concatMapˡ to src-lib-exts or agda-sets)
482+
486483
requiredCreds : ℙ Credential
487-
requiredCreds =
488-
fromList (map (proj₁ ∘ proj₂)
489-
(concatMap subTxRequiredTopLevelGuardRequests subTxs))
484+
requiredCreds = concatMapˡ subTxGuardCredentials subTxs
490485
```
491486

492487
## Changes to Transaction Validity

0 commit comments

Comments
 (0)