def exists(self, object_id, related_id): """Check the existence of a relationship record""" # pylint: disable=not-callable container = self._state_container() address = self.address(object_id=object_id, related_id=related_id) data = client.get_address(address=address) if not data: return False container.ParseFromString(data) stores = list(container.relationships) if not stores: LOGGER.warning( "%s %s relationship container for %s %s at address %s has no records", self.object_type.name.title(), object_id, self.related_type.name.lower(), related_id, address, ) return False if len(stores) > 1: LOGGER.warning( "%s %s relationship container for %s %s at address %s has more than one record", self.object_type.name.title(), object_id, self.related_type.name.lower(), related_id, address, ) store = stores[0] return bool(store.object_id == object_id and store.related_id == related_id)
def get(self, object_id, related_id=None): """Gets an address from the blockchain from the validator API""" address = self.address(object_id=object_id, related_id=related_id) # pylint: disable=not-callable container = self._state_container() container.ParseFromString(client.get_address(address=address)) return self._find_in_state_container( container=container, address=address, object_id=object_id, related_id=related_id, )
def exists(self, object_id, target_id): """Check the existence of a relationship record""" # pylint: disable=not-callable container = self._state_container() address = self.address(object_id=object_id, target_id=target_id) container.ParseFromString(client.get_address(address=address)) items = list(container.relationships) if not items: return False if len(items) > 1: LOGGER.warning( "%s %s relationship container for %s %s at address %s has more than one record", self.object_type.name.title(), object_id, self.related_type.name.lower(), target_id, address, ) item = items[0] identifiers = list(item.identifiers) if not identifiers: LOGGER.warning( "%s %s relationship container for user %s %s at address %s has no identifiers", self.object_type.name.title(), object_id, self.related_type.name.lower(), target_id, address, ) return False if len(identifiers) > 1: LOGGER.warning( "%s %s relationship container for user %s %s at address %s has more than one identifier", self.object_type.name.title(), object_id, self.related_type.name.lower(), target_id, address, ) return bool(target_id in item.identifiers)