add isPubKey && utilize it in the TreasuryWithdrawal effect
This commit is contained in:
parent
1ba11bc23a
commit
1b9aaf111d
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 Generics.SOP (Generic, I (I))
|
||||||
|
|
||||||
import Agora.Effect (makeEffect)
|
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 (
|
import Plutarch.Api.V1 (
|
||||||
PCredential (..),
|
PCredential (..),
|
||||||
PTuple,
|
PTuple,
|
||||||
|
|
@ -140,12 +140,6 @@ treasuryWithdrawalValidator currSymbol = makeEffect currSymbol $
|
||||||
treasuryInputValuesSum = sumValues #$ ofTreasury # inputValues
|
treasuryInputValuesSum = sumValues #$ ofTreasury # inputValues
|
||||||
treasuryOutputValuesSum = sumValues #$ ofTreasury # outputValues
|
treasuryOutputValuesSum = sumValues #$ ofTreasury # outputValues
|
||||||
receiverValuesSum = sumValues # datum.receivers
|
receiverValuesSum = sumValues # datum.receivers
|
||||||
isPubkey = plam $ \cred ->
|
|
||||||
pmatch cred $
|
|
||||||
\case
|
|
||||||
PPubKeyCredential _ -> pcon PTrue
|
|
||||||
PScriptCredential _ -> pcon PFalse
|
|
||||||
|
|
||||||
-- Constraints
|
-- Constraints
|
||||||
outputContentMatchesRecivers =
|
outputContentMatchesRecivers =
|
||||||
pall # plam (\out -> pelem # out # outputValues)
|
pall # plam (\out -> pelem # out # outputValues)
|
||||||
|
|
@ -165,7 +159,7 @@ treasuryWithdrawalValidator currSymbol = makeEffect currSymbol $
|
||||||
( \((pfield @"_0" #) . pfromData -> cred) ->
|
( \((pfield @"_0" #) . pfromData -> cred) ->
|
||||||
cred #== pfield @"credential" # effInput.address
|
cred #== pfield @"credential" # effInput.address
|
||||||
#|| pelem # cred # datum.treasuries
|
#|| pelem # cred # datum.treasuries
|
||||||
#|| isPubkey # pfromData cred
|
#|| isPubKey # pfromData cred
|
||||||
)
|
)
|
||||||
# inputValues
|
# inputValues
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ module Agora.Utils (
|
||||||
pmergeBy,
|
pmergeBy,
|
||||||
phalve,
|
phalve,
|
||||||
isScriptAddress,
|
isScriptAddress,
|
||||||
|
isPubKey,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
@ -623,10 +624,15 @@ scriptHashFromAddress = phoistAcyclic $
|
||||||
-- | Return true if the given address is a script address.
|
-- | Return true if the given address is a script address.
|
||||||
isScriptAddress :: Term s (PAddress :--> PBool)
|
isScriptAddress :: Term s (PAddress :--> PBool)
|
||||||
isScriptAddress = phoistAcyclic $
|
isScriptAddress = phoistAcyclic $
|
||||||
plam $ \addr ->
|
plam $ \addr -> pnot #$ isPubKey #$ pfromData $ pfield @"credential" # addr
|
||||||
pmatch (pfromData $ pfield @"credential" # addr) $ \case
|
|
||||||
PScriptCredential _ -> pconstant True
|
-- | Return true if the given credential is a pub-key-hash.
|
||||||
_ -> pconstant False
|
isPubKey :: Term s (PCredential :--> PBool)
|
||||||
|
isPubKey = phoistAcyclic $
|
||||||
|
plam $ \cred ->
|
||||||
|
pmatch cred $ \case
|
||||||
|
PScriptCredential _ -> pconstant False
|
||||||
|
_ -> pconstant True
|
||||||
|
|
||||||
-- | Find all TxOuts sent to an Address
|
-- | Find all TxOuts sent to an Address
|
||||||
findOutputsToAddress :: Term s (PBuiltinList (PAsData PTxOut) :--> PAddress :--> PBuiltinList (PAsData PTxOut))
|
findOutputsToAddress :: Term s (PBuiltinList (PAsData PTxOut) :--> PAddress :--> PBuiltinList (PAsData PTxOut))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue