Skip to content

Commit 011e275

Browse files
Soupstrawlehins
authored andcommitted
Add guards to scriptsNeeded
1 parent aa656a5 commit 011e275

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

eras/dijkstra/src/Cardano/Ledger/Dijkstra/Scripts.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
module Cardano.Ledger.Dijkstra.Scripts (
2020
PlutusScript (..),
2121
DijkstraPlutusPurpose (..),
22+
DijkstraEraScript (..),
2223
pattern GuardingPurpose,
2324
) where
2425

eras/dijkstra/src/Cardano/Ledger/Dijkstra/UTxO.hs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
{-# LANGUAGE PatternSynonyms #-}
12
{-# LANGUAGE TypeFamilies #-}
23
{-# OPTIONS_GHC -Wno-orphans #-}
34

4-
module Cardano.Ledger.Dijkstra.UTxO () where
5+
module Cardano.Ledger.Dijkstra.UTxO (
6+
getDijkstraScriptsNeeded,
7+
) where
58

69
import Cardano.Ledger.Alonzo.UTxO (
710
AlonzoEraUTxO (..),
8-
AlonzoScriptsNeeded,
11+
AlonzoScriptsNeeded (..),
912
getAlonzoScriptsHashesNeeded,
13+
zipAsIxItem,
1014
)
1115
import Cardano.Ledger.Babbage.UTxO (
1216
getBabbageScriptsProvided,
@@ -20,11 +24,17 @@ import Cardano.Ledger.Conway.UTxO (
2024
getConwayScriptsNeeded,
2125
getConwayWitsVKeyNeeded,
2226
)
27+
import Cardano.Ledger.Credential (credScriptHash)
28+
import Cardano.Ledger.Dijkstra.Core (AsIxItem (..), EraTxBody (..))
2329
import Cardano.Ledger.Dijkstra.Era (DijkstraEra)
24-
import Cardano.Ledger.Dijkstra.State (EraUTxO (..))
30+
import Cardano.Ledger.Dijkstra.Scripts (DijkstraEraScript (..), pattern GuardingPurpose)
31+
import Cardano.Ledger.Dijkstra.State (EraUTxO (..), UTxO)
2532
import Cardano.Ledger.Dijkstra.State.CertState ()
2633
import Cardano.Ledger.Dijkstra.Tx ()
34+
import Cardano.Ledger.Dijkstra.TxBody (DijkstraEraTxBody (..))
2735
import Cardano.Ledger.Mary.UTxO (getConsumedMaryValue)
36+
import Data.Maybe (catMaybes)
37+
import Lens.Micro ((^.))
2838

2939
instance EraUTxO DijkstraEra where
3040
type ScriptsNeeded DijkstraEra = AlonzoScriptsNeeded DijkstraEra
@@ -37,14 +47,25 @@ instance EraUTxO DijkstraEra where
3747

3848
getScriptsProvided = getBabbageScriptsProvided
3949

40-
getScriptsNeeded = getConwayScriptsNeeded
50+
getScriptsNeeded = getDijkstraScriptsNeeded
4151

4252
getScriptsHashesNeeded = getAlonzoScriptsHashesNeeded
4353

4454
getWitsVKeyNeeded _ = getConwayWitsVKeyNeeded
4555

4656
getMinFeeTxUtxo = getConwayMinFeeTxUtxo
4757

58+
getDijkstraScriptsNeeded ::
59+
(DijkstraEraTxBody era, DijkstraEraScript era) => UTxO era -> TxBody era -> AlonzoScriptsNeeded era
60+
getDijkstraScriptsNeeded utxo txb =
61+
getConwayScriptsNeeded utxo txb
62+
<> guardingScriptsNeeded
63+
where
64+
guardingScriptsNeeded = AlonzoScriptsNeeded $
65+
catMaybes $
66+
zipAsIxItem (txb ^. guardsTxBodyL) $
67+
\(AsIxItem idx cred) -> (\sh -> (GuardingPurpose (AsIxItem idx sh), sh)) <$> credScriptHash cred
68+
4869
instance AlonzoEraUTxO DijkstraEra where
4970
getSupplementalDataHashes = getBabbageSupplementalDataHashes
5071

0 commit comments

Comments
 (0)