Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Module, containing function to interpret Michelson instructions against given context and input stack.
Synopsis
- type ContractEnv = ContractEnv' EvalOp
- data ContractEnv' m = ContractEnv {
- ceNow :: Timestamp
- ceMaxSteps :: RemainingSteps
- ceBalance :: Mutez
- ceContracts :: ContractAddress -> m (Maybe ContractState)
- ceSelf :: ContractAddress
- ceSource :: L1Address
- ceSender :: L1Address
- ceAmount :: Mutez
- ceVotingPowers :: VotingPowers
- ceChainId :: ChainId
- ceOperationHash :: Maybe OperationHash
- ceLevel :: Natural
- ceErrorSrcPos :: ErrorSrcPos
- ceMinBlockTime :: Natural
- ceMetaWrapper :: forall i o. Instr i o -> Instr i o
- data InterpreterState = InterpreterState {}
- data MichelsonFailed ext where
- MichelsonFailedWith :: (SingI t, ConstantScope t) => Value t -> MichelsonFailed ext
- MichelsonArithError :: (Typeable n, Typeable m) => ArithError (Value n) (Value m) -> MichelsonFailed ext
- MichelsonGasExhaustion :: MichelsonFailed ext
- MichelsonFailedTestAssert :: Text -> MichelsonFailed ext
- MichelsonUnsupported :: Text -> MichelsonFailed ext
- MichelsonExt :: ext -> MichelsonFailed ext
- data MichelsonFailureWithStack ext = MichelsonFailureWithStack {}
- newtype RemainingSteps = RemainingSteps Word64
- data SomeItStack where
- SomeItStack :: ExtInstr inp -> Rec StkEl inp -> SomeItStack
- newtype MorleyLogs = MorleyLogs {
- unMorleyLogs :: [Text]
- buildMorleyLogs :: MorleyLogsBuilder -> MorleyLogs
- newtype MorleyLogsBuilder = MorleyLogsBuilder (Endo [Text])
- interpret :: Contract cp st -> EntrypointCallT cp arg -> Value arg -> Value st -> GlobalCounter -> BigMapCounter -> ContractEnv -> ContractReturn st
- interpretInstr :: ContractEnv -> Instr inp out -> Rec Value inp -> Either (MichelsonFailureWithStack Void) (Rec Value out)
- interpretInstrAnnotated :: ContractEnv -> Instr inp out -> Rec Value inp -> Either (MichelsonFailureWithStack Void) (Rec StkEl out)
- type InterpretReturn ty = RunEvalOpReturn (Value ty)
- type ContractReturn st = InterpretReturn (ContractOut1 st)
- type RunEvalOpReturn a = ResultStateLogs (Either (MichelsonFailureWithStack Void) a)
- data ResultStateLogs res = ResultStateLogs {
- rslResult :: res
- rslState :: InterpreterState
- rslLogs :: MorleyLogs
- mkInitStack :: Value param -> Value st -> Rec StkEl (ContractInp param st)
- data InterpretError ext = InterpretError {}
- type InterpretResult ty = ResultStateLogs (Value ty)
- type ContractResult ty = InterpretResult (ContractOut1 ty)
- extractValOps :: Value (ContractOut1 st) -> ([Operation], Value st)
- type EvalM m = EvalM' Void m
- class Monad m => InterpreterStateMonad m where
- getInterpreterState :: m InterpreterState
- putInterpreterState :: InterpreterState -> m ()
- stateInterpreterState :: (InterpreterState -> (a, InterpreterState)) -> m a
- modifyInterpreterState :: (InterpreterState -> InterpreterState) -> m ()
- newtype StkEl t = StkEl {}
- type InstrRunner m = forall inp out. Instr inp out -> Rec StkEl inp -> m (Rec StkEl out)
- runInstr :: EvalM' ext m => InstrRunner m
- runInstrNoGas :: EvalM m => InstrRunner m
- runUnpack :: forall t. UnpackedValScope t => ByteString -> Either UnpackError (Value t)
- data ViewLookupError
- interpretView :: View arg st ret -> Value st -> Value arg -> ContractEnv -> InterpreterState -> InterpretReturn ret
- getViewByName :: Contract cp st -> ViewName -> Either ViewLookupError (SomeView st)
- getViewByNameAndType :: forall arg ret cp st. (SingI arg, SingI ret) => Contract cp st -> ViewName -> Either ViewLookupError (View arg st ret)
- initInterpreterState :: GlobalCounter -> BigMapCounter -> ContractEnv -> InterpreterState
- handleReturn :: InterpretReturn res -> Either (InterpretError Void) (ResultStateLogs (Value res))
- runEvalOp :: EvalOp a -> ContractEnv -> InterpreterState -> RunEvalOpReturn a
- runInstrImpl :: forall ext m. EvalM' ext m => InstrRunner m -> InstrRunner m
- assignBigMapIds :: MonadState BigMapCounter m => Bool -> Value t -> m (Value t)
- interpretView' :: forall ret st m arg ext. EvalM' ext m => (forall inp out. Instr inp out -> Rec StkEl inp -> m (Rec StkEl out)) -> (ContractEnv' m -> ContractEnv' m) -> View arg st ret -> Value st -> Value arg -> m (Value ret)
- newtype EvalOp a = EvalOp (ExceptT (MichelsonFailureWithStack Void) (RWS ContractEnv MorleyLogsBuilder InterpreterState) a)
- _MorleyLogs :: Iso' MorleyLogs [Text]
Documentation
type ContractEnv = ContractEnv' EvalOp Source #
data ContractEnv' m Source #
Environment for contract execution. Parametrized by the execution monad,
i.e. EvalOp
by default, but downstream consumers may define their own if
using low-level runners.
ContractEnv | |
|
Instances
MonadReader ContractEnv EvalOp Source # | |
Defined in Morley.Michelson.Interpret ask :: EvalOp ContractEnv # local :: (ContractEnv -> ContractEnv) -> EvalOp a -> EvalOp a # reader :: (ContractEnv -> a) -> EvalOp a # |
data InterpreterState Source #
Instances
data MichelsonFailed ext where Source #
Errors that can be thrown by the interpreter. The ext
type variable
allow the downstreams consumer to add additional exceptions.
MichelsonFailedWith | |
| |
MichelsonArithError :: (Typeable n, Typeable m) => ArithError (Value n) (Value m) -> MichelsonFailed ext | |
MichelsonGasExhaustion :: MichelsonFailed ext | |
MichelsonFailedTestAssert :: Text -> MichelsonFailed ext | |
MichelsonUnsupported :: Text -> MichelsonFailed ext | |
MichelsonExt :: ext -> MichelsonFailed ext |
Instances
Show ext => Show (MichelsonFailed ext) Source # | |
Defined in Morley.Michelson.Interpret showsPrec :: Int -> MichelsonFailed ext -> ShowS # show :: MichelsonFailed ext -> String # showList :: [MichelsonFailed ext] -> ShowS # | |
NFData ext => NFData (MichelsonFailed ext) Source # | |
Defined in Morley.Michelson.Interpret rnf :: MichelsonFailed ext -> () # | |
Buildable ext => Buildable (MichelsonFailed ext) Source # | |
Defined in Morley.Michelson.Interpret build :: MichelsonFailed ext -> Builder # | |
Eq ext => Eq (MichelsonFailed ext) Source # | |
Defined in Morley.Michelson.Interpret (==) :: MichelsonFailed ext -> MichelsonFailed ext -> Bool # (/=) :: MichelsonFailed ext -> MichelsonFailed ext -> Bool # |
data MichelsonFailureWithStack ext Source #
Carries a MichelsonFailed
ext
error and the ErrorSrcPos
at which it was raised
Instances
newtype RemainingSteps Source #
Instances
data SomeItStack where Source #
SomeItStack :: ExtInstr inp -> Rec StkEl inp -> SomeItStack |
newtype MorleyLogs Source #
Morley logs appearing as interpreter result.
MorleyLogs | |
|
Instances
newtype MorleyLogsBuilder Source #
Morley logs accumulator, for incremental building.
Instances
interpret :: Contract cp st -> EntrypointCallT cp arg -> Value arg -> Value st -> GlobalCounter -> BigMapCounter -> ContractEnv -> ContractReturn st Source #
interpretInstr :: ContractEnv -> Instr inp out -> Rec Value inp -> Either (MichelsonFailureWithStack Void) (Rec Value out) Source #
Interpret an instruction in vacuum, putting no extra constraints on its execution.
Mostly for testing purposes.
interpretInstrAnnotated :: ContractEnv -> Instr inp out -> Rec Value inp -> Either (MichelsonFailureWithStack Void) (Rec StkEl out) Source #
Interpret an instruction in vacuum, putting no extra constraints on its execution while preserving its annotations.
Mostly for testing purposes.
type InterpretReturn ty = RunEvalOpReturn (Value ty) Source #
Result of interpretView
. A version of RunEvalOpReturn
specialized to Value
.
type ContractReturn st = InterpretReturn (ContractOut1 st) Source #
Result of interpret
. A version of InterpretReturn
specialized to ContractOut1
.
type RunEvalOpReturn a = ResultStateLogs (Either (MichelsonFailureWithStack Void) a) Source #
Result of runEvalOp
. Essentially, return value (possibly failing), state
and logs.
data ResultStateLogs res Source #
ResultStateLogs | |
|
Instances
mkInitStack :: Value param -> Value st -> Rec StkEl (ContractInp param st) Source #
data InterpretError ext Source #
Instances
type InterpretResult ty = ResultStateLogs (Value ty) Source #
Pure result of an interpretation, i.e. return value, final interpreter state and execution logs.
type ContractResult ty = InterpretResult (ContractOut1 ty) Source #
Pure result of contract interpretation. A specialized version of
InterpretResult
.
extractValOps :: Value (ContractOut1 st) -> ([Operation], Value st) Source #
Extract list of operations from ContractOut1
Value
.
class Monad m => InterpreterStateMonad m where Source #
Nothing
getInterpreterState :: m InterpreterState Source #
putInterpreterState :: InterpreterState -> m () Source #
stateInterpreterState :: (InterpreterState -> (a, InterpreterState)) -> m a Source #
modifyInterpreterState :: (InterpreterState -> InterpreterState) -> m () Source #
Instances
Instances
runInstr :: EvalM' ext m => InstrRunner m Source #
Function to change amount of remaining steps stored in State monad.
runInstrNoGas :: EvalM m => InstrRunner m Source #
runUnpack :: forall t. UnpackedValScope t => ByteString -> Either UnpackError (Value t) Source #
Unpacks given raw data into a typed value.
Views
data ViewLookupError Source #
Instances
Show ViewLookupError Source # | |
Defined in Morley.Michelson.Interpret showsPrec :: Int -> ViewLookupError -> ShowS # show :: ViewLookupError -> String # showList :: [ViewLookupError] -> ShowS # | |
Buildable ViewLookupError Source # | |
Defined in Morley.Michelson.Interpret build :: ViewLookupError -> Builder # |
interpretView :: View arg st ret -> Value st -> Value arg -> ContractEnv -> InterpreterState -> InterpretReturn ret Source #
Interpret a contract's view for given ContractEnv
and initial
InterpreterState
. It is assumed ContractEnv
is suitable for the view
call, that is, the view is executed exactly in the env that's passed here.
getViewByName :: Contract cp st -> ViewName -> Either ViewLookupError (SomeView st) Source #
Attempt to find a view with a given name in a given contract.
getViewByNameAndType :: forall arg ret cp st. (SingI arg, SingI ret) => Contract cp st -> ViewName -> Either ViewLookupError (View arg st ret) Source #
Attempt to find a view with a given name and given type in a given contract.
Internals
handleReturn :: InterpretReturn res -> Either (InterpretError Void) (ResultStateLogs (Value res)) Source #
On failure, attach logs to failure, but throw away the final state.
runEvalOp :: EvalOp a -> ContractEnv -> InterpreterState -> RunEvalOpReturn a Source #
runInstrImpl :: forall ext m. EvalM' ext m => InstrRunner m -> InstrRunner m Source #
Function to interpret Michelson instruction(s) against given stack.
The ext
type variable specifies additional exceptions that can be thrown from the inner
runner function (via MichelsonExt
). In Morley, it's set to Void
, but downstream consumers
may use other type here.
:: MonadState BigMapCounter m | |
=> Bool | If true, assign a new ID even if the bigmap already has one. Otherwise, assign IDs only to bigmaps that don't have one yet. |
-> Value t | |
-> m (Value t) |
All big_maps stored in a chain have a globally unique ID.
We use this function to assign a new ID whenever a big_map is created.
interpretView' :: forall ret st m arg ext. EvalM' ext m => (forall inp out. Instr inp out -> Rec StkEl inp -> m (Rec StkEl out)) -> (ContractEnv' m -> ContractEnv' m) -> View arg st ret -> Value st -> Value arg -> m (Value ret) Source #
EvalM
view interpretation helper.
The main interpreter monad. Downstream consumers which use runInstrImpl
directly may define their own monad similar to this one.
This is a newtype and not a type synonym due to the reader environment, i.e.
ContractEnv
, being parameterized by this monad.
EvalOp (ExceptT (MichelsonFailureWithStack Void) (RWS ContractEnv MorleyLogsBuilder InterpreterState) a) |
Instances
Prisms
_MorleyLogs :: Iso' MorleyLogs [Text] Source #