From bf1b895a10d2c2572d75052c8993fc85001d750e Mon Sep 17 00:00:00 2001 From: Michael Peyton Jones Date: Fri, 4 Jun 2021 15:20:46 +0100 Subject: [PATCH] Doc fixups --- doc/plutus/tutorials/BasicApps.hs | 10 +++++----- doc/plutus/tutorials/BasicValidators.hs | 10 +++++----- doc/plutus/tutorials/GameModel.hs | 3 +-- doc/plutus/tutorials/basic-apps.rst | 2 +- doc/plutus/tutorials/basic-validators.rst | 4 ++-- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/doc/plutus/tutorials/BasicApps.hs b/doc/plutus/tutorials/BasicApps.hs index bb5cfb5464f..48bf6dba2b8 100644 --- a/doc/plutus/tutorials/BasicApps.hs +++ b/doc/plutus/tutorials/BasicApps.hs @@ -60,8 +60,8 @@ instance Scripts.ValidatorTypes Split where type instance RedeemerType Split = () type instance DatumType Split = SplitData -splitInstance :: Scripts.TypedValidator Split -splitInstance = Scripts.mkTypedValidator @Split +splitValidator :: Scripts.TypedValidator Split +splitValidator = Scripts.mkTypedValidator @Split $$(PlutusTx.compile [|| validateSplit ||]) $$(PlutusTx.compile [|| wrap ||]) where wrap = Scripts.wrapValidator @SplitData @() @@ -109,20 +109,20 @@ lockFunds :: SplitData -> Contract () SplitSchema T.Text () lockFunds s@SplitData{amount} = do logInfo $ "Locking " <> Haskell.show amount let tx = Constraints.mustPayToTheScript s (Ada.toValue amount) - void $ submitTxConstraints splitInstance tx + void $ submitTxConstraints splitValidator tx -- BLOCK8 unlockFunds :: SplitData -> Contract () SplitSchema T.Text () unlockFunds SplitData{recipient1, recipient2, amount} = do - let contractAddress = Ledger.validatorAddress splitInstance + let contractAddress = Scripts.validatorAddress splitValidator utxos <- utxoAt contractAddress let half = Ada.divide amount 2 tx = collectFromScript utxos () <> Constraints.mustPayToPubKey recipient1 (Ada.toValue half) <> Constraints.mustPayToPubKey recipient2 (Ada.toValue $ amount - half) - void $ submitTxConstraintsSpending splitInstance utxos tx + void $ submitTxConstraintsSpending splitValidator utxos tx -- BLOCK9 diff --git a/doc/plutus/tutorials/BasicValidators.hs b/doc/plutus/tutorials/BasicValidators.hs index 92b090ce16c..d0dd0e6d763 100644 --- a/doc/plutus/tutorials/BasicValidators.hs +++ b/doc/plutus/tutorials/BasicValidators.hs @@ -12,7 +12,7 @@ import PlutusTx import PlutusTx.Lift import PlutusTx.Prelude -import Ledger hiding (ScriptType) +import Ledger hiding (validatorHash) import Ledger.Ada import Ledger.Typed.Scripts import Ledger.Value @@ -84,7 +84,7 @@ validatePayment _ _ ctx = check $ case fromData ctx of _ -> False -- BLOCK5 data DateValidator -instance ScriptType DateValidator where +instance ValidatorTypes DateValidator where type instance RedeemerType DateValidator = Date type instance DatumType DateValidator = EndDate -- BLOCK6 @@ -94,8 +94,8 @@ validateDateTyped endDate date _ = beforeEnd date endDate validateDateWrapped :: Data -> Data -> Data -> () validateDateWrapped = wrapValidator validateDateTyped -- BLOCK7 -dateInstance :: ScriptInstance DateValidator -dateInstance = validator @DateValidator +dateInstance :: TypedValidator DateValidator +dateInstance = mkTypedValidator @DateValidator -- The first argument is the compiled validator. $$(compile [|| validateDateTyped ||]) -- The second argument is a compiled wrapper. @@ -105,7 +105,7 @@ dateInstance = validator @DateValidator wrap = wrapValidator dateValidatorHash :: ValidatorHash -dateValidatorHash = scriptHash dateInstance +dateValidatorHash = validatorHash dateInstance dateValidator :: Validator dateValidator = validatorScript dateInstance diff --git a/doc/plutus/tutorials/GameModel.hs b/doc/plutus/tutorials/GameModel.hs index ef219f43829..b3b886bc61a 100644 --- a/doc/plutus/tutorials/GameModel.hs +++ b/doc/plutus/tutorials/GameModel.hs @@ -300,7 +300,7 @@ wallets = [w1, w2, w3] -- START gameTokenVal gameTokenVal :: Value gameTokenVal = - let sym = Scripts.monetaryPolicyHash G.typedValidator + let sym = Scripts.forwardingMonetaryPolicyHash G.typedValidator in G.token sym "guess" -- END gameTokenVal @@ -580,4 +580,3 @@ typeSignatures = id chooseQ :: (Arbitrary a, Random a, Ord a) => (a, a) -> Quantification a -- END chooseQ type chooseQ = ContractModel.chooseQ - diff --git a/doc/plutus/tutorials/basic-apps.rst b/doc/plutus/tutorials/basic-apps.rst index e0194f473e8..4a7590de551 100644 --- a/doc/plutus/tutorials/basic-apps.rst +++ b/doc/plutus/tutorials/basic-apps.rst @@ -74,7 +74,7 @@ You then need some boilerplate to compile the validator to a Plutus script (see :start-after: BLOCK3 :end-before: BLOCK4 -The :hsobj:`Ledger.Typed.Scripts.Validators.ValidatorTypes` class defines the types of the validator, and ``splitInstance`` contains the compiled Plutus core code of ``validateSplit``. +The :hsobj:`Ledger.Typed.Scripts.Validators.ValidatorTypes` class defines the types of the validator, and ``splitValidator`` contains the compiled Plutus core code of ``validateSplit``. Asking for input ---------------- diff --git a/doc/plutus/tutorials/basic-validators.rst b/doc/plutus/tutorials/basic-validators.rst index 219bf6eb4cf..7c52376e527 100644 --- a/doc/plutus/tutorials/basic-validators.rst +++ b/doc/plutus/tutorials/basic-validators.rst @@ -109,7 +109,7 @@ There is a higher-level interface in :hsmod:`Ledger.Typed.Scripts` which handles To use it, we first need to define a datatype that we can use to identify the particular validator that we are working on. This data type is empty, because we're just going to use it as a "name": it helps the Haskell type system know what to look for. -We then define an instance of :hsobj:`Ledger.Typed.Scripts.Validators.ScriptType` for our "name". +We then define an instance of :hsobj:`Ledger.Typed.Scripts.Validators.ValidatorTypes` for our "name". This tells the compiler what the Haskell types for the redeemer and datum are, so that the compiler can check whether we're using the right ones later. .. literalinclude:: BasicValidators.hs @@ -125,7 +125,7 @@ This takes advantage of the information we provided in our ``ScriptType`` instan :start-after: BLOCK6 :end-before: BLOCK7 -Finally, we can use the :hsobj:`Ledger.Typed.Scripts.validator` function to get a :hsobj:`Ledger.Typed.Scripts.ScriptInstance`. +Finally, we can use the :hsobj:`Ledger.Typed.Scripts.Validators.mkTypedValidator` function to get a :hsobj:`Ledger.Typed.Scripts.Validators.TypedValidator`. This packages up the compiled validator for us, letting us pull out the compiled version, the hash, the address, and a few other useful things. .. literalinclude:: BasicValidators.hs