morley-1.20.0: Developer tools for the Michelson Language
Safe HaskellSafe-Inferred
LanguageHaskell2010

Morley.Michelson.Runtime

Description

Executor and typechecker of a contract in Morley language.

Synopsis

High level interface for end user

originateContract :: ("dbPath" :! FilePath) -> ("tcOpts" :? TypeCheckOptions) -> ("originator" :? ImplicitAddress) -> ("alias" :? ContractAlias) -> ("delegate" :? KeyHash) -> ("csod" :! ContractSimpleOriginationData Contract) -> ("verbose" :? Bool) -> IO ContractAddress Source #

Originate a contract. Returns the address of the originated contract.

runContract :: CommonRunOptions -> ContractSimpleOriginationData Contract -> TxData -> IO SomeStorage Source #

Run a contract. The contract is originated first (if it's not already) and then we pretend that we send a transaction to it.

transfer :: CommonRunOptions -> SomeAddressOrAlias -> TxData -> IO () Source #

Send a transaction to given address with given parameters.

runCode :: RunCodeParameters cp epArg st -> Either (InterpretError Void) ([Operation], Value st) Source #

Emulate run_code RPC endpoint to an extent. Unlike runContract, runs the contract through the emulator directly, without doing any operations. This includes not doing the origination operation, and not applying the operations produced by the transfer.

runView :: CommonRunOptions -> ContractSpecification (ContractSimpleOriginationData Contract) -> ViewName -> SomeAddressOrAlias -> TxParam -> IO SomeValue Source #

Run a contract view. The contract is originated first (if it's not already) and then we pretend that we send a transaction to it.

data RunCodeParameters cp epArg st Source #

Data required for calling runCode.

Constructors

RunCodeParameters 

Fields

runCodeParameters Source #

Arguments

:: Contract cp st

Contract to run

-> Value st

Contract storage

-> EntrypointCallT cp epArg

Entrypoint call specification

-> Value epArg

Entrypoint argument

-> RunCodeParameters cp epArg st 

Construct RunCodeParameters with some reasonable defaults.

Prepare untyped storage and parameter with resolveRunCodeBigMaps.

Use mkEntrypointCall or mkDefEntrypointCall to construct the entrypoint call specification.

resolveRunCodeBigMaps :: SingI t => BigMapFinder -> Value -> Either TcError (Value t) Source #

Given an untyped value, possibly containing big_map ids, typecheck it, resolving ids to the corresponding big_maps.

BigMapFinder can be constructed using mkBigMapFinder.

mkBigMapFinder :: ExecutorM BigMapFinder Source #

Construct BigMapFinder using the current executor context.

data ContractSpecification a Source #

Instances

Instances details
Foldable ContractSpecification Source # 
Instance details

Defined in Morley.Michelson.Runtime

Methods

fold :: Monoid m => ContractSpecification m -> m #

foldMap :: Monoid m => (a -> m) -> ContractSpecification a -> m #

foldMap' :: Monoid m => (a -> m) -> ContractSpecification a -> m #

foldr :: (a -> b -> b) -> b -> ContractSpecification a -> b #

foldr' :: (a -> b -> b) -> b -> ContractSpecification a -> b #

foldl :: (b -> a -> b) -> b -> ContractSpecification a -> b #

foldl' :: (b -> a -> b) -> b -> ContractSpecification a -> b #

foldr1 :: (a -> a -> a) -> ContractSpecification a -> a #

foldl1 :: (a -> a -> a) -> ContractSpecification a -> a #

toList :: ContractSpecification a -> [a] #

null :: ContractSpecification a -> Bool #

length :: ContractSpecification a -> Int #

elem :: Eq a => a -> ContractSpecification a -> Bool #

maximum :: Ord a => ContractSpecification a -> a #

minimum :: Ord a => ContractSpecification a -> a #

sum :: Num a => ContractSpecification a -> a #

product :: Num a => ContractSpecification a -> a #

Traversable ContractSpecification Source # 
Instance details

Defined in Morley.Michelson.Runtime

Functor ContractSpecification Source # 
Instance details

Defined in Morley.Michelson.Runtime

data ContractSimpleOriginationData a Source #

Instances

Instances details
Foldable ContractSimpleOriginationData Source # 
Instance details

Defined in Morley.Michelson.Runtime

Traversable ContractSimpleOriginationData Source # 
Instance details

Defined in Morley.Michelson.Runtime

Functor ContractSimpleOriginationData Source # 
Instance details

Defined in Morley.Michelson.Runtime

Other helpers

parseExpandContract :: MichelsonSource -> Text -> Either ParserException Contract Source #

Parse a contract from Text and expand macros.

readAndParseContract :: Maybe FilePath -> IO (Contract' ParsedOp) Source #

Read and parse a contract from give path or stdin (if the argument is Nothing). The contract is not expanded.

prepareContract :: Maybe FilePath -> IO Contract Source #

Read a contract using readAndParseContract, expand and flatten. The contract is not type checked.

Re-exports

data ContractState Source #

State of a contract with code.

Constructors

forall cp st.(ParameterScope cp, StorageScope st) => ContractState 

Fields

data VotingPowers Source #

Distribution of voting power among the contracts.

Voting power reflects the ability of bakers to accept, deny or pass new proposals for protocol updates. I.e. each baker has its vote weight.

This datatype definition may change in future, so its internals are not exported.

mkVotingPowers :: [(KeyHash, Natural)] -> VotingPowers Source #

Create voting power distribution.

If some key is encountered multiple times, voting power will be summed up.

mkVotingPowersFromMap :: Map KeyHash Natural -> VotingPowers Source #

Create voting power distribution from map.

data TxData Source #

Data associated with a particular transaction.

Instances

Instances details
Show TxData Source # 
Instance details

Defined in Morley.Michelson.Runtime.TxData

data TxParam where Source #

A parameter associated with a particular transaction.

Constructors

TxTypedParam :: forall t. ParameterScope t => Value t -> TxParam 
TxUntypedParam :: Value -> TxParam 

Instances

Instances details
Show TxParam Source # 
Instance details

Defined in Morley.Michelson.Runtime.TxData

Buildable TxParam Source # 
Instance details

Defined in Morley.Michelson.Runtime.TxData

Methods

build :: TxParam -> Doc

buildList :: [TxParam] -> Doc

For testing

data ExecutorOp Source #

Operations executed by interpreter. In our model one Michelson's operation (operation type in Michelson) corresponds to 0 or 1 interpreter operation.

Note: Address is not part of TxData, because TxData is supposed to be provided by the user, while Address can be computed by our code.

Constructors

OriginateOp OriginationOperation

Originate a contract.

TransferOp TransferOperation

Transfer tokens to the address.

SetDelegateOp SetDelegateOperation

Set the delegate of a contract.

EmitOp EmitOperation

Emit contract event.

Instances

Instances details
Show ExecutorOp Source # 
Instance details

Defined in Morley.Michelson.Runtime

Buildable ExecutorOp Source # 
Instance details

Defined in Morley.Michelson.Runtime

Methods

build :: ExecutorOp -> Doc

buildList :: [ExecutorOp] -> Doc

data ExecutorRes Source #

Result of a single execution of interpreter.

Constructors

ExecutorRes 

Fields

Instances

Instances details
Show ExecutorRes Source # 
Instance details

Defined in Morley.Michelson.Runtime

data ExecutorError' a Source #

ExecutorErrorPrim, enriched by the list of operations that succeeded before the error.

Instances

Instances details
Foldable ExecutorError' Source # 
Instance details

Defined in Morley.Michelson.Runtime

Methods

fold :: Monoid m => ExecutorError' m -> m #

foldMap :: Monoid m => (a -> m) -> ExecutorError' a -> m #

foldMap' :: Monoid m => (a -> m) -> ExecutorError' a -> m #

foldr :: (a -> b -> b) -> b -> ExecutorError' a -> b #

foldr' :: (a -> b -> b) -> b -> ExecutorError' a -> b #

foldl :: (b -> a -> b) -> b -> ExecutorError' a -> b #

foldl' :: (b -> a -> b) -> b -> ExecutorError' a -> b #

foldr1 :: (a -> a -> a) -> ExecutorError' a -> a #

foldl1 :: (a -> a -> a) -> ExecutorError' a -> a #

toList :: ExecutorError' a -> [a] #

null :: ExecutorError' a -> Bool #

length :: ExecutorError' a -> Int #

elem :: Eq a => a -> ExecutorError' a -> Bool #

maximum :: Ord a => ExecutorError' a -> a #

minimum :: Ord a => ExecutorError' a -> a #

sum :: Num a => ExecutorError' a -> a #

product :: Num a => ExecutorError' a -> a #

Traversable ExecutorError' Source # 
Instance details

Defined in Morley.Michelson.Runtime

Methods

traverse :: Applicative f => (a -> f b) -> ExecutorError' a -> f (ExecutorError' b) #

sequenceA :: Applicative f => ExecutorError' (f a) -> f (ExecutorError' a) #

mapM :: Monad m => (a -> m b) -> ExecutorError' a -> m (ExecutorError' b) #

