Skip to content

Commit

Permalink
Doc fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpj committed Jun 8, 2021
1 parent 87a4f08 commit bf1b895
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
10 changes: 5 additions & 5 deletions doc/plutus/tutorials/BasicApps.hs
Expand Up @@ -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 @()
Expand Down Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions doc/plutus/tutorials/BasicValidators.hs
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -105,7 +105,7 @@ dateInstance = validator @DateValidator
wrap = wrapValidator

dateValidatorHash :: ValidatorHash
dateValidatorHash = scriptHash dateInstance
dateValidatorHash = validatorHash dateInstance

dateValidator :: Validator
dateValidator = validatorScript dateInstance
Expand Down
3 changes: 1 addition & 2 deletions doc/plutus/tutorials/GameModel.hs
Expand Up @@ -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

Expand Down Expand Up @@ -580,4 +580,3 @@ typeSignatures = id
chooseQ :: (Arbitrary a, Random a, Ord a) => (a, a) -> Quantification a
-- END chooseQ type
chooseQ = ContractModel.chooseQ

2 changes: 1 addition & 1 deletion doc/plutus/tutorials/basic-apps.rst
Expand Up @@ -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
----------------
Expand Down
4 changes: 2 additions & 2 deletions doc/plutus/tutorials/basic-validators.rst
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit bf1b895

Please sign in to comment.