Working with Michelson code¶
Expanding macros¶
-
class
pytezos.michelson.macros.
PxrNode
(depth, annots, args, is_root)¶ -
property
annots
¶ Alias for field number 1
-
property
args
¶ Alias for field number 2
-
property
depth
¶ Alias for field number 0
-
property
is_root
¶ Alias for field number 3
-
property
-
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, extra=None)[source]¶ Expands Michelson macro.
- Parameters
prim – macro name
annots – annotations (optional)
args – arguments (optional)
internal – this function is called during another mocro expansion
extra – list of ignored primitives
- Returns
Code sequence (Micheline expression)
Parsing AST¶
-
class
pytezos.michelson.parse.
MichelsonParser
(debug=False, write_tables=False, extra_primitives=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[Micheline], Any]], annots: Optional[list] = None, **kwargs) → Type[ParameterSection][source]¶
-
classmethod
execute
(stack, stdout: List[str], context: pytezos.context.abstract.AbstractContext)[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[pytezos.michelson.types.base.MichelsonType]][source]¶
-
static
match
(type_expr) → Type[ParameterSection][source]¶
-
merge_lazy_diff
(lazy_diff: List[dict]) → ParameterSection[source]¶
-
prim
: Optional[str] = 'parameter'¶
-
root_name
: str¶
-
classmethod
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) → 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
: Optional[str] = 'storage'¶
-
classmethod
Code section¶
Script wrapper¶
-
class
pytezos.michelson.program.
MichelsonProgram
(entrypoint: str, parameter: pytezos.michelson.sections.parameter.ParameterSection, storage: pytezos.michelson.sections.storage.StorageSection)[source]¶ -
-
begin
(stack: pytezos.michelson.stack.MichelsonStack, stdout: List[str], context: pytezos.context.abstract.AbstractContext)[source]¶
-
code
: Type[pytezos.michelson.sections.code.CodeSection]¶
-
static
create
(sequence: Type[pytezos.michelson.micheline.MichelineSequence]) → Type[pytezos.michelson.program.MichelsonProgram][source]¶
-
end
(stack: pytezos.michelson.stack.MichelsonStack, stdout: List[str], output_mode='readable') → Tuple[List[dict], Any, List[dict], pytezos.michelson.types.pair.PairType][source]¶
-
execute
(stack: pytezos.michelson.stack.MichelsonStack, stdout: List[str], context: pytezos.context.abstract.AbstractContext) → pytezos.michelson.instructions.base.MichelsonInstruction[source]¶
-
classmethod
instantiate
(entrypoint: str, parameter, storage) → pytezos.michelson.program.MichelsonProgram[source]¶
-
static
match
(expr) → Type[pytezos.michelson.program.MichelsonProgram][source]¶
-
parameter
: Type[pytezos.michelson.sections.parameter.ParameterSection]¶
-
storage
: Type[pytezos.michelson.sections.storage.StorageSection]¶
-