Working with Michelson code
Expanding macros
- class pytezos.michelson.macros.PxrNode(depth, annots, args, is_root)
- annots
Alias for field number 1
- args
Alias for field number 2
- depth
Alias for field number 0
- is_root
Alias for field number 3
- pytezos.michelson.macros.expand_macro(prim, annots, args, internal=False)[source]
Expands Michelson macro.
- Parameters:
prim – macro name
annots – annotations (optional)
args – arguments (optional)
internal – this function is called during another macro expansion
- Returns:
Code sequence (Micheline expression)
Parsing AST
- class pytezos.michelson.parse.MichelsonParser(debug=False, write_tables=False, extra_primitives: List[str] | None = None)[source]
Customizable Michelson parser
- parse(code)[source]
Parse Michelson source.
- Parameters:
code – Michelson source
- Returns:
Micheline expression
- tokens = ('INT', 'BYTE', 'STR', 'ANNOT', 'PRIM', 'LEFT_CURLY', 'RIGHT_CURLY', 'LEFT_PAREN', 'RIGHT_PAREN', 'SEMI')
- class pytezos.michelson.parse.SimpleMichelsonLexer[source]
- t_ANNOT = '[:@%]+([_0-9a-zA-Z\\.]*)?'
- t_BYTE = '0x[A-Fa-f0-9]*'
- t_INT = '-?[0-9]+'
- t_LEFT_CURLY = '\\{'
- t_LEFT_PAREN = '\\('
- t_PRIM = '[A-Za-z][A-Za-z0-9_]+'
- t_RIGHT_CURLY = '\\}'
- t_RIGHT_PAREN = '\\)'
- t_SEMI = ';'
- t_STR = '\\"(\\\\.|[^\\"])*\\"'
- t_ignore = ' \t\r\n\x0c'
- t_ignore_COMMENT = '#[^\\n]*'
- t_ignore_MULTI_COMMENT = '/\\*[^*]*\\*/'
- tokens = ('INT', 'BYTE', 'STR', 'ANNOT', 'PRIM', 'LEFT_CURLY', 'RIGHT_CURLY', 'LEFT_PAREN', 'RIGHT_PAREN', 'SEMI')
Code formatter
- pytezos.michelson.format.format_timestamp(timestamp: int) str [source]
Format unix timestamp.
- Parameters:
timestamp – Unix timestamp (seconds)
- pytezos.michelson.format.micheline_to_michelson(data, inline=False, wrap=False) str [source]
Converts micheline expression into formatted Michelson source.
- Parameters:
data – Micheline expression
inline – produce single line, used for tezos-client arguments (False by default)
wrap – ensure expression is wrapped in brackets
Parameter section
- class pytezos.michelson.sections.parameter.ParameterSection(item: MichelsonType)[source]
-
- classmethod create_type(args: List[Type[Micheline] | Any], annots: list | None = None, **kwargs) Type[ParameterSection] [source]
- classmethod from_micheline_value(val_expr) ParameterSection [source]
- classmethod from_parameters(parameters: Dict[str, Any]) ParameterSection [source]
- classmethod from_python_object(py_obj) ParameterSection [source]
- classmethod list_entrypoints() Dict[str, Type[MichelsonType]] [source]
- static match(type_expr) Type[ParameterSection] [source]
- merge_lazy_diff(lazy_diff: List[dict]) ParameterSection [source]
- prim: str | None = 'parameter'
- root_name: str
Storage section
- class pytezos.michelson.sections.storage.StorageSection(item: MichelsonType)[source]
-
- classmethod from_micheline_value(val_expr) StorageSection [source]
- classmethod from_python_object(py_obj) StorageSection [source]
- static match(type_expr) Type[StorageSection] [source]
- merge_lazy_diff(lazy_diff: List[dict]) StorageSection [source]
- prim: str | None = 'storage'
Code section
Script wrapper
- class pytezos.michelson.program.MichelsonProgram(name: str, parameter: ParameterSection, storage: StorageSection)[source]
Michelson .tz contract interpreter interface
- begin(stack: MichelsonStack, stdout: List[str], context: ExecutionContext) None [source]
Prepare stack for contract execution
- code: Type[CodeSection]
- static create(sequence: Type[MichelineSequence]) Type[MichelsonProgram] [source]
Create MichelsonProgram type from micheline
- end(stack: MichelsonStack, stdout: List[str], output_mode='readable') Tuple[List[dict], Any, List[dict], PairType] [source]
Finish contract execution
- execute(stack: MichelsonStack, stdout: List[str], context: ExecutionContext) MichelsonInstruction [source]
Execute contract in interpreter
- execute_view(stack: MichelsonStack, stdout: List[str], context: ExecutionContext)[source]
Execute view in interpreter
- classmethod instantiate(entrypoint: str, parameter, storage) MichelsonProgram [source]
- classmethod instantiate_view(name: str, parameter, storage) MichelsonProgram [source]
- static load(context: ExecutionContext, with_code=False) Type[MichelsonProgram] [source]
Create MichelsonProgram type from filled context
- static match(expr) Type[MichelsonProgram] [source]
- parameter: Type[ParameterSection]
- ret(stack: MichelsonStack, stdout: List[str], output_mode='readable') MichelsonType [source]
- storage: Type[StorageSection]
- views: List[Type[ViewSection]]
- class pytezos.michelson.program.TztMichelsonProgram[source]
Michelson .tzt contract interpreter interface
- begin(stack: MichelsonStack, stdout: List[str], context: ExecutionContext) None [source]
Prepare stack for contract execution
- big_maps: Type[BigMapsSection] | None
- code: Type[CodeSection]
- static create(sequence: Type[MichelineSequence]) Type[TztMichelsonProgram] [source]
Create TztMichelsonProgram type from micheline
- end(stack: MichelsonStack, stdout: List[str], context: ExecutionContext) None [source]
Finish contract execution
- execute(stack: MichelsonStack, stdout: List[str], context: ExecutionContext) MichelsonInstruction [source]
Execute contract in interpreter
- fill_context(script, context: ExecutionContext) None [source]
- input: Type[InputSection]
- classmethod instantiate() TztMichelsonProgram [source]
- static load(context: ExecutionContext, with_code=False)[source]
Create TztMichelsonProgram type from filled context
- static match(expr) Type[TztMichelsonProgram] [source]
- output: Type[OutputSection]
- register_bigmaps(stack: MichelsonStack, stdout: List[str], context: ExecutionContext) None [source]