diff --git a/src/sakia/core/community.py b/src/sakia/core/community.py index 9b3fd3f6ab1bd932eac6d9c6c511abc9ae28979b..23dfb8efb7aa604998ffb7cbfd01dce2c0b8fbee 100644 --- a/src/sakia/core/community.py +++ b/src/sakia/core/community.py @@ -267,6 +267,16 @@ class Community(QObject): blockchain_time = await self.time() return blockchain_time - cert_time > parameters['sigValidity'] + async def certification_writable(self, cert_time): + """ + Return True if the certificaton time is too old + + :param int cert_time: the timestamp of the certification + """ + parameters = await self.parameters() + blockchain_time = await self.time() + return blockchain_time - cert_time < parameters['sigWindow'] * parameters['avgGenTime'] + def add_node(self, node): """ Add a peer to the community. diff --git a/src/sakia/core/registry/identity.py b/src/sakia/core/registry/identity.py index 405a2b05b6100efee0d0763bec23975c13ce1893..a1d2752a0cdae0c726d2081a015a93545b4c136a 100644 --- a/src/sakia/core/registry/identity.py +++ b/src/sakia/core/registry/identity.py @@ -346,37 +346,6 @@ class Identity(QObject): logging.debug(str(e)) return certifiers - async def unique_valid_certifiers_of(self, identities_registry, community): - """ - Get the certifications in the blockchain and in the pools - Get only unique and last certification for each pubkey - :param sakia.core.registry.identities.IdentitiesRegistry identities_registry: The identities registry - :param sakia.core.community.Community community: The community target - :return: The list of the certifiers of this community - :rtype: list - """ - certifier_list = await self.certifiers_of(identities_registry, community) - unique_valid = [] - # Â add certifiers of uid - for certifier in tuple([c for c in certifier_list if c['cert_time']]): - # add only valid certification... - try: - cert_expired = await community.certification_expired(certifier['cert_time']) - except NoPeerAvailable: - logging.debug("No peer available") - cert_expired = True - - if not cert_expired: - # keep only the latest certification - already_found = [c['identity'].pubkey for c in unique_valid] - if certifier['identity'].pubkey in already_found: - index = already_found.index(certifier['identity'].pubkey) - if certifier['cert_time'] > unique_valid[index]['cert_time']: - unique_valid[index] = certifier - else: - unique_valid.append(certifier) - return unique_valid - async def certified_by(self, identities_registry, community): """ Get the list of persons certified by this person @@ -430,37 +399,70 @@ class Identity(QObject): logging.debug(str(e)) return certified_list - async def unique_valid_certified_by(self, identities_registry, community): + async def _unique_valid(self, cert_list, community): """ - Get the list of persons certified by this person, filtered to get only unique - and valid certifications. - :param sakia.core.registry.IdentitiesRegistry identities_registry: The registry + Get the certifications in the blockchain and in the pools + Get only unique and last certification for each pubkey + :param list cert_list: The certifications list to filter :param sakia.core.community.Community community: The community target - :return: The list of the certified persons of this community in BMA json format + :return: The list of the certifiers of this community :rtype: list """ - certified_list = await self.certified_by(identities_registry, community) unique_valid = [] # Â add certifiers of uid - for certified in tuple([c for c in certified_list if c['cert_time']]): + for certifier in tuple(cert_list): # add only valid certification... try: - cert_expired = await community.certification_expired(certified['cert_time']) + cert_expired = await community.certification_expired(certifier['cert_time']) except NoPeerAvailable: logging.debug("No peer available") cert_expired = True - if not cert_expired: + if not certifier['block_number']: + # add only valid certification... + try: + cert_writable = await community.certification_writable(certifier['cert_time']) + except NoPeerAvailable: + logging.debug("No peer available") + cert_writable = False + else: + cert_writable = True + + if not cert_expired and cert_writable: # keep only the latest certification already_found = [c['identity'].pubkey for c in unique_valid] - if certified['identity'].pubkey in already_found: - index = already_found.index(certified['identity'].pubkey) - if certified['cert_time'] > unique_valid[index]['cert_time']: - unique_valid[index] = certified + if certifier['identity'].pubkey in already_found: + index = already_found.index(certifier['identity'].pubkey) + if certifier['cert_time'] > unique_valid[index]['cert_time']: + unique_valid[index] = certifier else: - unique_valid.append(certified) + unique_valid.append(certifier) return unique_valid + async def unique_valid_certifiers_of(self, identities_registry, community): + """ + Get the certifications in the blockchain and in the pools + Get only unique and last certification for each pubkey + :param sakia.core.registry.identities.IdentitiesRegistry identities_registry: The identities registry + :param sakia.core.community.Community community: The community target + :return: The list of the certifiers of this community + :rtype: list + """ + certifier_list = await self.certifiers_of(identities_registry, community) + return await self._unique_valid(certifier_list, community) + + async def unique_valid_certified_by(self, identities_registry, community): + """ + Get the list of persons certified by this person, filtered to get only unique + and valid certifications. + :param sakia.core.registry.IdentitiesRegistry identities_registry: The registry + :param sakia.core.community.Community community: The community target + :return: The list of the certified persons of this community in BMA json format + :rtype: list + """ + certified_list = await self.certified_by(identities_registry, community) + return await self._unique_valid(certified_list, community) + async def membership_expiration_time(self, community): """ Get the remaining time before membership expiration diff --git a/src/sakia/gui/certification.py b/src/sakia/gui/certification.py index 442c1368dd787e96677cd1be96e285a929c79235..7a087303f9f50a19437b674244aeb986289145b5 100644 --- a/src/sakia/gui/certification.py +++ b/src/sakia/gui/certification.py @@ -242,7 +242,7 @@ class CertificationDialog(QObject): def async_exec(self): future = asyncio.Future() - self.widget.finished.connect(lambda r: future.set_result(r) and self.widget.finished.disconnect()) + self.widget.finished.connect(lambda r: future.set_result(r)) self.widget.open() self.refresh() return future