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):
strdata = bytes(reply.readAll()).decode('utf-8')
json_data = json.loads(strdata)
nonlocal selfcert
selfcert = self._identities_registry.lookup(pubkey, community).selfcert(community, json_data)
selfcert = identity.selfcert(community, json_data)
future_selfcert.set_result(True)
logging.debug("Certdata")
future_certdata = asyncio.Future()
reply = community.bma_access.request(qtbma.blockchain.Current)
reply.finished.connect(lambda: build_certification_data(reply))
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()
reply = community.bma_access.request( qtbma.wot.Lookup, req_args={'search': pubkey})
reply.finished.connect(lambda: build_certification_selfcert(reply))
yield from future_selfcert
logging.debug("End")
certification = Certification(PROTOCOL_VERSION, community.currency,
self.pubkey, pubkey,
blockid['number'], blockid['hash'], None)
......@@ -369,6 +376,7 @@ class Account(QObject):
replies = community.bma_access.broadcast(qtbma.wot.Add, {}, data)
for r in replies:
r.finished.connect(lambda reply=r: self.__handle_certification_reply(replies, reply))
return True
def __handle_certification_reply(self, replies, reply):
"""
......
......@@ -34,7 +34,7 @@ class Application(QObject):
loading_progressed = pyqtSignal(int, int)
version_requested = pyqtSignal()
def __init__(self, argv, qapp):
def __init__(self, argv, qapp, loop):
'''
Create a new "cutecoin" application
......@@ -43,7 +43,7 @@ class Application(QObject):
super().__init__()
self.accounts = {}
self.current_account = None
self.qapp = qapp
self.loop = loop
self.available_version = (True,
__version__,
"")
......
......@@ -4,6 +4,7 @@ from cutecoin.core.net.api import bma as qtbma
from .identity import Identity
import json
import asyncio
import logging
......@@ -65,6 +66,40 @@ class IdentitiesRegistry:
reply.finished.connect(lambda: self.handle_lookup(reply, 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):
"""
:param cutecoin.core.registry.identity.Identity identity: The looked up identity
......
......@@ -8,6 +8,7 @@ from PyQt5.QtCore import Qt, pyqtSlot
import quamash
from ..gen_resources.certification_uic import Ui_CertificationDialog
from . import toast
import asyncio
class CertificationDialog(QDialog, Ui_CertificationDialog):
......@@ -49,8 +50,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
pubkey))
self.account.broadcast_error.connect(self.handle_error)
with quamash.QEventLoop(self.app.qapp) as loop:
loop.run_until_complete(self.account.certify(password, self.community, pubkey))
asyncio.async(self.account.certify(password, self.community, pubkey))
def certification_sent(self, pubkey, currency):
toast.display(self.tr("Certification"),
......
......@@ -17,7 +17,7 @@ from .wot_tab import WotTabWidget
from .transfer import TransferMoneyDialog
from .certification import CertificationDialog
from . import toast
import quamash
import asyncio
from ..tools.exceptions import LookupFailureError, NoPeerAvailable
from ..core.registry import IdentitiesRegistry
from ucoinpy.api import bma
......@@ -177,12 +177,7 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget):
password = self.password_asker.exec_()
if self.password_asker.result() == QDialog.Rejected:
return
with quamash.QEventLoop(self.app.qapp) as loop:
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)
asyncio.async(self.account.send_membership(password, self.community, 'IN'))
def send_membership_leaving(self):
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.""")
if self.password_asker.result() == QDialog.Rejected:
return
with quamash.QEventLoop(self.app.qapp) as loop:
loop.run_until_complete(self.account.send_membership(password, self.community, 'OUT'))
asyncio.async(self.account.send_membership(password, self.community, 'OUT'))
def publish_uid(self):
reply = QMessageBox.warning(self, self.tr("Warning"),
......
......@@ -19,10 +19,12 @@ if __name__ == '__main__':
signal.signal(signal.SIGINT, signal.SIG_DFL)
cutecoin = QApplication(sys.argv)
app = Application(sys.argv, cutecoin)
loop = QEventLoop(app)
loop = QEventLoop(cutecoin)
app = Application(sys.argv, cutecoin, loop)
asyncio.set_event_loop(loop)
with loop:
window = MainWindow(app)
window.showMaximized()
loop.run_forever()
sys.exit(cutecoin.exec_())
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment