From dbd838cff218cec81acd2929b4a4782aed2afbbd Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Sun, 14 Dec 2014 19:45:51 +0100
Subject: [PATCH] Fixing some bugs

---
 lib/ucoinpy/api/bma/tx/__init__.py            |  2 +-
 lib/ucoinpy/documents/transaction.py          |  2 +-
 src/cutecoin/gui/processConfigureAccount.py   |  4 ----
 src/cutecoin/gui/processConfigureCommunity.py | 20 +++++++++++++++----
 src/cutecoin/models/node/__init__.py          |  2 +-
 src/cutecoin/models/person/__init__.py        |  4 ++++
 src/cutecoin/tools/exceptions.py              | 20 ++++++-------------
 7 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/lib/ucoinpy/api/bma/tx/__init__.py b/lib/ucoinpy/api/bma/tx/__init__.py
index 10ea07a5..384b7ff9 100644
--- a/lib/ucoinpy/api/bma/tx/__init__.py
+++ b/lib/ucoinpy/api/bma/tx/__init__.py
@@ -44,4 +44,4 @@ class Sources(Tx):
 
     def __get__(self, **kwargs):
         assert self.pubkey is not None
-        return self.requests_get('/sources/%s' % self.pubkey, **kwargs).json()
+        return self.requests_get('/sources/%d' % self.pubkey, **kwargs).json()
diff --git a/lib/ucoinpy/documents/transaction.py b/lib/ucoinpy/documents/transaction.py
index 251c6b89..2cbdb700 100644
--- a/lib/ucoinpy/documents/transaction.py
+++ b/lib/ucoinpy/documents/transaction.py
@@ -265,7 +265,7 @@ class InputSource():
     @classmethod
     def from_bma(cls, bma_data):
         index = None
-        source = bma_data['type']
+        source = bma_data['source']
         number = bma_data['number']
         txhash = bma_data['fingerprint']
         amount = bma_data['amount']
diff --git a/src/cutecoin/gui/processConfigureAccount.py b/src/cutecoin/gui/processConfigureAccount.py
index 9d5d0e7e..2ad208e4 100644
--- a/src/cutecoin/gui/processConfigureAccount.py
+++ b/src/cutecoin/gui/processConfigureAccount.py
@@ -35,7 +35,6 @@ class StepPageInit(Step):
             return False
 
     def process_next(self):
-        logging.debug("Init NEXT")
         if self.config_dialog.account is None:
             name = self.config_dialog.edit_account_name.text()
             self.config_dialog.account = self.config_dialog.core.create_account(name)
@@ -44,7 +43,6 @@ class StepPageInit(Step):
             self.config_dialog.account.name = name
 
     def display_page(self):
-        logging.debug("Init DISPLAY")
         if self.config_dialog.account is not None:
             self.config_dialog.edit_account_name.setText(self.config_dialog.account.name)
             model = CommunitiesListModel(self.config_dialog.account)
@@ -75,7 +73,6 @@ class StepPageKey(Step):
         return True
 
     def process_next(self):
-        logging.debug("Key NEXT")
         salt = self.config_dialog.edit_email.text()
         password = self.config_dialog.edit_password.text()
         self.config_dialog.account.salt = salt
@@ -84,7 +81,6 @@ class StepPageKey(Step):
         self.config_dialog.list_communities.setModel(model)
 
     def display_page(self):
-        logging.debug("Key DISPLAY")
         self.config_dialog.button_previous.setEnabled(False)
         self.config_dialog.button_next.setEnabled(False)
 
diff --git a/src/cutecoin/gui/processConfigureCommunity.py b/src/cutecoin/gui/processConfigureCommunity.py
index 68af5ea8..5c1f58d9 100644
--- a/src/cutecoin/gui/processConfigureCommunity.py
+++ b/src/cutecoin/gui/processConfigureCommunity.py
@@ -11,6 +11,8 @@ from PyQt5.QtWidgets import QDialog, QMenu, QMessageBox, QWidget, QAction
 from PyQt5.QtCore import QSignalMapper
 from cutecoin.models.node.treeModel import NodesTreeModel
 from cutecoin.models.node import Node
+from cutecoin.models.person import Person
+from cutecoin.tools.exceptions import PersonNotFoundError
 from cutecoin.tools.exceptions import Error
 
 
@@ -158,10 +160,20 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog):
 
     def accept(self):
         try:
-            self.account.send_pubkey(self.community)
-        except Error as e:
-            QMessageBox.critical(self, "Pubkey publishing error",
-                              e.message)
+            Person.lookup(self.account.pubkey, self.community)
+        except PersonNotFoundError as e:
+            reply = QMessageBox.question(self, "Pubkey not found",
+                                 "The public key of your account wasn't found in the community. :\n \
+                                 {0}\n \
+                                 Would you like to publish the key ?".format(self.account.pubkey))
+            if reply == QMessageBox.Yes:
+                try:
+                    self.account.send_pubkey(self.community)
+                except Error as e:
+                    QMessageBox.critical(self, "Pubkey publishing error",
+                                      e.message)
+            else:
+                return
 
         self.accepted.emit()
         self.close()
diff --git a/src/cutecoin/models/node/__init__.py b/src/cutecoin/models/node/__init__.py
index eeb94a1c..c1794258 100644
--- a/src/cutecoin/models/node/__init__.py
+++ b/src/cutecoin/models/node/__init__.py
@@ -46,7 +46,7 @@ class Node(object):
 
     def __eq__(self, other):
         pubkey = bma.network.Peering(server=self.server,
-                                     port=self.port).get()['puubkey']
+                                     port=self.port).get()['pubkey']
         other_pubkey = bma.network.Peering(server=other.server,
                                            port=other.port).get()['pubkey']
         return (pubkey == other_pubkey)
diff --git a/src/cutecoin/models/person/__init__.py b/src/cutecoin/models/person/__init__.py
index c22c81b0..0c2dc519 100644
--- a/src/cutecoin/models/person/__init__.py
+++ b/src/cutecoin/models/person/__init__.py
@@ -37,6 +37,10 @@ class Person(object):
                 name = uids[0]["uid"]
             else:
                 raise PersonNotFoundError(pubkey, community.name())
+                return None
+        else:
+            raise PersonNotFoundError(pubkey, community.name())
+            return None
         return cls(name, pubkey)
 
     @classmethod
diff --git a/src/cutecoin/tools/exceptions.py b/src/cutecoin/tools/exceptions.py
index 6354da4d..31613389 100644
--- a/src/cutecoin/tools/exceptions.py
+++ b/src/cutecoin/tools/exceptions.py
@@ -24,7 +24,7 @@ class NotMemberOfCommunityError(Error):
         '''
         Constructor
         '''
-        super(NotMemberOfCommunityError, self) \
+        super() \
             .__init__(account + " is not a member of " + community)
 
 
@@ -39,9 +39,7 @@ class PersonNotFoundError(Error):
         '''
         Constructor
         '''
-        super(
-            PersonNotFoundError,
-            self) .__init(
+        super() .__init__(
             "Person looked by " +
             value +
             " in " +
@@ -59,7 +57,7 @@ class AlgorithmNotImplemented(Error):
         '''
         Constructor
         '''
-        super(AlgorithmNotImplemented, self) \
+        super() \
             .__init__("Algorithm " + algo_name + " not implemented.")
 
 
@@ -74,9 +72,7 @@ class KeyAlreadyUsed(Error):
         '''
         Constructor
         '''
-        super(
-            KeyAlreadyUsed,
-            self) .__init__(
+        super() .__init__(
             "Cannot add account " +
             new_account.name +
             " : the pgpKey " +
@@ -96,9 +92,7 @@ class NameAlreadyExists(Error):
         '''
         Constructor
         '''
-        super(
-            KeyAlreadyUsed,
-            self) .__init__(
+        super() .__init__(
             "Cannot add account " +
             account.name +
             " the name already exists")
@@ -115,7 +109,5 @@ class BadAccountFile(Error):
         '''
         Constructor
         '''
-        super(
-            BadAccountFile,
-            self) .__init__(
+        super() .__init__(
             "File " + path + " is not an account file")
-- 
GitLab