Skip to content

Commit

Permalink
Rename ScriptInstance -> TypedValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpj committed Jun 8, 2021
1 parent 5a24d0a commit 2bfe4ba
Show file tree
Hide file tree
Showing 28 changed files with 69 additions and 69 deletions.
2 changes: 1 addition & 1 deletion doc/plutus/tutorials/BasicApps.hs
Expand Up @@ -60,7 +60,7 @@ instance Scripts.ValidatorTypes Split where
type instance RedeemerType Split = ()
type instance DatumType Split = SplitData

splitInstance :: Scripts.ScriptInstance Split
splitInstance :: Scripts.TypedValidator Split
splitInstance = Scripts.validator @Split
$$(PlutusTx.compile [|| validateSplit ||])
$$(PlutusTx.compile [|| wrap ||]) where
Expand Down
2 changes: 1 addition & 1 deletion marlowe/src/Language/Marlowe/Client.hs
Expand Up @@ -598,7 +598,7 @@ mkMarloweValidatorCode params =

type MarloweStateMachine = StateMachine MarloweData MarloweInput

scriptInstance :: MarloweParams -> Scripts.ScriptInstance MarloweStateMachine
scriptInstance :: MarloweParams -> Scripts.TypedValidator MarloweStateMachine
scriptInstance params = Scripts.validator @MarloweStateMachine
(mkMarloweValidatorCode params)
$$(PlutusTx.compile [|| wrap ||])
Expand Down
6 changes: 3 additions & 3 deletions plutus-contract/src/Plutus/Contract/Effects/WriteTx.hs
Expand Up @@ -31,7 +31,7 @@ import Ledger.Constraints (TxConstraints)
import Ledger.Constraints.OffChain (ScriptLookups, UnbalancedTx)
import qualified Ledger.Constraints.OffChain as Constraints
import Ledger.Tx (Tx, txId)
import Ledger.Typed.Scripts (ScriptInstance, ValidatorTypes (..))
import Ledger.Typed.Scripts (TypedValidator, ValidatorTypes (..))

import Wallet.API (WalletAPIError)

Expand Down Expand Up @@ -90,7 +90,7 @@ submitTxConstraints
, PlutusTx.IsData (DatumType a)
, AsContractError e
)
=> ScriptInstance a
=> TypedValidator a
-> TxConstraints (RedeemerType a) (DatumType a)
-> Contract w s e Tx
submitTxConstraints inst = submitTxConstraintsWith (Constraints.scriptInstanceLookups inst)
Expand All @@ -104,7 +104,7 @@ submitTxConstraintsSpending
, PlutusTx.IsData (DatumType a)
, AsContractError e
)
=> ScriptInstance a
=> TypedValidator a
-> UtxoMap
-> TxConstraints (RedeemerType a) (DatumType a)
-> Contract w s e Tx
Expand Down
Expand Up @@ -96,7 +96,7 @@ data StateMachineInstance s i = StateMachineInstance {
-- | The state machine specification.
stateMachine :: StateMachine s i,
-- | The validator code for this state machine.
validatorInstance :: ScriptInstance (StateMachine s i)
validatorInstance :: TypedValidator (StateMachine s i)
}

machineAddress :: StateMachineInstance s i -> Address
Expand Down
22 changes: 11 additions & 11 deletions plutus-ledger/src/Ledger/Constraints/OffChain.hs
Expand Up @@ -59,7 +59,7 @@ import qualified PlutusTx.Numeric as N

