morley-1.7.0: Developer tools for the Michelson Language
Safe HaskellNone
LanguageHaskell2010

Michelson.Runtime

Description

Executor and typechecker of a contract in Morley language.

Synopsis

High level interface for end user

originateContract :: FilePath -> Address -> Maybe KeyHash -> Mutez -> Value -> Contract -> ("verbose" :! Bool) -> IO Address Source #

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

runContract :: Maybe Timestamp -> Word64 -> Mutez -> FilePath -> Value -> Contract -> TxData -> ("verbose" :! Bool) -> ("dryRun" :! Bool) -> IO () 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 :: Maybe Timestamp -> Word64 -> FilePath -> Address -> TxData -> ("verbose" :! Bool) -> ("dryRun" :? Bool) -> IO () Source #

Send a transaction to given address with given parameters.

Other helpers

parseExpandContract :: Maybe FilePath -> 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 AddressState Source #

State of an arbitrary address.

Constructors

ASSimple Mutez

For contracts without code we store only its balance.

ASContract ContractState

For contracts with code we store more state represented by ContractState.

Instances

Instances details
Show AddressState Source # 
Instance details

Defined in Michelson.Runtime.GState

Generic AddressState Source # 
Instance details

Defined in Michelson.Runtime.GState

Associated Types

type Rep AddressState :: Type -> Type #

ToJSON AddressState Source # 
Instance details

Defined in Michelson.Runtime.GState

FromJSON AddressState Source # 
Instance details

Defined in Michelson.Runtime.GState

Buildable AddressState Source # 
Instance details

Defined in Michelson.Runtime.GState

type Rep AddressState Source # 
Instance details

Defined in Michelson.Runtime.GState

type Rep AddressState = D1 ('MetaData "AddressState" "Michelson.Runtime.GState" "morley-1.7.0-inplace" 'False) (C1 ('MetaCons "ASSimple" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Mutez)) :+: C1 ('MetaCons "ASContract" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ContractState)))

data TxData Source #

Data associated with a particular transaction.

Instances

Instances details
Show TxData Source # 
Instance details

Defined in 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 Michelson.Runtime.TxData

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 Address TxData

Send a transaction to given address which is assumed to be the address of an originated contract.

Instances

Instances details
Show ExecutorOp Source # 
Instance details

Defined in Michelson.Runtime

data ExecutorRes Source #

Result of a single execution of interpreter.

Constructors

ExecutorRes 

Fields

Instances

Instances details
Show ExecutorRes Source # 
Instance details

Defined in Michelson.Runtime

data ExecutorError' 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

Interpretation of Michelson contract failed.

EEAlreadyOriginated !a !ContractState

A contract is already originated.

EEUnknownSender !a

Sender address is unknown.

EEUnknownManager !a

Manager address is unknown.

EENotEnoughFunds !a !Mutez

Sender doesn't have enough funds.

EEZeroTransaction !a

Sending 0tz towards an address.

EEFailedToApplyUpdates !GStateUpdateError

Failed to apply updates to GState.

EEIllTypedParameter !TCError

Contract parameter is ill-typed.

EEUnexpectedParameterType T 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.

Instances

Instances details
Functor ExecutorError' Source # 
Instance details

Defined in Michelson.Runtime

Methods

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

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

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

Defined in Michelson.Runtime

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

Defined in Michelson.Runtime

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

Defined in Michelson.Runtime

Methods

build :: ExecutorError' a -> Builder #

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

A monad in which contract executor runs.

runExecutorM :: Timestamp -> RemainingSteps -> 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 :: Maybe Timestamp -> FilePath -> RemainingSteps -> ("verbose" :! Bool) -> ("dryRun" :? Bool) -> ExecutorM a -> IO (ExecutorRes, a) Source #

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

Unless dryRun 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 () Source #

Execute a list of global operations, discarding their results.

executeGlobalOrigination :: OriginationOperation -> ExecutorM Address Source #

Execute a global origination operation.

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

Execute an origination operation.

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

Execute a transfer operation.

To avoid warnings (can't generate lenses only for some fields)