-
Notifications
You must be signed in to change notification settings - Fork 463
/
BasicPolicies.hs
43 lines (37 loc) · 1.41 KB
/
BasicPolicies.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
module BasicPolicies where
import qualified Language.PlutusCore.Universe as PLC
import Language.PlutusTx
import Language.PlutusTx.Lift
import Language.PlutusTx.Prelude
import Ledger
import Ledger.Ada
import Ledger.Typed.Scripts
import Ledger.Value
tname :: TokenName
tname = error ()
key :: PubKeyHash
key = error ()
-- BLOCK1
oneAtATimePolicy :: PolicyCtx -> Bool
oneAtATimePolicy ctx =
-- 'ownCurrencySymbol' lets us get our own hash (= currency symbol)
-- from the context
let ownSymbol = ownCurrencySymbol ctx
txinfo = policyCtxTxInfo ctx
forged = txInfoForge txinfo
-- Here we're looking at some specific token name, which we
-- will assume we've got from elsewhere for now.
in valueOf forged ownSymbol tname == 1
-- We can use 'compile' to turn a forging policy into a compiled Plutus Core program,
-- just as for validator scripts. We also provide a 'wrapMonetaryPolicy' function
-- to handle the boilerplate.
oneAtATimeCompiled :: CompiledCode PLC.DefaultUni () (Data -> ())
oneAtATimeCompiled = $$(compile [|| wrapMonetaryPolicy oneAtATimePolicy ||])
-- BLOCK2
singleSignerPolicy :: PolicyCtx -> Bool
singleSignerPolicy ctx = txSignedBy (policyCtxTxInfo ctx) key
-- BLOCK3