Skip to content
Snippets Groups Projects
Commit 49d8869e authored by inso's avatar inso
Browse files

IdentitiesRegistry can now returns a future lookup

parent 5537c3d2
No related branches found
No related tags found
No related merge requests found
...@@ -340,19 +340,26 @@ class Account(QObject): ...@@ -340,19 +340,26 @@ class Account(QObject):
strdata = bytes(reply.readAll()).decode('utf-8') strdata = bytes(reply.readAll()).decode('utf-8')
json_data = json.loads(strdata) json_data = json.loads(strdata)
nonlocal selfcert nonlocal selfcert
selfcert = self._identities_registry.lookup(pubkey, community).selfcert(community, json_data) selfcert = identity.selfcert(community, json_data)
future_selfcert.set_result(True) future_selfcert.set_result(True)
logging.debug("Certdata")
future_certdata = asyncio.Future() future_certdata = asyncio.Future()
reply = community.bma_access.request(qtbma.blockchain.Current) reply = community.bma_access.request(qtbma.blockchain.Current)
reply.finished.connect(lambda: build_certification_data(reply)) reply.finished.connect(lambda: build_certification_data(reply))
yield from future_certdata yield from future_certdata
logging.debug("Identity")
identity = yield from self._identities_registry.future_lookup(pubkey, community)
logging.debug("YEILDDDDDDDDDdD")
logging.debug("Selfcert")
future_selfcert = asyncio.Future() future_selfcert = asyncio.Future()
reply = community.bma_access.request( qtbma.wot.Lookup, req_args={'search': pubkey}) reply = community.bma_access.request( qtbma.wot.Lookup, req_args={'search': pubkey})
reply.finished.connect(lambda: build_certification_selfcert(reply)) reply.finished.connect(lambda: build_certification_selfcert(reply))
yield from future_selfcert yield from future_selfcert
logging.debug("End")
certification = Certification(PROTOCOL_VERSION, community.currency, certification = Certification(PROTOCOL_VERSION, community.currency,
self.pubkey, pubkey, self.pubkey, pubkey,
blockid['number'], blockid['hash'], None) blockid['number'], blockid['hash'], None)
...@@ -369,6 +376,7 @@ class Account(QObject): ...@@ -369,6 +376,7 @@ class Account(QObject):
replies = community.bma_access.broadcast(qtbma.wot.Add, {}, data) replies = community.bma_access.broadcast(qtbma.wot.Add, {}, data)
for r in replies: for r in replies:
r.finished.connect(lambda reply=r: self.__handle_certification_reply(replies, reply)) r.finished.connect(lambda reply=r: self.__handle_certification_reply(replies, reply))
return True
def __handle_certification_reply(self, replies, reply): def __handle_certification_reply(self, replies, reply):
""" """
......
...@@ -34,7 +34,7 @@ class Application(QObject): ...@@ -34,7 +34,7 @@ class Application(QObject):
loading_progressed = pyqtSignal(int, int) loading_progressed = pyqtSignal(int, int)
version_requested = pyqtSignal() version_requested = pyqtSignal()
def __init__(self, argv, qapp): def __init__(self, argv, qapp, loop):
''' '''
Create a new "cutecoin" application Create a new "cutecoin" application
...@@ -43,7 +43,7 @@ class Application(QObject): ...@@ -43,7 +43,7 @@ class Application(QObject):
super().__init__() super().__init__()
self.accounts = {} self.accounts = {}
self.current_account = None self.current_account = None
self.qapp = qapp self.loop = loop
self.available_version = (True, self.available_version = (True,
__version__, __version__,
"") "")
......
...@@ -4,6 +4,7 @@ from cutecoin.core.net.api import bma as qtbma ...@@ -4,6 +4,7 @@ from cutecoin.core.net.api import bma as qtbma
from .identity import Identity from .identity import Identity
import json import json
import asyncio
import logging import logging
...@@ -65,6 +66,40 @@ class IdentitiesRegistry: ...@@ -65,6 +66,40 @@ class IdentitiesRegistry:
reply.finished.connect(lambda: self.handle_lookup(reply, identity)) reply.finished.connect(lambda: self.handle_lookup(reply, identity))
return identity return identity
@asyncio.coroutine
def future_lookup(self, pubkey, community):
def handle_reply(reply):
strdata = bytes(reply.readAll()).decode('utf-8')
data = json.loads(strdata)
timestamp = 0
for result in data['results']:
if result["pubkey"] == identity.pubkey:
uids = result['uids']
identity_uid = ""
for uid_data in uids:
if uid_data["meta"]["timestamp"] > timestamp:
timestamp = uid_data["meta"]["timestamp"]
identity_uid = uid_data["uid"]
identity.uid = identity_uid
identity.status = Identity.FOUND
logging.debug("Lookup : found {0}".format(identity))
future_identity.set_result(True)
future_identity = asyncio.Future()
logging.debug("Future identity")
if pubkey in self._instances:
identity = self._instances[pubkey]
future_identity.set_result(True)
else:
identity = Identity.empty(pubkey)
self._instances[pubkey] = identity
reply = community.bma_access.request(qtbma.wot.Lookup, req_args={'search': pubkey})
reply.finished.connect(lambda: handle_reply(reply))
logging.debug("Return")
yield from future_identity
return identity
def handle_lookup(self, reply, identity): def handle_lookup(self, reply, identity):
""" """
:param cutecoin.core.registry.identity.Identity identity: The looked up identity :param cutecoin.core.registry.identity.Identity identity: The looked up identity
......
...@@ -8,6 +8,7 @@ from PyQt5.QtCore import Qt, pyqtSlot ...@@ -8,6 +8,7 @@ from PyQt5.QtCore import Qt, pyqtSlot
import quamash import quamash
from ..gen_resources.certification_uic import Ui_CertificationDialog from ..gen_resources.certification_uic import Ui_CertificationDialog
from . import toast from . import toast
import asyncio
class CertificationDialog(QDialog, Ui_CertificationDialog): class CertificationDialog(QDialog, Ui_CertificationDialog):
...@@ -49,8 +50,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): ...@@ -49,8 +50,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
pubkey)) pubkey))
self.account.broadcast_error.connect(self.handle_error) self.account.broadcast_error.connect(self.handle_error)
with quamash.QEventLoop(self.app.qapp) as loop: asyncio.async(self.account.certify(password, self.community, pubkey))
loop.run_until_complete(self.account.certify(password, self.community, pubkey))
def certification_sent(self, pubkey, currency): def certification_sent(self, pubkey, currency):
toast.display(self.tr("Certification"), toast.display(self.tr("Certification"),
......
...@@ -17,7 +17,7 @@ from .wot_tab import WotTabWidget ...@@ -17,7 +17,7 @@ from .wot_tab import WotTabWidget
from .transfer import TransferMoneyDialog from .transfer import TransferMoneyDialog
from .certification import CertificationDialog from .certification import CertificationDialog
from . import toast from . import toast
import quamash import asyncio
from ..tools.exceptions import LookupFailureError, NoPeerAvailable from ..tools.exceptions import LookupFailureError, NoPeerAvailable
from ..core.registry import IdentitiesRegistry from ..core.registry import IdentitiesRegistry
from ucoinpy.api import bma from ucoinpy.api import bma
...@@ -177,12 +177,7 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): ...@@ -177,12 +177,7 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget):
password = self.password_asker.exec_() password = self.password_asker.exec_()
if self.password_asker.result() == QDialog.Rejected: if self.password_asker.result() == QDialog.Rejected:
return return
with quamash.QEventLoop(self.app.qapp) as loop: asyncio.async(self.account.send_membership(password, self.community, 'IN'))
loop.run_until_complete(self.account.send_membership(password, self.community, 'IN'))
# except Exception as e:
# QMessageBox.critical(self, "Error",
# "{0}".format(e),
# QMessageBox.Ok)
def send_membership_leaving(self): def send_membership_leaving(self):
reply = QMessageBox.warning(self, self.tr("Warning"), reply = QMessageBox.warning(self, self.tr("Warning"),
...@@ -195,8 +190,7 @@ The process to join back the community later will have to be done again.""") ...@@ -195,8 +190,7 @@ The process to join back the community later will have to be done again.""")
if self.password_asker.result() == QDialog.Rejected: if self.password_asker.result() == QDialog.Rejected:
return return
with quamash.QEventLoop(self.app.qapp) as loop: asyncio.async(self.account.send_membership(password, self.community, 'OUT'))
loop.run_until_complete(self.account.send_membership(password, self.community, 'OUT'))
def publish_uid(self): def publish_uid(self):
reply = QMessageBox.warning(self, self.tr("Warning"), reply = QMessageBox.warning(self, self.tr("Warning"),
......
...@@ -19,10 +19,12 @@ if __name__ == '__main__': ...@@ -19,10 +19,12 @@ if __name__ == '__main__':
signal.signal(signal.SIGINT, signal.SIG_DFL) signal.signal(signal.SIGINT, signal.SIG_DFL)
cutecoin = QApplication(sys.argv) cutecoin = QApplication(sys.argv)
app = Application(sys.argv, cutecoin) loop = QEventLoop(cutecoin)
loop = QEventLoop(app) app = Application(sys.argv, cutecoin, loop)
asyncio.set_event_loop(loop) asyncio.set_event_loop(loop)
window = MainWindow(app) with loop:
window.showMaximized() window = MainWindow(app)
window.showMaximized()
loop.run_forever()
sys.exit(cutecoin.exec_()) sys.exit(cutecoin.exec_())
pass pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment