diff --git a/src/cutecoin/core/community.py b/src/cutecoin/core/community.py index 7a7d3fd69898e9f99f27bc216d5e66c743aa255b..5325475dca7900669844d6ef0b332dee06605354 100644 --- a/src/cutecoin/core/community.py +++ b/src/cutecoin/core/community.py @@ -478,7 +478,7 @@ class Community(QObject): nodes_data = [] for node in self._network.root_nodes: - nodes_data.append(node.jsonify()) + nodes_data.append(node.jsonify_root_node()) data = {'currency': self.currency, 'peers': nodes_data} diff --git a/src/cutecoin/core/net/network.py b/src/cutecoin/core/net/network.py index 7d3cc30323431bc904ed84558c11815bb94ac10c..b33dd0976f30b71eff3055572220fdb42b77d2c7 100644 --- a/src/cutecoin/core/net/network.py +++ b/src/cutecoin/core/net/network.py @@ -26,7 +26,7 @@ class Network(Watcher): Constructor of a network :param str currency: The currency name of the community - :param list nodes: The nodes of the network + :param list nodes: The root nodes of the network ''' super().__init__() self._root_nodes = nodes @@ -63,11 +63,12 @@ class Network(Watcher): if node.pubkey not in [n.pubkey for n in self.nodes]: self.add_node(node) logging.debug("Loading : {:}".format(data['pubkey'])) - for n in self.nodes: - try: - n.changed.disconnect() - except TypeError: - pass + else: + other_node = [n for n in self.nodes if n.pubkey == node.pubkey][0] + if other_node.block < node.block: + other_node.block = node.block + other_node.last_change = node.last_change + other_node.state = node.state @classmethod def from_json(cls, currency, json_data): diff --git a/src/cutecoin/core/net/node.py b/src/cutecoin/core/net/node.py index 165aba984700b5efa773143fd51ce603196ee0ae..3f6cb0b696600aa8a32e40d62cbdf0441808e2de 100644 --- a/src/cutecoin/core/net/node.py +++ b/src/cutecoin/core/net/node.py @@ -71,7 +71,6 @@ class Node(QObject): node = cls(peer.currency, peer.endpoints, "", peer.pubkey, 0, Node.ONLINE, time.time()) - node.refresh_state() logging.debug("Node from address : {:}".format(str(node))) return node @@ -90,7 +89,6 @@ class Node(QObject): node = cls(peer.currency, peer.endpoints, "", "", 0, Node.ONLINE, time.time()) - node.refresh_state() logging.debug("Node from peer : {:}".format(str(node))) return node @@ -99,6 +97,7 @@ class Node(QObject): endpoints = [] uid = "" pubkey = "" + block = 0 last_change = time.time() state = Node.ONLINE logging.debug(data) @@ -117,24 +116,38 @@ class Node(QObject): if 'last_change' in data: last_change = data['last_change'] + if 'block' in data: + block = data['block'] + if 'state' in data: state = data['state'] else: logging.debug("Error : no state in node") - node = cls(currency, endpoints, uid, pubkey, 0, + node = cls(currency, endpoints, uid, pubkey, block, state, last_change) - node.refresh_state() logging.debug("Node from json : {:}".format(str(node))) return node + def jsonify_root_node(self): + logging.debug("Saving root node : {:}".format(str(self))) + data = {'pubkey': self._pubkey, + 'uid': self._uid, + 'currency': self._currency} + endpoints = [] + for e in self._endpoints: + endpoints.append(e.inline()) + data['endpoints'] = endpoints + return data + def jsonify(self): logging.debug("Saving node : {:}".format(str(self))) data = {'pubkey': self._pubkey, 'uid': self._uid, 'currency': self._currency, 'state': self._state, - 'last_change': self._last_change} + 'last_change': self._last_change, + 'block': self.block} endpoints = [] for e in self._endpoints: endpoints.append(e.inline()) diff --git a/src/cutecoin/gui/contact.py b/src/cutecoin/gui/contact.py index a753de202864aee35ab44c27925702b8d7f0c3c1..a176ab22a8238b8ccc147f239e58c6090d989a55 100644 --- a/src/cutecoin/gui/contact.py +++ b/src/cutecoin/gui/contact.py @@ -32,6 +32,8 @@ class ConfigureContactDialog(QDialog, Ui_ConfigureContactDialog): 'pubkey': contact.pubkey} elif type(contact) is dict: self.contact = contact + else: + self.contact = None if index_edit is not None: self.contact = account.contacts[index_edit]