import Ledger.Constraints.TxConstraints hiding (requiredSignatories)
import Ledger.Orphans ()
import Ledger.Typed.Scripts (ScriptInstance, ValidatorTypes (..))
import Ledger.Typed.Scripts (TypedValidator, ValidatorTypes (..))
import qualified Ledger.Typed.Scripts as Scripts
import Ledger.Typed.Tx (ConnectionError)
import qualified Ledger.Typed.Tx as Typed
Expand All @@ -83,7 +83,7 @@ data ScriptLookups a =
-- ^ Validators of scripts other than "our script"
, slOtherData :: Map DatumHash Datum
-- ^ Datums that we might need
, slScriptInstance :: Maybe (ScriptInstance a)
, slTypedValidator :: Maybe (TypedValidator a)
-- ^ The script instance with the typed validator hash & actual compiled program
, slOwnPubkey :: Maybe PubKeyHash
-- ^ The contract's public key address, used for depositing tokens etc.
Expand All @@ -98,7 +98,7 @@ instance Semigroup (ScriptLookups a) where
, slOtherScripts = slOtherScripts l <> slOtherScripts r
, slOtherData = slOtherData l <> slOtherData r
-- 'First' to match the semigroup instance of Map (left-biased)
, slScriptInstance = fmap getFirst $ (First <$> slScriptInstance l) <> (First <$> slScriptInstance r)
, slTypedValidator = fmap getFirst $ (First <$> slTypedValidator l) <> (First <$> slTypedValidator r)
, slOwnPubkey = fmap getFirst $ (First <$> slOwnPubkey l) <> (First <$> slOwnPubkey r)

}
Expand All @@ -110,14 +110,14 @@ instance Monoid (ScriptLookups a) where
-- | A script lookups value with a script instance. For convenience this also
-- includes the monetary policy script that forwards all checks to the
-- instance's validator.
scriptInstanceLookups :: ScriptInstance a -> ScriptLookups a
scriptInstanceLookups :: TypedValidator a -> ScriptLookups a
scriptInstanceLookups inst =
ScriptLookups
{ slMPS = Map.singleton (Scripts.monetaryPolicyHash inst) (Scripts.monetaryPolicy inst)
, slTxOutputs = Map.empty
, slOtherScripts = Map.empty
, slOtherData = Map.empty
, slScriptInstance = Just inst
, slTypedValidator = Just inst
, slOwnPubkey = Nothing
}

Expand Down Expand Up @@ -344,8 +344,8 @@ addOwnInput
=> InputConstraint (RedeemerType a)
-> m ()
addOwnInput InputConstraint{icRedeemer, icTxOutRef} = do
ScriptLookups{slTxOutputs, slScriptInstance} <- ask
inst <- maybe (throwError ScriptInstanceMissing) pure slScriptInstance
ScriptLookups{slTxOutputs, slTypedValidator} <- ask
inst <- maybe (throwError TypedValidatorMissing) pure slTypedValidator
typedOutRef <-
either (throwError . TypeCheckFailed) pure
$ runExcept @ConnectionError
Expand All @@ -365,8 +365,8 @@ addOwnOutput
=> OutputConstraint (DatumType a)
-> m ()
addOwnOutput OutputConstraint{ocDatum, ocValue} = do
ScriptLookups{slScriptInstance} <- ask
inst <- maybe (throwError ScriptInstanceMissing) pure slScriptInstance
ScriptLookups{slTypedValidator} <- ask
inst <- maybe (throwError TypedValidatorMissing) pure slTypedValidator
let txOut = Typed.makeTypedScriptTxOut inst ocDatum ocValue
dsV = Datum (toData ocDatum)
unbalancedTx . tx . Tx.outputs %= (Typed.tyTxOutTxOut txOut :)
Expand All @@ -381,7 +381,7 @@ data MkTxError =
| MonetaryPolicyNotFound MonetaryPolicyHash
| ValidatorHashNotFound Address
| OwnPubKeyMissing
| ScriptInstanceMissing
| TypedValidatorMissing
| DatumWrongHash DatumHash Datum
deriving stock (Eq, Show, Generic)
deriving anyclass (ToJSON, FromJSON)
Expand All @@ -395,7 +395,7 @@ instance Pretty MkTxError where
MonetaryPolicyNotFound h -> "No monetary policy with hash" <+> pretty h <+> "was found"
ValidatorHashNotFound h -> "No validator with hash" <+> pretty h <+> "was found"
OwnPubKeyMissing -> "Own public key is missing"
ScriptInstanceMissing -> "Script instance is missing"
TypedValidatorMissing -> "Script instance is missing"
DatumWrongHash h d -> "Wrong hash for datum" <+> pretty d <> colon <+> pretty h

