Michelson REPL

Interpreter

class pymavryk.michelson.repl.Interpreter(extra_primitives: List[str] | None = None, debug: bool = False)[source]

Michelson interpreter reimplemented in Python. Based on the following reference: https://tezos.gitlab.io/michelson-reference/

execute(code: str) InterpreterResult[source]

Execute some code preserving current context and stack

Parameters:

code – Michelson code

reset() None[source]

Reset interpreter’s stack and context

static run_callback(entrypoint: str, parameter, storage, context: ExecutionContext) Tuple[Any, Any, List[str], Exception | None][source]

Execute view entrypoint of the contract loaded into the context

Parameters:
  • entrypoint – contract entrypoint

  • parameter – parameter section

  • storage – storage section

  • context – execution context

Returns:

[operations, storage, stdout, error]

static run_code(parameter, storage, script: str, entrypoint='default', output_mode='readable', amount=None, chain_id=None, source=None, sender=None, balance=None, block_id=None, **kwargs) Tuple[List[dict], Any, List[dict], List[str], Exception | None][source]

Execute contract in interpreter

Parameters:
  • parameter – parameter expression

  • storage – storage expression

  • script – contract’s Michelson code

  • entrypoint – contract entrypoint

  • output_mode – one of readable/optimized/legacy_optimized

  • amount – patch AMOUNT

  • chain_id – patch CHAIN_ID

  • source – patch SOURCE

  • sender – patch SENDER

  • balance – patch BALANCE

  • block_id – set block ID

static run_tzt(script: str, amount=None, chain_id=None, source=None, sender=None, balance=None, block_id=None, **kwargs) None[source]

Execute TZT test suite code

Parameters:
  • script – test contract’s Michelson code

  • amount – patch AMOUNT

  • chain_id – patch CHAIN_ID

  • source – patch SOURCE

  • sender – patch SENDER

  • balance – patch BALANCE

  • block_id – set block ID

static run_view(name: str, parameter, storage, context: ExecutionContext) Tuple[Any, Any, Exception | None][source]
class pymavryk.michelson.repl.InterpreterResult(*, stdout: List[str], error: Exception | None = None, instructions: MichelineSequence | None = None, stack: MichelsonStack | None = None)[source]

Result of running contract in interpreter

error: Exception | None
instructions: MichelineSequence | None
lazy_diff = None
operations = None
stack: MichelsonStack | None
stdout: List[str]
storage = None

Michelson stack

class pymavryk.michelson.stack.MichelsonStack(items: List[MichelsonType] | None = None)[source]
clear() None[source]
dump(count: int) List[MichelsonType] | None[source]
classmethod from_items(items: List[MichelsonType]) MichelsonStack[source]
peek() MichelsonType[source]
pop(count: int) List[MichelsonType][source]
pop1() MichelsonType[source]
pop2() Tuple[MichelsonType, MichelsonType][source]
pop3() Tuple[MichelsonType, MichelsonType, MichelsonType][source]
protect(count: int) None[source]
push(item: MichelsonType)[source]
restore(count: int) None[source]

Execution context

class pymavryk.context.impl.ExecutionContext(amount=None, chain_id=None, protocol=None, source=None, sender=None, balance=None, block_id=None, now=None, level=None, voting_power=None, total_voting_power=None, min_block_time=None, key=None, shell=None, address=None, counter=None, script=None, tzt=False, mode=None, ipfs_gateway=None, global_constants=None, view_results=None)[source]
get_amount() int[source]
get_amount_expr()[source]
get_balance() int[source]
get_balance_expr()[source]
get_big_map_diff(ptr: int) Tuple[int | None, int, str][source]
get_big_map_value(ptr: int, key_hash: str)[source]
get_big_maps_expr()[source]
get_chain_id() str[source]
get_chain_id_expr()[source]
get_code_expr()[source]
get_counter() int[source]
get_counter_offset() int[source]

Return current count of pending transactions in mempool.

get_dummy_address() str[source]
get_dummy_chain_id() str[source]
get_dummy_key_hash() str[source]
get_dummy_lambda()[source]
get_dummy_public_key() str[source]
get_dummy_signature() str[source]
get_dummy_txr_address() str[source]
get_input_expr()[source]
get_level() int[source]
get_min_block_time() int[source]
get_now() int[source]
get_now_expr()[source]
get_operations_ttl() int[source]
get_originated_address() str[source]
get_output_expr()[source]
get_parameter_expr(address=None) dict | None[source]
get_protocol() str[source]
get_sapling_state_diff(offset_commitment=0, offset_nullifier=0) Tuple[int, list][source]
get_self_address() str[source]
get_self_expr()[source]
get_sender() str[source]
get_sender_expr()[source]
get_source() str[source]
get_source_expr()[source]
get_storage_expr(address=None) dict | None[source]
get_storage_value(address=None) dict | None[source]
get_tmp_big_map_id() int[source]
get_tmp_sapling_state_id() int[source]
get_total_voting_power() int[source]
get_view_expr(name, address=None) dict | None[source]
get_view_result(name, address=None) Any | None[source]
get_views_expr() List[dict][source]
get_voting_power(address: str) int[source]
register_big_map(ptr: int, copy=False) int[source]
register_global_constant(expression)[source]

Register global constant :param expression: Micheline expression

register_sapling_state(ptr: int)[source]
reset()[source]
resolve_global_constants(expression)[source]

Replace global constants with their respectful values or throw an error if the constant is not defined :param expression: Micheline expression

property sandboxed: bool
property script: dict | None
set_big_maps_expr(expr)[source]
set_chain_id_expr(expr)[source]
set_code_expr(expr)[source]
set_counter(counter: int)[source]
set_input_expr(expr)[source]
set_output_expr(expr)[source]
set_parameter_expr(expr)[source]
set_source_expr(expr)[source]
set_storage_expr(expr)[source]
set_total_voting_power(total_voting_power: int)[source]
set_voting_power(address: str, voting_power: int)[source]
spend_balance(amount: int)[source]