use Plutarch.Monadic in Stake
This commit is contained in:
parent
5ec12e6ae9
commit
39e5eac2a1
1 changed files with 14 additions and 18 deletions
|
|
@ -23,6 +23,7 @@ import Plutarch.DataRepr (
|
||||||
PIsDataReprInstances (PIsDataReprInstances),
|
PIsDataReprInstances (PIsDataReprInstances),
|
||||||
)
|
)
|
||||||
import Plutarch.Internal
|
import Plutarch.Internal
|
||||||
|
import Plutarch.Monadic qualified as P
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -62,33 +63,28 @@ newtype StakeDatum (gt :: MoneyClass) (s :: S) = StakeDatum
|
||||||
(PlutusType, PIsData, PDataFields)
|
(PlutusType, PIsData, PDataFields)
|
||||||
via (PIsDataReprInstances (StakeDatum gt))
|
via (PIsDataReprInstances (StakeDatum gt))
|
||||||
|
|
||||||
assert :: Term s PString -> Term s PBool -> TermCont @r s ()
|
passert :: Term s PString -> Term s PBool -> Term s k -> Term s k
|
||||||
assert errorMessage check = TermCont $ \k -> pif check (k ()) (ptraceError errorMessage)
|
passert errorMessage check k = pif check k (ptraceError errorMessage)
|
||||||
|
|
||||||
-- pfindDatum :: Term s (PDatumHash :--> PTxInfo :--> PMaybe PDatum)
|
|
||||||
-- pfindDatum = phoistAcyclic $
|
|
||||||
-- plam $ \_datumHash _txInfo -> unTermCont $ do
|
|
||||||
-- pure (pcon PNothing)
|
|
||||||
|
|
||||||
stakePolicy ::
|
stakePolicy ::
|
||||||
forall (gt :: MoneyClass) s.
|
forall (gt :: MoneyClass) s.
|
||||||
Stake gt ->
|
Stake gt ->
|
||||||
Term s (PData :--> PScriptContext :--> PUnit)
|
Term s (PData :--> PScriptContext :--> PUnit)
|
||||||
stakePolicy _stake =
|
stakePolicy _stake =
|
||||||
plam $ \_redeemer ctx -> unTermCont $ do
|
plam $ \_redeemer ctx -> P.do
|
||||||
PScriptContext ctx' <- tcont $ pmatch ctx
|
PScriptContext ctx' <- pmatch ctx
|
||||||
ctx'' <- tcont $ pletFields @'["txInfo", "purpose"] ctx'
|
ctx'' <- pletFields @'["txInfo", "purpose"] ctx'
|
||||||
PTxInfo txInfo <- tcont $ pmatch $ pfromData (hrecField @"txInfo" ctx'')
|
PTxInfo txInfo <- pmatch $ pfromData (hrecField @"txInfo" ctx'')
|
||||||
txInfo' <- tcont $ pletFields @'["signatories", "outputs"] txInfo
|
txInfo' <- pletFields @'["signatories", "outputs"] txInfo
|
||||||
let outputs = hrecField @"outputs" txInfo'
|
let outputs = hrecField @"outputs" txInfo'
|
||||||
|
|
||||||
assert "Created stake must be owned by a signer of this transaction" $
|
passert "Created stake must be owned by a signer of this transaction" $
|
||||||
pany
|
pany
|
||||||
# ( plam $ \txOut -> unTermCont $ do
|
# ( plam $ \txOut -> P.do
|
||||||
PTxOut txOut' <- tcont $ pmatch (pfromData txOut)
|
PTxOut txOut' <- pmatch (pfromData txOut)
|
||||||
_txOut'' <- tcont $ pletFields @'["value", "datumHash"] txOut'
|
_txOut'' <- pletFields @'["value", "datumHash"] txOut'
|
||||||
pure (pcon PTrue)
|
pcon PTrue
|
||||||
)
|
)
|
||||||
# outputs
|
# outputs
|
||||||
|
|
||||||
pure (pcon PUnit)
|
pcon PUnit
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue