Ejemplo n.º 1
0
 def _convert_score_data(self, key: bytes, value: Optional[bytes]):
     # Score address | type | name ...
     score_addr = Address.from_bytes(key[:21])
     type_ = key[22:23]
     converted_key = self.mapper[type_](key[24:])
     converted_key: str = f"SCORE: {score_addr} || Type: {self.DECODER_STRING_MAPPER[type_]} || Key: {converted_key}"
     return converted_key, str(value)
Ejemplo n.º 2
0
 def test_address_from_to_bytes_OTHER(self):
     addr1 = create_address()
     buf = addr1.to_bytes()
     prefix: int = 0
     prefix_buf: bytes = prefix.to_bytes(1, 'big')
     buf = prefix_buf + buf
     addr2 = Address.from_bytes(buf)
     self.assertEqual(addr1, addr2)
Ejemplo n.º 3
0
 def test_address_from_to_bytes_eoa_20length_eq_21length_from_bytes(self):
     addr1 = create_address()
     buf = addr1.to_bytes()
     prefix: int = 0
     prefix_buf: bytes = prefix.to_bytes(1, 'big')
     buf = prefix_buf + buf
     addr2 = Address.from_bytes(buf)
     assert addr1 == addr2
Ejemplo n.º 4
0
    def _decode_name(cls, name: bytes):
        #
        try:
            decoded_name = Address.from_bytes(name)
            if decoded_name is None:
                raise KeyError
        except:
            try:
                decoded_name = name.decode()
            except UnicodeDecodeError:
                decoded_name = name

        return decoded_name
Ejemplo n.º 5
0
 def _dict_db_decoder(cls, key: bytes):
     ret: list = key.split(b'|')
     name = cls._decode_name(ret.pop(0))
     string_dict: str = f"{name}"
     for key in ret:
         if key == ContainerTag.DICT.value:
             continue
         try:
             decoded_key = Address.from_bytes(key)
             if decoded_key is None:
                 decoded_key = key
         except:
             decoded_key = key
         string_dict += f"[{decoded_key}]"
     return string_dict
Ejemplo n.º 6
0
 def _convert_prep(cls, key: bytes, value: bytes):
     prep_address = Address.from_bytes(key[len(PRep.PREFIX):])
     return f"Prep: {prep_address}", str(PRep.from_bytes(value))
Ejemplo n.º 7
0
 def _convert_delegation_parts(cls, key: bytes, value: bytes):
     ret = DelegationPart.from_bytes(value)
     return str(Address.from_bytes(key[len(StakePart.PREFIX):])), str(ret)
Ejemplo n.º 8
0
    def _convert_coin_parts(cls, key: bytes, value: bytes):

        return str(Address.from_bytes(key)), str(CoinPart.from_bytes(value))
Ejemplo n.º 9
0
 def test_address_from_to_bytes_CONTRACT(self):
     addr1 = create_address(prefix=1)
     buf = addr1.to_bytes()
     addr2 = Address.from_bytes(buf)
     self.assertEqual(addr1, addr2)
Ejemplo n.º 10
0
 def test_address_from_to_bytes_EOA(self):
     addr1 = create_address()
     buf = addr1.to_bytes()
     addr2 = Address.from_bytes(buf)
     self.assertEqual(addr1, addr2)
Ejemplo n.º 11
0
def create_address(prefix: AddressPrefix = AddressPrefix.EOA) -> 'Address':
    return Address.from_bytes(prefix.to_bytes(1, 'big') + os.urandom(20))
Ejemplo n.º 12
0
 def test_address_from_to_bytes(self, prefix):
     addr1 = create_address(prefix)
     buf = addr1.to_bytes()
     addr2 = Address.from_bytes(buf)
     assert addr1 == addr2