Safe Haskell | None |
---|---|
Language | Haskell2010 |
Executor and typechecker of a contract in Morley language.
Synopsis
- originateContract :: FilePath -> TypeCheckOptions -> Address -> Maybe KeyHash -> Mutez -> Value -> Contract -> ("verbose" :! Bool) -> IO Address
- runContract :: Maybe Timestamp -> Maybe Natural -> Word64 -> Mutez -> FilePath -> TypeCheckOptions -> Value -> Contract -> TxData -> ("verbose" :! Bool) -> ("dryRun" :! Bool) -> IO SomeStorage
- transfer :: Maybe Timestamp -> Maybe Natural -> Word64 -> FilePath -> TypeCheckOptions -> Address -> TxData -> ("verbose" :! Bool) -> ("dryRun" :? Bool) -> IO ()
- parseContract :: MichelsonSource -> Text -> Either ParserException (Contract' ParsedOp)
- parseExpandContract :: MichelsonSource -> Text -> Either ParserException Contract
- readAndParseContract :: Maybe FilePath -> IO (Contract' ParsedOp)
- prepareContract :: Maybe FilePath -> IO Contract
- data ContractState = forall cp st.(ParameterScope cp, StorageScope st) => ContractState {
- csBalance :: Mutez
- csContract :: Contract cp st
- csStorage :: Value st
- csDelegate :: Maybe KeyHash
- data AddressState
- data VotingPowers
- mkVotingPowers :: [(KeyHash, Natural)] -> VotingPowers
- mkVotingPowersFromMap :: Map KeyHash Natural -> VotingPowers
- data TxData = TxData {}
- data TxParam where
- TxTypedParam :: forall t. ParameterScope t => Value t -> TxParam
- TxUntypedParam :: Value -> TxParam
- data ExecutorOp
- data ExecutorRes = ExecutorRes {}
- data ExecutorError' a
- = EEUnknownContract a
- | EEInterpreterFailed a InterpretError
- | EEAlreadyOriginated a ContractState
- | EEUnknownSender a
- | EEUnknownManager a
- | EENotEnoughFunds a Mutez
- | EEZeroTransaction a
- | EEFailedToApplyUpdates GStateUpdateError
- | EEIllTypedParameter a TCError
- | EEUnexpectedParameterType a T T
- | EEUnknownEntrypoint EpName
- | EETransactionFromContract a Mutez
- | EEWrongParameterType a
- | EEOperationReplay ExecutorOp
- type ExecutorError = ExecutorError' Address
- type ExecutorM = ReaderT ExecutorEnv (StateT ExecutorState (Except ExecutorError))
- runExecutorM :: Timestamp -> Natural -> RemainingSteps -> GState -> ExecutorM a -> Either ExecutorError (ExecutorRes, a)
- runExecutorMWithDB :: Maybe Timestamp -> Maybe Natural -> FilePath -> RemainingSteps -> ("verbose" :! Bool) -> ("dryRun" :? Bool) -> ExecutorM a -> IO (ExecutorRes, a)
- executeGlobalOperations :: TypeCheckOptions -> [ExecutorOp] -> ExecutorM ()
- executeGlobalOrigination :: OriginationOperation -> ExecutorM Address
- executeOrigination :: ("isGlobalOp" :! Bool) -> OriginationOperation -> ExecutorM Address
- executeTransfer :: ("isGlobalOp" :! Bool) -> TypeCheckOptions -> TransferOperation -> ExecutorM [ExecutorOp]
- erInterpretResults :: Lens' ExecutorRes [(Address, InterpretResult)]
- erUpdates :: Lens' ExecutorRes [GStateUpdate]
- erGState :: Lens' ExecutorRes GState
- erRemainingSteps :: Lens' ExecutorRes RemainingSteps
- elInterpreterResults :: Lens' ExecutorLog [(Address, InterpretResult)]
- elUpdates :: Lens' ExecutorLog [GStateUpdate]
High level interface for end user
originateContract :: FilePath -> TypeCheckOptions -> Address -> Maybe KeyHash -> Mutez -> Value -> Contract -> ("verbose" :! Bool) -> IO Address Source #
Originate a contract. Returns the address of the originated contract.
runContract :: Maybe Timestamp -> Maybe Natural -> Word64 -> Mutez -> FilePath -> TypeCheckOptions -> Value -> Contract -> TxData -> ("verbose" :! Bool) -> ("dryRun" :! Bool) -> 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 :: Maybe Timestamp -> Maybe Natural -> Word64 -> FilePath -> TypeCheckOptions -> Address -> TxData -> ("verbose" :! Bool) -> ("dryRun" :? Bool) -> IO () Source #
Send a transaction to given address with given parameters.
Other helpers
parseContract :: MichelsonSource -> Text -> Either ParserException (Contract' ParsedOp) Source #
Parse a contract from Text
.
parseExpandContract :: MichelsonSource -> Text -> Either ParserException Contract Source #
Parse a contract from Text
and expand macros.
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.
forall cp st.(ParameterScope cp, StorageScope st) => ContractState | |
|
Instances
Show ContractState Source # | |
Defined in Morley.Michelson.Runtime.GState showsPrec :: Int -> ContractState -> ShowS # show :: ContractState -> String # showList :: [ContractState] -> ShowS # | |
ToJSON ContractState Source # | |
Defined in Morley.Michelson.Runtime.GState toJSON :: ContractState -> Value # toEncoding :: ContractState -> Encoding # toJSONList :: [ContractState] -> Value # toEncodingList :: [ContractState] -> Encoding # | |
FromJSON ContractState Source # | |
Defined in Morley.Michelson.Runtime.GState parseJSON :: Value -> Parser ContractState # parseJSONList :: Value -> Parser [ContractState] # | |
Buildable ContractState Source # | |
Defined in Morley.Michelson.Runtime.GState build :: ContractState -> Builder # |
data AddressState Source #
State of an arbitrary address.
ASSimple Mutez | For contracts without code we store only its balance. |
ASContract ContractState | For contracts with code we store more state represented by
|
Instances
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.
Instances
Show VotingPowers Source # | |
Defined in Morley.Michelson.Runtime.GState showsPrec :: Int -> VotingPowers -> ShowS # show :: VotingPowers -> String # showList :: [VotingPowers] -> ShowS # | |
ToJSON VotingPowers Source # | |
Defined in Morley.Michelson.Runtime.GState toJSON :: VotingPowers -> Value # toEncoding :: VotingPowers -> Encoding # toJSONList :: [VotingPowers] -> Value # toEncodingList :: [VotingPowers] -> Encoding # | |
FromJSON VotingPowers Source # | |
Defined in Morley.Michelson.Runtime.GState parseJSON :: Value -> Parser VotingPowers # parseJSONList :: Value -> Parser [VotingPowers] # |
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 associated with a particular transaction.
TxData | |
|
A parameter associated with a particular transaction.
TxTypedParam :: forall t. ParameterScope t => Value t -> TxParam | |
TxUntypedParam :: Value -> TxParam |
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.
OriginateOp OriginationOperation | Originate a contract. |
TransferOp TransferOperation | Transfer tokens to the address. |
SetDelegateOp SetDelegateOperation | Set the delegate of a contract. |
Instances
Show ExecutorOp Source # | |
Defined in Morley.Michelson.Runtime showsPrec :: Int -> ExecutorOp -> ShowS # show :: ExecutorOp -> String # showList :: [ExecutorOp] -> ShowS # | |
Buildable ExecutorOp Source # | |
Defined in Morley.Michelson.Runtime build :: ExecutorOp -> Builder # |
data ExecutorRes Source #
Result of a single execution of interpreter.
ExecutorRes | |
|
Instances
Show ExecutorRes Source # | |
Defined in Morley.Michelson.Runtime showsPrec :: Int -> ExecutorRes -> ShowS # show :: ExecutorRes -> String # showList :: [ExecutorRes] -> ShowS # |
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
.
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 a TCError | Contract parameter is ill-typed. |
EEUnexpectedParameterType a 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. |
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 |
Instances
Functor ExecutorError' Source # | |
Defined in Morley.Michelson.Runtime fmap :: (a -> b) -> ExecutorError' a -> ExecutorError' b # (<$) :: a -> ExecutorError' b -> ExecutorError' a # | |
Show a => Show (ExecutorError' a) Source # | |
Defined in Morley.Michelson.Runtime showsPrec :: Int -> ExecutorError' a -> ShowS # show :: ExecutorError' a -> String # showList :: [ExecutorError' a] -> ShowS # | |
(Typeable a, Show a, Buildable a) => Exception (ExecutorError' a) Source # | |
Defined in Morley.Michelson.Runtime toException :: ExecutorError' a -> SomeException # fromException :: SomeException -> Maybe (ExecutorError' a) # displayException :: ExecutorError' a -> String # | |
Buildable a => Buildable (ExecutorError' a) Source # | |
Defined in Morley.Michelson.Runtime build :: ExecutorError' a -> Builder # |
type ExecutorError = ExecutorError' Address Source #
type ExecutorM = ReaderT ExecutorEnv (StateT ExecutorState (Except ExecutorError)) Source #
A monad in which contract executor runs.
runExecutorM :: Timestamp -> Natural -> 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 -> Maybe Natural -> 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 :: TypeCheckOptions -> [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) -> TypeCheckOptions -> TransferOperation -> ExecutorM [ExecutorOp] Source #
Execute a transfer operation.
To avoid warnings (can't generate lenses only for some fields)
elInterpreterResults :: Lens' ExecutorLog [(Address, InterpretResult)] Source #
elUpdates :: Lens' ExecutorLog [GStateUpdate] Source #