lookupTxOutRef
Expand Down
26 changes: 13 additions & 13 deletions plutus-ledger/src/Ledger/Typed/Scripts.hs
Expand Up @@ -10,7 +10,7 @@
module Ledger.Typed.Scripts(
ValidatorTypes(..)
, Validator
, ScriptInstance
, TypedValidator
, MonetaryPolicy
, validator
, validatorParam
Expand Down Expand Up @@ -41,8 +41,8 @@ import GHC.Generics (Generic)
import Ledger.Typed.Scripts.Validators

-- | A typed validator script with its 'ValidatorScript' and 'Address'.
data ScriptInstance (a :: Type) =
ValidatorInstance
data TypedValidator (a :: Type) =
TypedValidator
{ instanceScript :: Validator
, instanceHash :: ValidatorHash
, instanceMPSHash :: MonetaryPolicyHash
Expand All @@ -52,13 +52,13 @@ data ScriptInstance (a :: Type) =
}
deriving (Show, Eq, Generic, ToJSON, FromJSON)

-- | The 'ScriptInstance' of a validator script and its wrapper.
-- | The 'TypedValidator' of a validator script and its wrapper.
validator ::
CompiledCode (ValidatorType a)
-- ^ Validator script (compiled)
-> CompiledCode (ValidatorType a -> WrappedValidatorType)
-- ^ A wrapper for the compiled validator
-> ScriptInstance a
-> TypedValidator a
validator vc wrapper =
let val = mkValidatorScript $ wrapper `applyCode` vc
hsh = validatorHash val
Expand All @@ -70,7 +70,7 @@ validator vc wrapper =
, instanceMPSHash = Scripts.monetaryPolicyHash mps
}

-- | The 'ScriptInstance' of a paramaterized validator script and its wrapper.
-- | The 'TypedValidator' of a paramaterized validator script and its wrapper.
validatorParam
:: forall a param. Lift DefaultUni param
=> CompiledCode (param -> ValidatorType a)
Expand All @@ -79,24 +79,24 @@ validatorParam
-- ^ A wrapper for the compiled validator
-> param
-- ^ The extra paramater for the validator script
-> ScriptInstance a
-> TypedValidator a
validatorParam vc wrapper param =
validator (vc `PlutusTx.applyCode` PlutusTx.liftCode param) wrapper

-- | The script's 'ValidatorHash'
scriptHash :: ScriptInstance a -> ValidatorHash
scriptHash :: TypedValidator a -> ValidatorHash
scriptHash = instanceHash

-- | Get the address for a script instance.
scriptAddress :: ScriptInstance a -> Addr.Address
scriptAddress :: TypedValidator a -> Addr.Address
scriptAddress = Addr.scriptHashAddress . scriptHash

-- | Get the validator script for a script instance.
validatorScript :: ScriptInstance a -> Validator
validatorScript :: TypedValidator a -> Validator
validatorScript = instanceScript

-- | Script instance for a validator whose type is unknown
fromValidator :: Validator -> ScriptInstance Any
fromValidator :: Validator -> TypedValidator Any
fromValidator vl =
let vh = validatorHash vl
mps = forwardingMPS vh
Expand All @@ -110,10 +110,10 @@ fromValidator vl =

-- | The monetary policy that forwards all checks to the instance's
-- validator
monetaryPolicy :: ScriptInstance a -> MonetaryPolicy
monetaryPolicy :: TypedValidator a -> MonetaryPolicy
monetaryPolicy = instanceMPS

