def parameter(self, action, path=None): """ :param action: One of `schema` :param path: Path to the .tz file, or the following uri: <network>:<KT-address> """ contract = get_contract(path) if action == 'schema': print(generate_docstring(contract.parameter.schema, title='parameter')) else: assert False, action
def storage(self, action, path=None): """ :param action: One of `schema`, `default` :param path: Path to the .tz file, or the following uri: <network>:<KT-address> """ contract = get_contract(path) if action == 'schema': print(generate_docstring(contract.storage.schema, title='storage')) elif action == 'default': pprint(contract.storage.default()) else: assert False, action
def decode_micheline(data, schema: Schema, root='0'): """ Converts Micheline data into Python object :param data: Micheline expression :param schema: schema built for particular contract/section :param root: which binary node to take as root, used to decode BigMap values/diffs :return: Object """ try: json_values = parse_micheline(data, schema.bin_to_json, schema.bin_types, root) return make_json(json_values) except (KeyError, IndexError, TypeError): print(generate_docstring(schema, 'schema')) raise MichelineSchemaError('Failed to decode micheline expression', data) from None
def decode_micheline(val_expr, type_expr, schema: Schema, root='0'): """ Converts Micheline data into Python object. :param val_expr: Micheline value expression :param type_expr: Michelson type expression for the entire type :param schema: schema built for particular contract/section :param root: which binary node to take as root, used to decode BigMap values/diffs :returns: Object """ try: return parse_micheline(val_expr, type_expr, schema, root) except (KeyError, IndexError, TypeError) as e: print(generate_docstring(schema, 'schema')) pprint(val_expr, compact=True) raise MichelineSchemaError(f'Failed to decode micheline expression', e.args)
def encode_micheline(data, schema: Schema, root='0', binary=False): """ Converts Python object into Micheline expression. :param data: Python object :param schema: schema built for particular contract/section :param root: which binary node to take as root, used to encode BigMap values :param binary: Encode keys and addresses in bytes rather than strings, default is False :returns: Micheline expression """ try: bin_values = parse_json(data, schema, root) return make_micheline(bin_values, schema.bin_types, root, binary) except (KeyError, IndexError, TypeError) as e: print(generate_docstring(schema, 'schema')) pprint(data, compact=True) raise MichelineSchemaError(f'Failed to encode micheline expression', e.args)
def make_docs(bin_path): if self.schema.bin_types[bin_path] in ['namedtuple', 'router']: title = 'kwargs' else: title = 'args' return generate_docstring(self.schema, title, bin_path)
def __init__(self, section): self.code = section self.schema = build_schema(section) self.__doc__ = generate_docstring(self.schema, 'parameter')
def __init__(self, section): self.code = section self.schema = build_schema(section) self.big_map_schema = None self.__doc__ = generate_docstring(self.schema, 'storage')