Skip to content

Commit 21d0f5c

Browse files
committed
remove case logic and make code more idiomatic
1 parent 44b6d0b commit 21d0f5c

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

cardano-db-sync/src/Cardano/DbSync/Config.hs

+14-21
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,9 @@ mkAdjustPath :: SyncPreConfig -> (FilePath -> FilePath)
9696
mkAdjustPath cfg fp = takeDirectory (pcNodeConfigFilePath cfg) </> fp
9797

9898
-- check both whitelist but also checking plutus Maybes first
99-
-- TODO: cmdv: unsure if this is correct because if plutusMaybeCheck fails then no multiasset whitelist is not checked
10099
plutusMultiAssetWhitelistCheck :: SyncEnv -> [Generic.TxOut] -> Bool
101100
plutusMultiAssetWhitelistCheck syncEnv txOuts =
102-
plutusMaybeCheck txOuts && (plutusWhitelistCheck syncEnv txOuts || multiAssetWhitelistCheck syncEnv txOuts)
101+
plutusMaybeCheck txOuts || (plutusWhitelistCheck syncEnv txOuts || multiAssetWhitelistCheck syncEnv txOuts)
103102

104103
plutusMaybeCheck :: [Generic.TxOut] -> Bool
105104
plutusMaybeCheck =
@@ -110,34 +109,28 @@ plutusWhitelistCheck syncEnv txOuts = do
110109
-- first check the config option
111110
case ioPlutusExtra iopts of
112111
PlutusEnable -> True
113-
PlutusDisable -> False
112+
PlutusDisable -> True
114113
PlutusWhitelistScripts plutusWhitelist -> plutuswhitelistCheck plutusWhitelist
115114
where
116115
iopts = soptInsertOptions $ envOptions syncEnv
117-
plutuswhitelistCheck whitelist = do
118-
any
119-
( isJust
120-
. ( \txOut -> do
121-
case (Generic.txOutScript txOut, Generic.maybePaymentCred $ Generic.txOutAddress txOut) of
122-
(Just script, _) ->
123-
if Generic.txScriptHash script `elem` whitelist
124-
then Just txOut
125-
else Nothing
126-
(_, Just address) ->
127-
if address `elem` whitelist
128-
then Just txOut
129-
else Nothing
130-
(Nothing, Nothing) -> Nothing
131-
)
132-
)
133-
txOuts
116+
plutuswhitelistCheck :: NonEmpty ByteString -> Bool
117+
plutuswhitelistCheck whitelist =
118+
any (\txOut -> isScriptHashWhitelisted whitelist txOut || isAddressWhitelisted whitelist txOut) txOuts
119+
-- check if the script hash is in the whitelist
120+
isScriptHashWhitelisted :: NonEmpty ByteString -> Generic.TxOut -> Bool
121+
isScriptHashWhitelisted whitelist txOut =
122+
maybe False ((`elem` whitelist) . Generic.txScriptHash) (Generic.txOutScript txOut)
123+
-- check if the address is in the whitelist
124+
isAddressWhitelisted :: NonEmpty ByteString -> Generic.TxOut -> Bool
125+
isAddressWhitelisted whitelist txOut=
126+
maybe False (`elem` whitelist) (Generic.maybePaymentCred $ Generic.txOutAddress txOut)
134127

135128
multiAssetWhitelistCheck :: SyncEnv -> [Generic.TxOut] -> Bool
136129
multiAssetWhitelistCheck syncEnv txOuts = do
137130
let iopts = soptInsertOptions $ envOptions syncEnv
138131
case ioMultiAssets iopts of
139132
MultiAssetEnable -> True
140-
MultiAssetDisable -> False
133+
MultiAssetDisable -> True
141134
MultiAssetWhitelistPolicies multiAssetWhitelist ->
142135
or multiAssetwhitelistCheck
143136
where

0 commit comments

Comments
 (0)