-- | Hash of the monetary policy that forwards all checks to the instance's
-- validator
monetaryPolicyHash :: ScriptInstance a -> MonetaryPolicyHash
monetaryPolicyHash :: TypedValidator a -> MonetaryPolicyHash
monetaryPolicyHash = instanceMPSHash
16 changes: 8 additions & 8 deletions plutus-ledger/src/Ledger/Typed/Tx.hs
Expand Up @@ -63,7 +63,7 @@ instance (ToJSON (DatumType a)) => ToJSON (TypedScriptTxIn a) where
makeTypedScriptTxIn
:: forall inn
. (IsData (RedeemerType inn), IsData (DatumType inn))
=> ScriptInstance inn
=> TypedValidator inn
-> RedeemerType inn
-> TypedScriptTxOutRef inn
-> TypedScriptTxIn inn
Expand Down Expand Up @@ -107,7 +107,7 @@ instance (ToJSON (DatumType a)) => ToJSON (TypedScriptTxOut a) where
makeTypedScriptTxOut
:: forall out
. (IsData (DatumType out))
=> ScriptInstance out
=> TypedValidator out
-> DatumType out
-> Value.Value
-> TypedScriptTxOut out
Expand Down Expand Up @@ -172,7 +172,7 @@ instance Pretty ConnectionError where
UnknownRef -> "Unknown reference"

-- | Checks that the given validator hash is consistent with the actual validator.
checkValidatorAddress :: forall a m . (MonadError ConnectionError m) => ScriptInstance a -> Address -> m ()
checkValidatorAddress :: forall a m . (MonadError ConnectionError m) => TypedValidator a -> Address -> m ()
checkValidatorAddress ct actualAddr = do
let expectedAddr = scriptAddress ct
unless (expectedAddr == actualAddr) $ throwError $ WrongValidatorAddress expectedAddr actualAddr
Expand All @@ -181,7 +181,7 @@ checkValidatorAddress ct actualAddr = do
checkRedeemer
:: forall inn m
. (IsData (RedeemerType inn), MonadError ConnectionError m)
=> ScriptInstance inn
=> TypedValidator inn
-> Redeemer
-> m (RedeemerType inn)
checkRedeemer _ (Redeemer d) =
Expand All @@ -192,7 +192,7 @@ checkRedeemer _ (Redeemer d) =
-- | Checks that the given datum has the right type.
checkDatum
:: forall a m . (IsData (DatumType a), MonadError ConnectionError m)
=> ScriptInstance a
=> TypedValidator a
-> Datum
-> m (DatumType a)
checkDatum _ (Datum d) =
Expand All @@ -207,7 +207,7 @@ typeScriptTxIn
, IsData (DatumType inn)
, MonadError ConnectionError m)
=> (TxOutRef -> Maybe TxOutTx)
-> ScriptInstance inn
-> TypedValidator inn
-> TxIn
-> m (TypedScriptTxIn inn)
typeScriptTxIn lookupRef si TxIn{txInRef,txInType} = do
Expand Down Expand Up @@ -238,7 +238,7 @@ typeScriptTxOut
:: forall out m
. ( IsData (DatumType out)
, MonadError ConnectionError m)
=> ScriptInstance out
=> TypedValidator out
-> TxOutTx
-> m (TypedScriptTxOut out)
typeScriptTxOut si TxOutTx{txOutTxTx=tx, txOutTxOut=TxOut{txOutAddress,txOutValue,txOutDatumHash}} = do
Expand All @@ -260,7 +260,7 @@ typeScriptTxOutRef
. ( IsData (DatumType out)
, MonadError ConnectionError m)
=> (TxOutRef -> Maybe TxOutTx)
-> ScriptInstance out
-> TypedValidator out
-> TxOutRef
-> m (TypedScriptTxOutRef out)
typeScriptTxOutRef lookupRef ct ref = do
Expand Down
2 changes: 1 addition & 1 deletion plutus-playground-server/usecases/Crowdfunding.hs
Expand Up @@ -100,7 +100,7 @@ instance Scripts.ValidatorTypes Crowdfunding where
type instance RedeemerType Crowdfunding = CampaignAction
type instance DatumType Crowdfunding = PubKeyHash