sequence :: Monad m => ExecutorError' (m a) -> m (ExecutorError' a) #

Functor ExecutorError' Source # 
Instance details

Defined in Morley.Michelson.Runtime

Methods

fmap :: (a -> b) -> ExecutorError' a -> ExecutorError' b #

(<$) :: a -> ExecutorError' b -> ExecutorError' a #

(Typeable a, Show a, Buildable a) => Exception (ExecutorError' a) Source # 
Instance details

Defined in Morley.Michelson.Runtime

Show a => Show (ExecutorError' a) Source # 
Instance details

Defined in Morley.Michelson.Runtime

Buildable a => Buildable (ExecutorError' a) Source # 
Instance details

Defined in Morley.Michelson.Runtime

Methods

build :: ExecutorError' a -> Doc

buildList :: [ExecutorError' a] -> Doc

data ExecutorErrorPrim a Source #

Errors that can happen during contract interpreting. Type parameter a determines how contracts will be represented in these errors, e.g. Address.

Constructors

EEUnknownContract a

The interpreted contract hasn't been originated.

EEInterpreterFailed a (InterpretError Void)

Interpretation of Michelson contract failed.

EEViewLookupError a ViewLookupError

Error looking up view while trying to call it.

EEViewArgTcError a TcError

Error type-checking untyped view argument.

EEUnknownAddressAlias SomeAlias

The given alias isn't associated with any address OR is associated with an address of an unexpected kind (e.g. we expected an implicit address and found a contract address, or vice-versa).

EEUnknownL1AddressAlias Text

The given alias is not associated with any address.

EEAmbiguousAlias Text ImplicitAddress ContractAddress

The given alias is ambiguous, i.e. it is associated with both an implicit address and a contract address.

EEUnknownSender a

Sender address is unknown.

EEUnknownManager a

Manager address is unknown.

EENotEnoughFunds a Mutez

Sender doesn't have enough funds.

EEEmptyImplicitContract a

Sender is an implicit address with the balance of 0. We mimic octez-client in calling it "Empty implicit contract".

EEZeroTransaction a

Sending 0tz towards an address.

EEFailedToApplyUpdates GStateUpdateError

Failed to apply updates to GState.

EEIllTypedParameter a TcError

Contract parameter is ill-typed.

EEDeprecatedType TcError

Found deprecated types.

EEUnexpectedParameterType a (MismatchError T)

Contract parameter is well-typed, but its type does not match the entrypoint's type.

EEUnknownEntrypoint EpName

Specified entrypoint to run is not found.

EETransactionFromContract a Mutez

A transaction from an originated contract was attempted as a global operation.

EEWrongParameterType a

Type of parameter in transfer to an implicit account is not Unit.

EEOperationReplay ExecutorOp

An attempt to perform the operation duplicated with DUP instruction.

EEGlobalOperationSourceNotImplicit Address

Attempted to initiate global operation from a non-implicit address.

EEGlobalEmitOp

Trying to run emit operation as a global operation, which should be impossible.

Instances

Instances details
Foldable ExecutorErrorPrim Source # 
Instance details

Defined in Morley.Michelson.Runtime

Methods

fold :: Monoid m => ExecutorErrorPrim m -> m #

foldMap :: Monoid m => (a -> m) -> ExecutorErrorPrim a -> m #

foldMap' :: Monoid m => (a -> m) -> ExecutorErrorPrim a -> m #

foldr :: (a -> b -> b) -> b -> ExecutorErrorPrim a -> b #

foldr' :: (a -> b -> b) -> b -> ExecutorErrorPrim a -> b #

foldl :: (b -> a -> b) -> b -> ExecutorErrorPrim a -> b #

foldl' :: (b -> a -> b) -> b -> ExecutorErrorPrim a -> b #

foldr1 :: (a -> a -> a) -> ExecutorErrorPrim a -> a #

foldl1 :: (a -> a -> a) -> ExecutorErrorPrim a -> a #

toList :: ExecutorErrorPrim a -> [a] #

null :: ExecutorErrorPrim a -> Bool #

length :: ExecutorErrorPrim a -> Int #

elem :: Eq a => a -> ExecutorErrorPrim a -> Bool #

maximum :: Ord a => ExecutorErrorPrim a -> a #

minimum :: Ord a => ExecutorErrorPrim a -> a #

sum :: Num a => ExecutorErrorPrim a -> a #

product :: Num a => ExecutorErrorPrim a -> a #

Traversable ExecutorErrorPrim Source # 
Instance details

Defined in Morley.Michelson.Runtime

Methods

traverse :: Applicative f => (a -> f b) -> ExecutorErrorPrim a -> f (ExecutorErrorPrim b) #

sequenceA :: Applicative f => ExecutorErrorPrim (f a) -> f (ExecutorErrorPrim a) #

mapM :: Monad m => (a -> m b) -> ExecutorErrorPrim a -> m (ExecutorErrorPrim b) #

sequence :: Monad m => ExecutorErrorPrim (m a) -> m (ExecutorErrorPrim a) #

Functor ExecutorErrorPrim Source # 
Instance details

Defined in Morley.Michelson.Runtime

(Typeable a, Show a, Buildable a) => Exception (ExecutorErrorPrim a) Source #

To reduce friction between ExecutorError' and ExecutorErrorPrim, this instance will try to run fromException for both.

Instance details

Defined in Morley.Michelson.Runtime

Show a => Show (ExecutorErrorPrim a) Source # 
Instance details

Defined in Morley.Michelson.Runtime

Buildable a => Buildable (ExecutorErrorPrim a) Source # 
Instance details

Defined in Morley.Michelson.Runtime

Methods

build :: ExecutorErrorPrim a -> Doc

buildList :: [ExecutorErrorPrim a] -> Doc

type ExecutorM = ReaderT ExecutorEnv (StateT ExecutorState (Except ExecutorError)) Source #

A monad in which contract executor runs.

runExecutorM :: Timestamp -> Natural -> Natural -> RemainingSteps -> TypeCheckOptions -> GState -> ExecutorM a -> Either ExecutorError (ExecutorRes, a) Source #

Run some executor action, returning its result and final executor state in ExecutorRes.

The action has access to the hash of currently executed global operation, in order to construct addresses of originated contracts. It is expected that the action uses #isGlobalOp :! True to specify this hash. Otherwise it is initialized with error.

runExecutorMWithDB :: CommonRunOptions -> ExecutorM a -> IO (ExecutorRes, a) Source #

Run some executor action, reading state from the DB on disk.

If croDryRun is False, the final state is written back to the disk.

If the executor fails with ExecutorError it will be thrown as an exception.

executeGlobalOperations :: [ExecutorOp] -> ExecutorM [EmitOperation] Source #

Execute a list of global operations, returning a list of generated events.

executeGlobalOrigination :: OriginationOperation -> ExecutorM ContractAddress Source #

Execute a global origination operation.

executeOrigination :: ("isGlobalOp" :! Bool) -> OriginationOperation -> ExecutorM ContractAddress Source #

Execute an origination operation.

executeTransfer :: ("isGlobalOp" :! Bool) -> TransferOperation -> ExecutorM [ExecutorOp] Source #

Execute a transfer operation.

Note: we're handling both XTZ and ticket transfers here to avoid code duplication. We assume that if an implicit account sends tickets via TxTypedParam, it should be interpreted as transfer_ticket manager operation, and not a regular transfer.

Note that this only works for TxTypedParam, as for ticket transfers between implicit accounts we can't know the exact type of the ticket to transfer if the value is untyped.

data ExecutorState Source #

Instances

Instances details
Generic ExecutorState Source # 
Instance details

Defined in Morley.Michelson.Runtime

Associated Types

type Rep ExecutorState :: Type -> Type #

Show ExecutorState Source # 
Instance details

Defined in Morley.Michelson.Runtime

type Rep ExecutorState Source # 
Instance details

Defined in Morley.Michelson.Runtime

data ExecutorLog Source #

Instances

Instances details
Monoid ExecutorLog Source # 
Instance details

Defined in Morley.Michelson.Runtime

Semigroup ExecutorLog Source # 
Instance details

Defined in Morley.Michelson.Runtime

Generic ExecutorLog Source # 
Instance details

Defined in Morley.Michelson.Runtime

Associated Types

type Rep ExecutorLog :: Type -> Type #

Show ExecutorLog Source # 
Instance details

Defined in Morley.Michelson.Runtime

type Rep ExecutorLog Source # 
Instance details

Defined in Morley.Michelson.Runtime

type Rep ExecutorLog = D1 ('MetaData "ExecutorLog" "Morley.Michelson.Runtime" "morley-1.20.0-inplace" 'False) (C1 ('MetaCons "ExecutorLog" 'PrefixI 'True) (S1 ('MetaSel ('Just "_elUpdates") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 [GStateUpdate]) :*: S1 ('MetaSel ('Just "_elInterpreterResults") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 [(Address, SomeInterpretResult)])))