diff --git a/src/cutecoin/core/net/network.py b/src/cutecoin/core/net/network.py index c079892aeafa964e79a9757cb01cf5686bcbddad..135eee1b9bf208b6fba95c352fc82eded8a4afb7 100644 --- a/src/cutecoin/core/net/network.py +++ b/src/cutecoin/core/net/network.py @@ -202,7 +202,7 @@ class Network(QObject): blocks_occurences = Counter(blocks) blocks_by_occurences = {} for key, value in blocks_occurences.items(): - the_block = [n.block for n in self.nodes if n.block['hash'] == key][0] + the_block = [n.block for n in self.nodes if n.block and n.block['hash'] == key][0] if value not in blocks_by_occurences: blocks_by_occurences[value] = [the_block] else: @@ -244,7 +244,7 @@ class Network(QObject): synced_block_hash = blocks_by_occurences[most_present][0]['hash'] for n in [n for n in self._nodes if n.state in (Node.ONLINE, Node.DESYNCED)]: - if n.block['hash'] == synced_block_hash: + if n.block and n.block['hash'] == synced_block_hash: n.state = Node.ONLINE else: n.state = Node.DESYNCED diff --git a/src/cutecoin/core/net/node.py b/src/cutecoin/core/net/node.py index 6e07ce66432824bd1a6cdcec66215cc479f15102..16474d09efb222705749a812dcea92a425d46964 100644 --- a/src/cutecoin/core/net/node.py +++ b/src/cutecoin/core/net/node.py @@ -99,7 +99,7 @@ class Node(QObject): raise InvalidNodeCurrency(peer.currency, currency) node = cls(peer.currency, peer.endpoints, - "", pubkey, bma.blockchain.Block.null_value, + "", pubkey, None, Node.ONLINE, time.time(), {'root': "", 'leaves': []}, "", "", 0) @@ -349,6 +349,8 @@ class Node(QObject): logging.debug("Timeout error : {0}".format(self.pubkey)) self.state = Node.OFFLINE + @asyncify + @asyncio.coroutine def refresh_summary(self): conn_handler = self.endpoint.conn_handler() @@ -371,12 +373,15 @@ class Node(QObject): logging.debug("Timeout error : {0}".format(self.pubkey)) self.state = Node.OFFLINE + @asyncify + @asyncio.coroutine def refresh_uid(self): conn_handler = self.endpoint.conn_handler() try: data = yield from bma.wot.Lookup(conn_handler, self.pubkey).get() self.state = Node.ONLINE timestamp = 0 + uid = None for result in data['results']: if result["pubkey"] == self.pubkey: uids = result['uids'] @@ -384,8 +389,7 @@ class Node(QObject): if uid["meta"]["timestamp"] > timestamp: timestamp = uid["meta"]["timestamp"] uid = uid["uid"] - - if self._uid != uid: + if uid and self._uid != uid: self._uid = uid self.changed.emit() except ValueError as e: @@ -401,6 +405,8 @@ class Node(QObject): logging.debug("Timeout error : {0}".format(self.pubkey)) self.state = Node.OFFLINE + @asyncify + @asyncio.coroutine def refresh_peers(self): conn_handler = self.endpoint.conn_handler()