Skip to content

Commit

Permalink
hasSt should lookup data in the map
Browse files Browse the repository at this point in the history
Let's use the lookup function offered by Plutus insteaed of
filtering the list ourselves. Makes the code easier to read.
  • Loading branch information
pgrange committed Feb 8, 2023
1 parent 6632086 commit 9934607
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions hydra-plutus/src/Hydra/Contract/Util.hs
Expand Up @@ -20,13 +20,14 @@ hydraHeadV1 = "HydraHeadV1"
-- 'CurrencySymbol' and 'TokenName' of 'hydraHeadV1'
hasST :: CurrencySymbol -> Value -> Bool
hasST headPolicyId v =
isJust $
find
(\(cs, tokenMap) -> cs == headPolicyId && hasHydraToken tokenMap)
(Map.toList $ getValue v)
case hasST' of
Just True -> True
_otherwise -> traceError "ST not spent in transaction"
where
hasHydraToken tm =
isJust $ find (\(tn, q) -> q == 1 && TokenName hydraHeadV1 == tn) (Map.toList tm)
hasST' = do
tokenMap <- Map.lookup headPolicyId $ getValue v
quantity <- Map.lookup (TokenName hydraHeadV1) tokenMap
pure $ quantity == 1
{-# INLINEABLE hasST #-}

-- | Checks if all the state token (ST) for list of parties containing specific
Expand All @@ -46,4 +47,3 @@ mustNotMintOrBurn TxInfo{txInfoMint} =
traceIfFalse "minting or burning is forbidden" $
isZero txInfoMint
{-# INLINEABLE mustNotMintOrBurn #-}

0 comments on commit 9934607

Please sign in to comment.