コード例 #1
0
 def __init__(self, serialized: bytes) -> None:
     self.__bytes = serialized
     self.__addresses = []
     if serialized is not None:
         self.__hash = get_hash(serialized)
         unpacked = rlp.rlp_decode(self.__bytes, {list: bytes})
         for b in unpacked:
             address = Address.from_bytes(b)
             self.__addresses.append(address)
コード例 #2
0
 def convert_from_bytes(param_type: str, v: bytes):
     if param_type == "int":
         return rlp.from_bytes(v, int)
     elif param_type == "str":
         return rlp.from_bytes(v, str)
     elif param_type == "bool":
         return rlp.from_bytes(v, bool)
     elif param_type == "bytes":
         return v
     elif param_type == "Address":
         return Address.from_bytes(v)
     else:
         raise BMVException(
             f"{param_type} is not supported type (only int, str, bool, Address, bytes are supported)"
         )
コード例 #3
0
ファイル: db.py プロジェクト: ilkereroglu/btp
 def get(self, k):
     if k in self.__remove:
         return None
     elif k in self.__cache:
         return self.__cache[k]
     else:
         b = self.__db[k]
         if b is None:
             if k in self.__default:
                 v = self.__default[k]
                 if isinstance(v, type) and issubclass(v, Serializable):
                     v = None
             else:
                 v = None
         elif b[0] == PropertiesDB.Type.INT:
             v = int.from_bytes(b[1:], "big", signed=True)
         elif b[0] == PropertiesDB.Type.STR:
             v = b[1:].decode('utf-8')
         elif b[0] == PropertiesDB.Type.BOOL:
             v = True if b[1:] == b'\x01' else False
         elif b[0] == PropertiesDB.Type.BYTES:
             v = b[1:]
         elif b[0] == PropertiesDB.Type.ADDRESS:
             v = Address.from_bytes(b[1:])
         elif b[0] == PropertiesDB.Type.BTPADDRESS:
             v = BTPAddress.from_bytes(b[1:])
         elif b[0] == PropertiesDB.Type.SERIALIZABLE:
             v = self.__default[k]
             if isinstance(v, type):
                 v = v.__new__(v)
             if isinstance(v, Serializable):
                 v = v.from_bytes(b[1:])
             else:
                 raise PropertiesDB.TypeException(
                     f"{type(v)} is not supported")
         else:
             raise PropertiesDB.TypeException(
                 f"{b[0]} is not supported type")
         self.__cache[k] = v
         return v