diff --git a/agora/Agora/Effect/TreasuryWithdrawal.hs b/agora/Agora/Effect/TreasuryWithdrawal.hs index 6bb2851..5bf451c 100644 --- a/agora/Agora/Effect/TreasuryWithdrawal.hs +++ b/agora/Agora/Effect/TreasuryWithdrawal.hs @@ -18,7 +18,7 @@ import GHC.Generics qualified as GHC import Generics.SOP (Generic, I (I)) import Agora.Effect (makeEffect) -import Agora.Utils (findTxOutByTxOutRef, paddValue, tcassert, tclet, tcmatch) +import Agora.Utils (findTxOutByTxOutRef, isPubKey, paddValue, tcassert, tclet, tcmatch) import Plutarch.Api.V1 ( PCredential (..), PTuple, @@ -140,12 +140,6 @@ treasuryWithdrawalValidator currSymbol = makeEffect currSymbol $ treasuryInputValuesSum = sumValues #$ ofTreasury # inputValues treasuryOutputValuesSum = sumValues #$ ofTreasury # outputValues receiverValuesSum = sumValues # datum.receivers - isPubkey = plam $ \cred -> - pmatch cred $ - \case - PPubKeyCredential _ -> pcon PTrue - PScriptCredential _ -> pcon PFalse - -- Constraints outputContentMatchesRecivers = pall # plam (\out -> pelem # out # outputValues) @@ -165,7 +159,7 @@ treasuryWithdrawalValidator currSymbol = makeEffect currSymbol $ ( \((pfield @"_0" #) . pfromData -> cred) -> cred #== pfield @"credential" # effInput.address #|| pelem # cred # datum.treasuries - #|| isPubkey # pfromData cred + #|| isPubKey # pfromData cred ) # inputValues diff --git a/agora/Agora/Utils.hs b/agora/Agora/Utils.hs index 63cf022..1a6424b 100644 --- a/agora/Agora/Utils.hs +++ b/agora/Agora/Utils.hs @@ -60,6 +60,7 @@ module Agora.Utils ( pmergeBy, phalve, isScriptAddress, + isPubKey, ) where -------------------------------------------------------------------------------- @@ -623,10 +624,15 @@ scriptHashFromAddress = phoistAcyclic $ -- | Return true if the given address is a script address. isScriptAddress :: Term s (PAddress :--> PBool) isScriptAddress = phoistAcyclic $ - plam $ \addr -> - pmatch (pfromData $ pfield @"credential" # addr) $ \case - PScriptCredential _ -> pconstant True - _ -> pconstant False + plam $ \addr -> pnot #$ isPubKey #$ pfromData $ pfield @"credential" # addr + +-- | Return true if the given credential is a pub-key-hash. +isPubKey :: Term s (PCredential :--> PBool) +isPubKey = phoistAcyclic $ + plam $ \cred -> + pmatch cred $ \case + PScriptCredential _ -> pconstant False + _ -> pconstant True -- | Find all TxOuts sent to an Address findOutputsToAddress :: Term s (PBuiltinList (PAsData PTxOut) :--> PAddress :--> PBuiltinList (PAsData PTxOut))