Skip to content
Snippets Groups Projects
Commit 4b05e81e authored by inso's avatar inso
Browse files

Fixed bugs thanks to vit recipe

- Wallet was displaying too many certifications
- Bug in community refreshing when a new block was mined
parent 7d6ec2f7
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ import logging
import inspect
import hashlib
import re
import time
from requests.exceptions import RequestException
......@@ -103,7 +104,7 @@ class Community(QObject):
but nothing exists in ucoin to assert that a currency name is unique.
'''
new_block_mined = pyqtSignal()
new_block_mined = pyqtSignal(int)
def __init__(self, currency, network):
'''
......@@ -299,10 +300,16 @@ class Community(QObject):
@property
def parameters(self):
'''
Return community parameters in bma format
'''
return self.request(bma.blockchain.Parameters)
def certification_expired(self, certtime):
'''
Return True if the certificaton time is too old
'''
return time.time() - certtime > self.parameters['sigValidity']
@property
def add_peer(self, peer):
'''
......
......@@ -303,6 +303,25 @@ class Person(object):
return certifiers['certifications']
def unique_valid_certifiers_of(self, community):
certifier_list = self.certifiers_of(community)
unique_valid = []
# add certifiers of uid
for certifier in tuple(certifier_list):
# add only valid certification...
if community.certification_expired(certifier['cert_time']['medianTime']):
continue
# keep only the latest certification
already_found = [c['pubkey'] for c in unique_valid]
if certifier['pubkey'] in already_found:
index = already_found.index(certifier['pubkey'])
if certifier['cert_time']['medianTime'] > unique_valid[index]['cert_time']['medianTime']:
unique_valid[index] = certifier
else:
unique_valid.append(certifier)
return unique_valid
@cached
def certified_by(self, community):
'''
......@@ -335,6 +354,25 @@ class Person(object):
return certified_list['certifications']
def unique_valid_certified_by(self, community):
certified_list = self.certified_by(community)
unique_valid = []
# add certifiers of uid
for certified in tuple(certified_list):
# add only valid certification...
if community.certification_expired(certified['cert_time']['medianTime']):
continue
# keep only the latest certification
already_found = [c['pubkey'] for c in unique_valid]
if certified['pubkey'] in already_found:
index = already_found.index(certified['pubkey'])
if certified['cert_time']['medianTime'] > unique_valid[index]['cert_time']['medianTime']:
unique_valid[index] = certified
else:
unique_valid.append(certified)
return unique_valid
def reload(self, func, community):
'''
Reload a cached property of this person in a community.
......
......@@ -4,10 +4,11 @@ Created on 18 mars 2015
@author: inso
'''
from PyQt5.QtCore import QThread
from PyQt5.QtCore import QThread, Qt
from .blockchain import BlockchainWatcher
from .persons import PersonsWatcher
from .network import NetworkWatcher
import logging
class Monitor(object):
......@@ -34,14 +35,18 @@ class Monitor(object):
def persons_watcher(self, community):
return self._persons_watchers[community.name]
def restart_persons_watching(self, community):
watcher = self.persons_watcher(community)
thread = watcher.thread()
logging.debug("Persons watching thread is : {0}".format(thread.isFinished()))
thread.start()
def connect_watcher_to_thread(self, watcher):
thread = QThread()
watcher.moveToThread(thread)
thread.started.connect(watcher.watch)
watcher.watching_stopped.connect(thread.exit)
thread.finished.connect(lambda: self.threads_pool.remove(thread))
thread.finished.connect(watcher.deleteLater)
thread.finished.connect(thread.deleteLater)
success = watcher.watching_stopped.connect(thread.exit, Qt.DirectConnection)
self.threads_pool.append(thread)
def prepare_watching(self):
......@@ -65,9 +70,18 @@ class Monitor(object):
def stop_watching(self):
for watcher in self._persons_watchers.values():
watcher.stop()
self.threads_pool.remove(watcher.thread())
watcher.deleteLater()
watcher.thread().deleteLater()
for watcher in self._blockchain_watchers.values():
watcher.stop()
self.threads_pool.remove(watcher.thread())
watcher.deleteLater()
watcher.thread().deleteLater()
for watcher in self._network_watchers.values():
watcher.stop()
self.threads_pool.remove(watcher.thread())
watcher.deleteLater()
watcher.thread().deleteLater()
......@@ -35,6 +35,7 @@ class PersonsWatcher(Watcher):
logging.debug("Change detected on {0} about {1}".format(p.pubkey,
func.__name__))
self.person_changed.emit(p.pubkey)
logging.debug("Finished watching persons")
self.watching_stopped.emit()
def stop(self):
......
......@@ -166,8 +166,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
QModelIndex(),
QModelIndex(),
[])
self.persons_watcher_thread.start()
self.app.monitor.restart_persons_watching(self.community)
text = "Connected : Block {0}".format(block_number)
self.status_label.setText(text)
......
......@@ -44,8 +44,8 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab):
try:
person = Person.lookup(self.account.pubkey, self.community)
membership = person.membership(self.community)
certified = person.certified_by(self.community)
certifiers = person.certifiers_of(self.community)
certified = person.unique_valid_certified_by(self.community)
certifiers = person.unique_valid_certifiers_of(self.community)
renew_block = membership['blockNumber']
last_renewal = self.community.get_block(renew_block).mediantime
......@@ -54,7 +54,6 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab):
pass
date_renewal = QDateTime.fromTime_t(last_renewal).date().toString()
date_expiration = QDateTime.fromTime_t(expiration).date().toString()
# set infos in label
self.label_general.setText(
"""
......@@ -68,8 +67,8 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab):
"Membership",
"Last renewal on {:}, expiration on {:}".format(date_renewal, date_expiration),
"Your web of trust :",
"Certified by : {0} members; Certifier of : {1} members".format(len(certified),
len(certifiers))
"Certified by : {0} members; Certifier of : {1} members".format(len(certifiers),
len(certified))
)
)
......
......@@ -63,6 +63,9 @@ class WalletsTableModel(QAbstractTableModel):
super().__init__(parent)
self.account = account
self.community = community
self.columns_texts = {'name': 'Name',
'pubkey': 'Pubkey',
'amount': 'Amount'}
self.columns_types = ('name', 'pubkey', 'amount')
@property
......@@ -77,7 +80,8 @@ class WalletsTableModel(QAbstractTableModel):
def headerData(self, section, orientation, role):
if role == Qt.DisplayRole:
return self.columns_types[section]
col_type = self.columns_types[section]
return self.columns_texts[col_type]
def wallet_data(self, row):
name = self.wallets[row].name
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment