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.build_pxr_tree(pxr_macro, pxr_annots) pytezos.michelson.macros.PxrNode [source]
- 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: Optional[List[str]] = 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')
- exception pytezos.michelson.parse.MichelsonParserError(token: ply.lex.LexToken, message=None)[source]
- 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: pytezos.michelson.types.base.MichelsonType)[source]
-
- classmethod create_type(args: List[Union[Type[pytezos.michelson.micheline.Micheline], Any]], annots: Optional[list] = None, **kwargs) Type[pytezos.michelson.sections.parameter.ParameterSection] [source]
- classmethod execute(stack, stdout: List[str], context: pytezos.context.abstract.AbstractContext)[source]
- classmethod from_micheline_value(val_expr) pytezos.michelson.sections.parameter.ParameterSection [source]
- classmethod from_parameters(parameters: Dict[str, Any]) pytezos.michelson.sections.parameter.ParameterSection [source]
- classmethod from_python_object(py_obj) pytezos.michelson.sections.parameter.ParameterSection [source]
- classmethod list_entrypoints() Dict[str, Type[pytezos.michelson.types.base.MichelsonType]] [source]
- static match(type_expr) Type[pytezos.michelson.sections.parameter.ParameterSection] [source]
- merge_lazy_diff(lazy_diff: List[dict]) pytezos.michelson.sections.parameter.ParameterSection [source]
- prim: Optional[str] = 'parameter'
- root_name: str
Storage section
- class pytezos.michelson.sections.storage.StorageSection(item: pytezos.michelson.types.base.MichelsonType)[source]
-
- classmethod execute(stack, stdout: List[str], context: pytezos.context.abstract.AbstractContext)[source]
- classmethod from_micheline_value(val_expr) pytezos.michelson.sections.storage.StorageSection [source]
- classmethod from_python_object(py_obj) pytezos.michelson.sections.storage.StorageSection [source]
- static match(type_expr) Type[pytezos.michelson.sections.storage.StorageSection] [source]
- merge_lazy_diff(lazy_diff: List[dict]) pytezos.michelson.sections.storage.StorageSection [source]
- prim: Optional[str] = 'storage'
Code section
Script wrapper
- class pytezos.michelson.program.MichelsonProgram(name: str, parameter: pytezos.michelson.sections.parameter.ParameterSection, storage: pytezos.michelson.sections.storage.StorageSection)[source]
Michelson .tz contract interpreter interface
- begin(stack: pytezos.michelson.stack.MichelsonStack, stdout: List[str], context: pytezos.context.impl.ExecutionContext) None [source]
Prepare stack for contract execution
- code: Type[pytezos.michelson.sections.code.CodeSection]
- static create(sequence: Type[pytezos.michelson.micheline.MichelineSequence]) Type[pytezos.michelson.program.MichelsonProgram] [source]
Create MichelsonProgram type from micheline
- end(stack: pytezos.michelson.stack.MichelsonStack, stdout: List[str], output_mode='readable') Tuple[List[dict], Any, List[dict], pytezos.michelson.types.pair.PairType] [source]
Finish contract execution
- execute(stack: pytezos.michelson.stack.MichelsonStack, stdout: List[str], context: pytezos.context.impl.ExecutionContext) pytezos.michelson.instructions.base.MichelsonInstruction [source]
Execute contract in interpreter
- execute_view(stack: pytezos.michelson.stack.MichelsonStack, stdout: List[str], context: pytezos.context.impl.ExecutionContext)[source]
Execute view in interpreter
- classmethod instantiate(entrypoint: str, parameter, storage) pytezos.michelson.program.MichelsonProgram [source]
- classmethod instantiate_view(name: str, parameter, storage) pytezos.michelson.program.MichelsonProgram [source]
- static load(context: pytezos.context.impl.ExecutionContext, with_code=False) Type[pytezos.michelson.program.MichelsonProgram] [source]
Create MichelsonProgram type from filled context
- static match(expr) Type[pytezos.michelson.program.MichelsonProgram] [source]
- parameter: Type[pytezos.michelson.sections.parameter.ParameterSection]
- ret(stack: pytezos.michelson.stack.MichelsonStack, stdout: List[str], output_mode='readable') pytezos.michelson.types.base.MichelsonType [source]
- storage: Type[pytezos.michelson.sections.storage.StorageSection]
- views: List[Type[pytezos.michelson.sections.view.ViewSection]]
- class pytezos.michelson.program.TztMichelsonProgram[source]
Michelson .tzt contract interpreter interface
- begin(stack: pytezos.michelson.stack.MichelsonStack, stdout: List[str], context: pytezos.context.impl.ExecutionContext) None [source]
Prepare stack for contract execution
- big_maps: Optional[Type[pytezos.michelson.sections.tzt.BigMapsSection]]
- code: Type[pytezos.michelson.sections.code.CodeSection]
- static create(sequence: Type[pytezos.michelson.micheline.MichelineSequence]) Type[pytezos.michelson.program.TztMichelsonProgram] [source]
Create TztMichelsonProgram type from micheline
- end(stack: pytezos.michelson.stack.MichelsonStack, stdout: List[str], context: pytezos.context.impl.ExecutionContext) None [source]
Finish contract execution
- execute(stack: pytezos.michelson.stack.MichelsonStack, stdout: List[str], context: pytezos.context.impl.ExecutionContext) pytezos.michelson.instructions.base.MichelsonInstruction [source]
Execute contract in interpreter
- fill_context(script, context: pytezos.context.impl.ExecutionContext) None [source]
- input: Type[pytezos.michelson.sections.tzt.InputSection]
- classmethod instantiate() pytezos.michelson.program.TztMichelsonProgram [source]
- static load(context: pytezos.context.impl.ExecutionContext, with_code=False)[source]
Create TztMichelsonProgram type from filled context
- static match(expr) Type[pytezos.michelson.program.TztMichelsonProgram] [source]
- output: Type[pytezos.michelson.sections.tzt.OutputSection]
- register_bigmaps(stack: pytezos.michelson.stack.MichelsonStack, stdout: List[str], context: pytezos.context.impl.ExecutionContext) None [source]