Skip to content

Commit 38786dc

Browse files
committed
clean up txInfoForPurpose
1 parent 56f60be commit 38786dc

File tree

2 files changed

+44
-36
lines changed

2 files changed

+44
-36
lines changed

src/Ledger/Dijkstra/Specification/Script/Validation.lagda.md

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -94,50 +94,51 @@ mutual
9494
txInfo : (ℓ : TxLevel) → UTxO → Tx ℓ → TxInfo
9595
9696
txInfo TxLevelTop utxo tx =
97-
record { realizedInputs = utxo ∣ (TxBody.txIns txBody)
98-
; txOuts = TxBody.txOuts txBody
99-
; txFee = just (TxBody.txFee txBody)
100-
; mint = TxBody.mint txBody
101-
; txCerts = TxBody.txCerts txBody
102-
; txWithdrawals = TxBody.txWithdrawals txBody
103-
; txVldt = TxBody.txVldt txBody
104-
; vkKey = TxBody.reqSignerHashes txBody
105-
; txGuards = TxBody.txGuards txBody
106-
; txData = DataOf tx
107-
; txId = TxBody.txId txBody
108-
; txInfoSubTxs = nothing
97+
record { realizedInputs = utxo ∣ (TxBody.txIns txBody)
98+
; txOuts = TxBody.txOuts txBody
99+
; txFee = just (TxBody.txFee txBody)
100+
; mint = TxBody.mint txBody
101+
; txCerts = TxBody.txCerts txBody
102+
; txWithdrawals = TxBody.txWithdrawals txBody
103+
; txVldt = TxBody.txVldt txBody
104+
; vkKey = TxBody.reqSignerHashes txBody
105+
; txGuards = TxBody.txGuards txBody
106+
; txData = DataOf tx
107+
; txId = TxBody.txId txBody
108+
; txInfoSubTxs = nothing
109109
} where open Tx tx
110110
111111
txInfo TxLevelSub utxo tx =
112-
record { realizedInputs = utxo ∣ (TxBody.txIns txBody)
113-
; txOuts = TxBody.txOuts txBody
114-
; txFee = nothing
115-
; mint = TxBody.mint txBody
116-
; txCerts = TxBody.txCerts txBody
117-
; txWithdrawals = TxBody.txWithdrawals txBody
118-
; txVldt = TxBody.txVldt txBody
119-
; vkKey = TxBody.reqSignerHashes txBody
120-
; txGuards = TxBody.txGuards txBody
121-
; txData = DataOf tx
122-
; txId = TxBody.txId txBody
123-
; txInfoSubTxs = nothing
112+
record { realizedInputs = utxo ∣ (TxBody.txIns txBody)
113+
; txOuts = TxBody.txOuts txBody
114+
; txFee = nothing
115+
; mint = TxBody.mint txBody
116+
; txCerts = TxBody.txCerts txBody
117+
; txWithdrawals = TxBody.txWithdrawals txBody
118+
; txVldt = TxBody.txVldt txBody
119+
; vkKey = TxBody.reqSignerHashes txBody
120+
; txGuards = TxBody.txGuards txBody
121+
; txData = DataOf tx
122+
; txId = TxBody.txId txBody
123+
; txInfoSubTxs = nothing
124124
} where open Tx tx
125125
126126
txInfoForPurpose : (ℓ : TxLevel) → UTxO → Tx ℓ → ScriptPurpose → TxInfo
127-
-- SubTx scripts never get subTx infos (even if their ScriptPurpose is Guard).
127+
128+
128129
txInfoForPurpose TxLevelSub utxo tx sp = txInfo TxLevelSub utxo tx
129-
-- Top-level scripts:
130-
-- - guard scripts see txInfoSubTxs
131-
-- - others do not
130+
-- SubTx scripts never get subTx infos (even if their ScriptPurpose is Guard).
131+
132132
txInfoForPurpose TxLevelTop utxo tx sp with sp
133-
... | Guard _ =
134-
let base = txInfo TxLevelTop utxo tx
135-
txb = TxBodyOf tx
136-
subTxs = TxBody.txSubTransactions txb
137-
subInfos : List SubTxInfo
138-
subInfos = map (txInfo TxLevelSub utxo) subTxs
139-
in
140-
record base { txInfoSubTxs = just subInfos }
133+
-- Top-level scripts:
134+
-- · guard scripts see subTx infos
135+
... | Guard _ = record base { txInfoSubTxs = just subInfos }
136+
where
137+
base : TxInfo
138+
base = txInfo TxLevelTop utxo tx
139+
subInfos : List SubTxInfo
140+
subInfos = map (txInfo TxLevelSub utxo) (SubTransactionsOf tx)
141+
-- · other top-level scripts see no subTx infos
141142
... | _ = txInfo TxLevelTop utxo tx
142143
```
143144

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ could be either of them.
311311
field ValueOf : A → Value
312312
open HasValue ⦃...⦄ public
313313
314+
record HasSubTransactions {txLevel} {a} (A : Type a) : Type a where
315+
field SubTransactionsOf : A → InTopLevel txLevel (List (Tx TxLevelSub))
316+
open HasSubTransactions ⦃...⦄ public
317+
314318
record HasGovProposals {a} (A : Type a) : Type a where
315319
field GovProposalsOf : A → List GovProposal
316320
open HasGovProposals ⦃...⦄ public
@@ -357,6 +361,9 @@ could be either of them.
357361
HasFees?-Tx : HasFees? (Tx txLevel)
358362
HasFees?-Tx .FeesOf? = FeesOf? ∘ TxBodyOf
359363
364+
HasSubTransactions-TopLevelTx : HasSubTransactions TopLevelTx
365+
HasSubTransactions-TopLevelTx .SubTransactionsOf = TxBody.txSubTransactions ∘ TxBodyOf
366+
360367
HasTxId-Tx : HasTxId (Tx txLevel)
361368
HasTxId-Tx .TxIdOf = TxBody.txId ∘ TxBodyOf
362369

0 commit comments

Comments
 (0)