From 02bf6f49ccb31cb54eb897f4a7b0001fabcba994 Mon Sep 17 00:00:00 2001 From: fanghr Date: Mon, 23 May 2022 18:11:32 +0800 Subject: [PATCH] remove `anyInput` --- agora/Agora/Stake/Scripts.hs | 23 +++++++++++++++-------- agora/Agora/Utils.hs | 27 --------------------------- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/agora/Agora/Stake/Scripts.hs b/agora/Agora/Stake/Scripts.hs index da9da7f..877819d 100644 --- a/agora/Agora/Stake/Scripts.hs +++ b/agora/Agora/Stake/Scripts.hs @@ -11,8 +11,8 @@ import Agora.Record (mkRecordConstr, (.&), (.=)) import Agora.SafeMoney (GTTag) import Agora.Stake import Agora.Utils ( - anyInput, anyOutput, + mustFindDatum', paddValue, pfindTxInByTxOutRef, pgeqByClass, @@ -77,7 +77,7 @@ stakePolicy gtClassRef = txInfo <- tclet $ ctx.txInfo let _a :: Term _ PTxInfo _a = txInfo - txInfoF <- tcont $ pletFields @'["mint", "inputs", "outputs", "signatories"] txInfo + txInfoF <- tcont $ pletFields @'["mint", "inputs", "outputs", "signatories", "datums"] txInfo PMinting ownSymbol' <- tcmatch $ pfromData ctx.purpose ownSymbol <- tclet $ pfield @"_0" # ownSymbol' @@ -92,12 +92,19 @@ stakePolicy gtClassRef = mintedST #== -1 tcassert "An unlocked input existed containing an ST" $ - anyInput @PStakeDatum # txInfo - #$ plam - $ \value _ stakeDatum' -> - let hasST = psymbolValueOf # ownSymbol # value #== 1 - unlocked = pnot # (stakeLocked # stakeDatum') - in hasST #&& unlocked + pany + # plam + ( \((pfield @"resolved" #) -> txOut) -> unTermCont $ do + txOutF <- tcont $ pletFields @'["value", "datumHash"] txOut + pure $ + pif + (psymbolValueOf # ownSymbol # txOutF.value #== 1) + ( let datum = mustFindDatum' @PStakeDatum # txOutF.datumHash # txInfoF.datums + in pnot # (stakeLocked # datum) + ) + (pconstant False) + ) + # pfromData txInfoF.inputs pure $ popaque (pconstant ()) diff --git a/agora/Agora/Utils.hs b/agora/Agora/Utils.hs index c594200..5cd6f40 100644 --- a/agora/Agora/Utils.hs +++ b/agora/Agora/Utils.hs @@ -46,7 +46,6 @@ module Agora.Utils ( -- * Functions which should (probably) not be upstreamed anyOutput, allOutputs, - anyInput, findTxOutByTxOutRef, scriptHashFromAddress, findOutputsToAddress, @@ -606,32 +605,6 @@ allOutputs = phoistAcyclic $ ) # pfromData txInfo.outputs --- | Check if any (resolved) input matches the predicate. -anyInput :: - forall (datum :: PType) s. - ( PIsData datum - , PTryFrom PData (PAsData datum) - ) => - Term s (PTxInfo :--> (PValue :--> PAddress :--> datum :--> PBool) :--> PBool) -anyInput = phoistAcyclic $ - plam $ \txInfo' predicate -> unTermCont $ do - txInfo <- tcont $ pletFields @'["inputs", "datums"] txInfo' - pure $ - pany - # plam - ( \txInInfo'' -> unTermCont $ do - PTxInInfo txInInfo' <- tcmatch (pfromData txInInfo'') - let txOut'' = pfield @"resolved" # txInInfo' - PTxOut txOut' <- tcmatch (pfromData txOut'') - txOut <- tcont $ pletFields @'["value", "datumHash", "address"] txOut' - PDJust dh <- tcmatch txOut.datumHash - pure $ - pmatch (ptryFindDatum @(PAsData datum) # (pfield @"_0" # dh) # txInfo.datums) $ \case - PJust datum -> predicate # txOut.value # txOut.address # pfromData datum - PNothing -> pcon PFalse - ) - # pfromData txInfo.inputs - -- | Create a value with a single asset class. psingletonValue :: forall s. Term s (PCurrencySymbol :--> PTokenName :--> PInteger :--> PValue) psingletonValue = phoistAcyclic $