check that ST is sent to script

This commit is contained in:
Emily Martins 2022-02-21 21:55:11 +01:00
parent 87af9ffcb9
commit df349b8f35

View file

@ -89,6 +89,7 @@ anyOutput = phoistAcyclic $
) )
# pfromData txInfo.outputs # pfromData txInfo.outputs
-- | Check if any (resolved) input matches the predicate
anyInput :: anyInput ::
forall (datum :: PType) s. forall (datum :: PType) s.
( PIsData datum ( PIsData datum
@ -179,12 +180,17 @@ stakePolicy _stake =
passert "A UTXO must exist with the correct output" $ passert "A UTXO must exist with the correct output" $
anyOutput @(StakeDatum gt) # pfromData txInfo' anyOutput @(StakeDatum gt) # pfromData txInfo'
#$ plam #$ plam
$ \value _ stakeDatum' -> P.do $ \value address stakeDatum' -> P.do
stakeDatum <- pletFields @'["owner", "stakedAmount"] stakeDatum' let cred = pfield @"credential" # address
let expectedValue = paddValue # (discreteValue # stakeDatum.stakedAmount) # stValue pmatch cred $ \case
let ownerSignsTransaction = ptxSignedBy # ctx.txInfo # stakeDatum.owner -- Should pay to a script address
let valueCorrect = pdata value #== pdata expectedValue -- TODO: Needs to be >=, rather than == PPubKeyCredential _ -> pcon PFalse
ownerSignsTransaction #&& valueCorrect PScriptCredential _ -> P.do
stakeDatum <- pletFields @'["owner", "stakedAmount"] stakeDatum'
let expectedValue = paddValue # (discreteValue # stakeDatum.stakedAmount) # stValue
let ownerSignsTransaction = ptxSignedBy # ctx.txInfo # stakeDatum.owner
let valueCorrect = pdata value #== pdata expectedValue -- TODO: Needs to be >=, rather than ==
ownerSignsTransaction #&& valueCorrect
pconstant () pconstant ()