add isPubKey && utilize it in the TreasuryWithdrawal effect
This commit is contained in:
parent
ab3dfba6e0
commit
dba8b3c68b
2 changed files with 12 additions and 12 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue