From 3eaf0a82932f718e2b6410e5dff2631bef122198 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Sun, 4 Oct 2015 13:21:48 +0200
Subject: [PATCH] Fix crash when certifying a user we could not find

---
 src/cutecoin/core/account.py      | 49 ++++++++++++++++---------------
 src/cutecoin/gui/certification.py |  2 +-
 2 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py
index 371aff88..5e6a66f8 100644
--- a/src/cutecoin/core/account.py
+++ b/src/cutecoin/core/account.py
@@ -437,29 +437,32 @@ class Account(QObject):
         blockid = yield from community.blockid()
         identity = yield from self._identities_registry.future_find(pubkey, community)
         selfcert = yield from identity.selfcert(community)
-        certification = Certification(PROTOCOL_VERSION, community.currency,
-                                      self.pubkey, pubkey,
-                                      blockid.number, blockid.sha_hash, None)
-
-        key = SigningKey(self.salt, password)
-        certification.sign(selfcert, [key])
-        signed_cert = certification.signed_raw(selfcert)
-        logging.debug("Certification : {0}".format(signed_cert))
-
-        data = {'pubkey': pubkey,
-                'self_': selfcert.signed_raw(),
-                'other': "{0}\n".format(certification.inline())}
-        logging.debug("Posted data : {0}".format(data))
-        responses = yield from community.bma_access.broadcast(bma.wot.Add, {}, data)
-        result = (False, "")
-        for r in responses:
-            if r.status == 200:
-                result = (True, (yield from r.json()))
-            elif not result[0]:
-                result = (False, (yield from r.text()))
-            else:
-                yield from r.release()
-        return result
+        if selfcert:
+            certification = Certification(PROTOCOL_VERSION, community.currency,
+                                          self.pubkey, pubkey,
+                                          blockid.number, blockid.sha_hash, None)
+
+            key = SigningKey(self.salt, password)
+            certification.sign(selfcert, [key])
+            signed_cert = certification.signed_raw(selfcert)
+            logging.debug("Certification : {0}".format(signed_cert))
+
+            data = {'pubkey': pubkey,
+                    'self_': selfcert.signed_raw(),
+                    'other': "{0}\n".format(certification.inline())}
+            logging.debug("Posted data : {0}".format(data))
+            responses = yield from community.bma_access.broadcast(bma.wot.Add, {}, data)
+            result = (False, "")
+            for r in responses:
+                if r.status == 200:
+                    result = (True, (yield from r.json()))
+                elif not result[0]:
+                    result = (False, (yield from r.text()))
+                else:
+                    yield from r.release()
+            return result
+        else:
+            return (False, self.tr("Could not find user self certification."))
 
     @asyncio.coroutine
     def revoke(self, password, community):
diff --git a/src/cutecoin/gui/certification.py b/src/cutecoin/gui/certification.py
index 79551a91..3ec8c738 100644
--- a/src/cutecoin/gui/certification.py
+++ b/src/cutecoin/gui/certification.py
@@ -114,4 +114,4 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
         future = asyncio.Future()
         self.finished.connect(lambda r: future.set_result(r))
         self.open()
-        return future
\ No newline at end of file
+        return future
-- 
GitLab