示例#1
0
 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
示例#2
0
 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
示例#3
0
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
示例#4
0
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)
示例#5
0
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)
示例#6
0
 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)
示例#7
0
 def __init__(self, section):
     self.code = section
     self.schema = build_schema(section)
     self.__doc__ = generate_docstring(self.schema, 'parameter')
示例#8
0
 def __init__(self, section):
     self.code = section
     self.schema = build_schema(section)
     self.big_map_schema = None
     self.__doc__ = generate_docstring(self.schema, 'storage')