scriptInstance :: Campaign -> Scripts.ScriptInstance Crowdfunding
scriptInstance :: Campaign -> Scripts.TypedValidator Crowdfunding
scriptInstance = Scripts.validatorParam @Crowdfunding
$$(PlutusTx.compile [|| mkValidator ||])
$$(PlutusTx.compile [|| wrap ||])
Expand Down
2 changes: 1 addition & 1 deletion plutus-playground-server/usecases/Game.hs
Expand Up @@ -55,7 +55,7 @@ instance Scripts.ValidatorTypes Game where
type instance RedeemerType Game = ClearString
type instance DatumType Game = HashedString

gameInstance :: Scripts.ScriptInstance Game
gameInstance :: Scripts.TypedValidator Game
gameInstance = Scripts.validator @Game
$$(PlutusTx.compile [|| validateGuess ||])
$$(PlutusTx.compile [|| wrap ||]) where
Expand Down
2 changes: 1 addition & 1 deletion plutus-playground-server/usecases/Starter.hs
Expand Up @@ -59,7 +59,7 @@ instance Scripts.ValidatorTypes Starter where
type instance DatumType Starter = MyDatum

-- | The script instance is the compiled validator (ready to go onto the chain)
starterInstance :: Scripts.ScriptInstance Starter
starterInstance :: Scripts.TypedValidator Starter
starterInstance = Scripts.validator @Starter
$$(PlutusTx.compile [|| validateSpend ||])
$$(PlutusTx.compile [|| wrap ||]) where
Expand Down
2 changes: 1 addition & 1 deletion plutus-playground-server/usecases/Vesting.hs
Expand Up @@ -136,7 +136,7 @@ instance Scripts.ValidatorTypes Vesting where
vestingScript :: VestingParams -> Validator
vestingScript = Scripts.validatorScript . scriptInstance

scriptInstance :: VestingParams -> Scripts.ScriptInstance Vesting
scriptInstance :: VestingParams -> Scripts.TypedValidator Vesting
scriptInstance = Scripts.validatorParam @Vesting
$$(PlutusTx.compile [|| validate ||])
$$(PlutusTx.compile [|| wrap ||])
Expand Down
4 changes: 2 additions & 2 deletions plutus-use-cases/src/Plutus/Contracts/Auction.hs
Expand Up @@ -152,7 +152,7 @@ auctionStateMachine threadToken auctionParams = SM.mkStateMachine (Just threadTo

-- | The script instance of the auction state machine. It contains the state
-- machine compiled to a Plutus core validator script.
scriptInstance :: AssetClass -> AuctionParams -> Scripts.ScriptInstance (StateMachine AuctionState AuctionInput)
scriptInstance :: AssetClass -> AuctionParams -> Scripts.TypedValidator (StateMachine AuctionState AuctionInput)
scriptInstance currency auctionParams =
let val = $$(PlutusTx.compile [|| validatorParam ||])
`PlutusTx.applyCode`
Expand All @@ -170,7 +170,7 @@ scriptInstance currency auctionParams =
-- with the on-chain code, and the Haskell definition of the state machine for
-- off-chain use.
machineClient
:: Scripts.ScriptInstance (StateMachine AuctionState AuctionInput)
:: Scripts.TypedValidator (StateMachine AuctionState AuctionInput)
-> AssetClass -- ^ Thread token of the instance
-> AuctionParams
-> StateMachineClient AuctionState AuctionInput
Expand Down
2 changes: 1 addition & 1 deletion plutus-use-cases/src/Plutus/Contracts/Crowdfunding.hs
Expand Up @@ -137,7 +137,7 @@ instance Scripts.ValidatorTypes Crowdfunding where
type instance RedeemerType Crowdfunding = CampaignAction
type instance DatumType Crowdfunding = PubKeyHash

scriptInstance :: Campaign -> Scripts.ScriptInstance Crowdfunding
scriptInstance :: Campaign -> Scripts.TypedValidator Crowdfunding
scriptInstance = Scripts.validatorParam @Crowdfunding
$$(PlutusTx.compile [|| mkValidator ||])
$$(PlutusTx.compile [|| wrap ||])
Expand Down

0 comments on commit 2bfe4ba

Please sign in to comment.