Skip to content
Snippets Groups Projects
Commit 683c8af3 authored by inso's avatar inso
Browse files

Handling disconnected state

parent 6e842318
No related branches found
No related tags found
No related merge requests found
......@@ -87,7 +87,9 @@ class Cache():
if cache_key not in self.data.keys():
result = self.community.request(request, req_args, get_args,
cached=False)
# For block 0, we should have a different behaviour
# Community members and certifications
# Should be requested without caching
self.data[cache_key] = result
return self.data[cache_key]
else:
......@@ -254,11 +256,16 @@ class Community(QObject):
:return: The monetary mass value
'''
try:
block = self.request(bma.blockchain.Current)
# Get cached block by block number
block_number = self.network.latest_block
block = self.request(bma.blockchain.Block,
req_args={'number': block_number})
return block['monetaryMass']
except ValueError as e:
if '404' in e:
return 0
except NoPeerAvailable as e:
return 0
@property
def nb_members(self):
......@@ -268,11 +275,16 @@ class Community(QObject):
:return: The community members number
'''
try:
block = self.request(bma.blockchain.Current)
# Get cached block by block number
block_number = self.network.latest_block
block = self.request(bma.blockchain.Block,
req_args={'number': block_number})
return block['membersCount']
except ValueError as e:
if '404' in e:
return 0
except NoPeerAvailable as e:
return 0
@property
def network(self):
......@@ -369,7 +381,6 @@ class Community(QObject):
'''
Start the refresh processing of the cache
'''
# We have to refresh node before refresh cache
self._cache.refresh()
def request(self, request, req_args={}, get_args={}, cached=True):
......
......@@ -12,7 +12,8 @@ from ucoinpy import PROTOCOL_VERSION
from ucoinpy.documents.certification import SelfCertification
from ucoinpy.documents.membership import Membership
from ..tools.exceptions import Error, PersonNotFoundError,\
MembershipNotFoundError
MembershipNotFoundError, \
NoPeerAvailable
from PyQt5.QtCore import QMutex
......@@ -51,6 +52,7 @@ class cached(object):
except KeyError:
value = self.func(inst, community)
inst._cache[community.currency][self.func.__name__] = value
finally:
inst._cache_mutex.unlock()
......@@ -219,6 +221,9 @@ class Person(object):
except ValueError as e:
if '400' in str(e):
raise MembershipNotFoundError(self.pubkey, community.name)
except Exception as e:
logging.debug('bma.blockchain.Membership request error : ' + str(e))
raise MembershipNotFoundError(self.pubkey, community.name)
#TODO: Manage 'OUT' memberships ? Maybe ?
@cached
......@@ -247,6 +252,9 @@ class Person(object):
except ValueError as e:
if '400' in str(e):
raise MembershipNotFoundError(self.pubkey, community.name)
except Exception as e:
logging.debug('bma.blockchain.Membership request error : ' + str(e))
raise MembershipNotFoundError(self.pubkey, community.name)
return membership_data
......@@ -263,6 +271,9 @@ class Person(object):
return certifiers['isMember']
except ValueError:
return False
except Exception as e:
logging.debug('bma.wot.CertifiersOf request error : ' + str(e))
return False
@cached
def certifiers_of(self, community):
......
......@@ -258,23 +258,13 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.currencies_tabwidget.clear()
if self.app.current_account:
for community in self.app.current_account.communities:
try:
tab_currency = CurrencyTabWidget(self.app, community,
self.password_asker,
self.status_label)
tab_currency.refresh()
self.currencies_tabwidget.addTab(tab_currency,
QIcon(":/icons/currency_icon"),
community.name)
except NoPeerAvailable as e:
QMessageBox.critical(self, "Could not join {0}".format(community.currency),
str(e),
QMessageBox.Ok)
continue
except requests.exceptions.RequestException as e:
QMessageBox.critical(self, ":(",
str(e),
QMessageBox.Ok)
tab_currency = CurrencyTabWidget(self.app, community,
self.password_asker,
self.status_label)
tab_currency.refresh()
self.currencies_tabwidget.addTab(tab_currency,
QIcon(":/icons/currency_icon"),
community.name)
def refresh_accounts(self):
self.menu_change_account.clear()
......
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