def __deserialize_stack_item(reader: BinaryReader) -> dict or bytearray:
     param_type = reader.read_byte()
     if param_type == BuildParams.Type.bytearray_type.value:
         b = reader.read_var_bytes()
         return b
     elif param_type == BuildParams.Type.bool_type.value:
         return reader.read_bool()
     elif param_type == BuildParams.Type.int_type.value:
         b = reader.read_var_bytes()
         return ContractDataParser.__big_int_from_bytes(bytearray(b))
     elif param_type == BuildParams.Type.struct_type.value or param_type == BuildParams.Type.array_type.value:
         count = reader.read_var_int()
         item_list = list()
         for _ in range(count):
             item = ContractDataParser.__deserialize_stack_item(reader)
             item_list.append(item)
         if param_type == BuildParams.Type.struct_type.value:
             return Struct(item_list)
         return item_list
     elif param_type == BuildParams.Type.dict_type.value:
         count = reader.read_var_int()
         item_dict = dict()
         for _ in range(count):
             key = ContractDataParser.__deserialize_stack_item(reader)
             value = ContractDataParser.__deserialize_stack_item(reader)
             item_dict[key] = value
         return item_dict
     else:
         raise SDKException(ErrorCode.other_error('type error'))
示例#2
0
def deserialize_stack_item(reader: BinaryReader) -> dict:
    t = reader.read_byte()
    if t == BuildParams.Type.bytearray_type.value:
        b = reader.read_var_bytes()
        return b
    elif t == BuildParams.Type.bool_type.value:
        return reader.read_bool()
    elif t == BuildParams.Type.int_type.value:
        b = reader.read_var_bytes()
        return bigint_from_bytes(b)
    elif t == BuildParams.Type.struct_type.value or t == BuildParams.Type.array_type.value:
        count = reader.read_var_int()
        # TODO
        item_list = list()
        for _ in range(count):
            item = deserialize_stack_item(reader)
            item_list.append(item)
        if t == t == BuildParams.Type.struct_type.value:
            return Struct(item_list)
        return item_list
    elif t == BuildParams.Type.dict_type.value:
        count = reader.read_var_int()
        item_dict = dict()
        for _ in range(count):
            key = deserialize_stack_item(reader)
            value = deserialize_stack_item(reader)
            item_dict[key] = value
        return item_dict
    else:
        raise SDKException(ErrorCode.other_error('type error'))