Michelson REPL

Interpreter

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

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

execute(code: str) pytezos.michelson.repl.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: pytezos.context.impl.ExecutionContext) Tuple[Any, Any, List[str], Optional[Exception]][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], Optional[Exception]][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: pytezos.context.impl.ExecutionContext) Tuple[Any, Any, Optional[Exception]][source]
class pytezos.michelson.repl.InterpreterResult(*, stdout: List[str], error: Optional[Exception] = None, instructions: Optional[pytezos.michelson.micheline.MichelineSequence] = None, stack: Optional[pytezos.michelson.stack.MichelsonStack] = None)[source]

Result of running contract in interpreter

error: Optional[Exception]
instructions: Optional[pytezos.michelson.micheline.MichelineSequence]
lazy_diff = None
operations = None
stack: Optional[pytezos.michelson.stack.MichelsonStack]
stdout: List[str]
storage = None

Michelson stack

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

Execution context

class pytezos.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, 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[Optional[int], 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_input_expr()[source]
get_level() 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) Optional[dict][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) Optional[dict][source]
get_storage_value(address=None) Optional[dict][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) Optional[dict][source]
get_view_result(name, address=None) Optional[Any][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: Optional[dict]
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]