Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type UntypedValidator = BuiltinData -> BuiltinData -> BuiltinData -> ()
- mkUntypedValidator :: (IsScriptContext sc, UnsafeFromData d, UnsafeFromData r) => (d -> r -> sc -> Bool) -> UntypedValidator
- class ValidatorTypes (a :: Type) where
- type RedeemerType a :: Type
- type DatumType a :: Type
- type ValidatorType (a :: Type) = DatumType a -> RedeemerType a -> ScriptContext -> Bool
- data TypedValidator (a :: Type)
- mkTypedValidator :: CompiledCode (ValidatorType a) -> CompiledCode (ValidatorType a -> UntypedValidator) -> TypedValidator a
- mkTypedValidatorParam :: forall a param. Lift DefaultUni param => CompiledCode (param -> ValidatorType a) -> CompiledCode (ValidatorType a -> UntypedValidator) -> param -> TypedValidator a
- validatorHash :: TypedValidator a -> ValidatorHash
- validatorAddress :: TypedValidator a -> Address
- validatorScript :: TypedValidator a -> Validator
- vValidatorScript :: TypedValidator a -> Versioned Validator
- forwardingMintingPolicy :: TypedValidator a -> MintingPolicy
- vForwardingMintingPolicy :: TypedValidator a -> Versioned MintingPolicy
- forwardingMintingPolicyHash :: TypedValidator a -> MintingPolicyHash
- generalise :: forall a. TypedValidator a -> TypedValidator Any
- data WrongOutTypeError
- data ConnectionError
- = WrongValidatorAddress Address Address
- | WrongOutType WrongOutTypeError
- | WrongValidatorType String
- | WrongRedeemerType BuiltinData
- | WrongDatumType BuiltinData
- | NoDatum TxOutRef DatumHash
- | UnknownRef TxOutRef
- checkValidatorAddress :: forall a m. MonadError ConnectionError m => TypedValidator a -> Address -> m ()
- checkDatum :: forall a m. (FromData (DatumType a), MonadError ConnectionError m) => TypedValidator a -> Datum -> m (DatumType a)
- checkRedeemer :: forall inn m. (FromData (RedeemerType inn), MonadError ConnectionError m) => TypedValidator inn -> Redeemer -> m (RedeemerType inn)
Documentation
type UntypedValidator = BuiltinData -> BuiltinData -> BuiltinData -> () Source #
mkUntypedValidator :: (IsScriptContext sc, UnsafeFromData d, UnsafeFromData r) => (d -> r -> sc -> Bool) -> UntypedValidator Source #
Converts a custom datum and redeemer from a validator function to an untyped validator function. See Note [Scripts returning Bool].
Here's an example of how this function can be used:
import PlutusTx qualified import Plutus.V2.Ledger.Scripts qualified as Plutus import Plutus.Script.Utils.V2.Scripts (mkUntypedValidator) newtype MyCustomDatum = MyCustomDatum Integer PlutusTx.unstableMakeIsData ''MyCustomDatum newtype MyCustomRedeemer = MyCustomRedeemer Integer PlutusTx.unstableMakeIsData ''MyCustomRedeemer mkValidator :: MyCustomDatum -> MyCustomRedeemer -> Plutus.ScriptContext -> Bool mkValidator _ _ _ = True validator :: Plutus.Validator validator = Plutus.mkValidatorScript $$(PlutusTx.compile [|| wrap ||]) where wrap = mkUntypedValidator mkValidator
Here's an example using a parameterized validator:
import PlutusTx qualified
import Plutus.V2.Ledger.Scripts qualified as Plutus
import Plutus.Script.Utils.V2.Scripts (mkUntypedValidator)
newtype MyCustomDatum = MyCustomDatum Integer
PlutusTx.unstableMakeIsData ''MyCustomDatum
newtype MyCustomRedeemer = MyCustomRedeemer Integer
PlutusTx.unstableMakeIsData ''MyCustomRedeemer
mkValidator :: Int -> MyCustomDatum -> MyCustomRedeemer -> Plutus.ScriptContext -> Bool
mkValidator _ _ _ _ = True
validator :: Int -> Plutus.Validator
validator i = Plutus.mkValidatorScript
$$(PlutusTx.compile [|| wrap . mkValidator ||]) applyCode
PlutusTx.liftCode i
where
wrap = mkUntypedValidator
For debugging purpose, it may be of interest to know that in the default implementation, the parameters are decoded in the order they appear (data, redeemer and then script context). A log trace is generated after each successfully decoded parameter. Thus, if a parameter can't be decoded, the culprit is the first parameter in the list that doesn't appear as successfully decoded in the log trace.
class ValidatorTypes (a :: Type) Source #
A class that associates a type standing for a connection type with two types, the type of the redeemer and the data script for that connection type.
type RedeemerType a :: Type Source #
The type of the redeemers of this connection type.
type RedeemerType a = ()
type DatumType a :: Type Source #
The type of the data of this connection type.
type DatumType a = ()
Instances
ValidatorTypes Void Source # | |
Defined in Plutus.Script.Utils.Typed | |
ValidatorTypes Any Source # | |
Defined in Plutus.Script.Utils.Typed |
type ValidatorType (a :: Type) = DatumType a -> RedeemerType a -> ScriptContext -> Bool Source #
The type of validators for the given connection type.
data TypedValidator (a :: Type) Source #
A typed validator script with its ValidatorScript
and Address
.
Instances
:: CompiledCode (ValidatorType a) | Validator script (compiled) |
-> CompiledCode (ValidatorType a -> UntypedValidator) | A wrapper for the compiled validator |
-> TypedValidator a |
Make a TypedValidator
from the CompiledCode
of a validator script and its wrapper.
mkTypedValidatorParam Source #
:: forall a param. Lift DefaultUni param | |
=> CompiledCode (param -> ValidatorType a) | Validator script (compiled) |
-> CompiledCode (ValidatorType a -> UntypedValidator) | A wrapper for the compiled validator |
-> param | The extra paramater for the validator script |
-> TypedValidator a |
Make a TypedValidator
from the CompiledCode
of a parameterized validator script and its wrapper.
validatorHash :: TypedValidator a -> ValidatorHash Source #
The hash of the validator.
validatorAddress :: TypedValidator a -> Address Source #
The address of the validator.
validatorScript :: TypedValidator a -> Validator Source #
The unversioned validator script itself.
vValidatorScript :: TypedValidator a -> Versioned Validator Source #
The validator script itself.
forwardingMintingPolicy :: TypedValidator a -> MintingPolicy Source #
The unversioned minting policy that forwards all checks to the instance's validator
vForwardingMintingPolicy :: TypedValidator a -> Versioned MintingPolicy Source #
The minting policy that forwards all checks to the instance's validator
forwardingMintingPolicyHash :: TypedValidator a -> MintingPolicyHash Source #
Hash of the minting policy that forwards all checks to the instance's validator
generalise :: forall a. TypedValidator a -> TypedValidator Any Source #
Generalise the typed validator to one that works with the Data
type.
data WrongOutTypeError Source #
Instances
data ConnectionError Source #
An error we can get while trying to type an existing transaction part.
WrongValidatorAddress Address Address | |
WrongOutType WrongOutTypeError | |
WrongValidatorType String | |
WrongRedeemerType BuiltinData | |
WrongDatumType BuiltinData | |
NoDatum TxOutRef DatumHash | |
UnknownRef TxOutRef |
Instances
checkValidatorAddress :: forall a m. MonadError ConnectionError m => TypedValidator a -> Address -> m () Source #
Checks that the given validator hash is consistent with the actual validator.
checkDatum :: forall a m. (FromData (DatumType a), MonadError ConnectionError m) => TypedValidator a -> Datum -> m (DatumType a) Source #
Checks that the given datum has the right type.
checkRedeemer :: forall inn m. (FromData (RedeemerType inn), MonadError ConnectionError m) => TypedValidator inn -> Redeemer -> m (RedeemerType inn) Source #
Checks that the given redeemer script has the right type.