diff --git a/src/sakia/gui/dialogs/connection_cfg/controller.py b/src/sakia/gui/dialogs/connection_cfg/controller.py index 66847154a3bbc5c110a64c1d52a9adf3a908d75a..1400ce737a1949913f356c69ba44f43e9776afcd 100644 --- a/src/sakia/gui/dialogs/connection_cfg/controller.py +++ b/src/sakia/gui/dialogs/connection_cfg/controller.py @@ -148,14 +148,17 @@ class ConnectionConfigController(ComponentController): self.view.progress_bar.setMaximum(3) await self.model.initialize_blockchain(self.view.stream_log) self.view.progress_bar.setValue(1) - self.view.display_info(self.tr("Broadcasting identity...")) - self.view.stream_log("Broadcasting identity...") - password = await self.password_asker.async_exec() - result = await self.model.publish_selfcert(self.model.connection.salt, password) - if result[0]: - self.view.show_success(self.model.notification()) - else: - self.view.show_error(self.model.notification(), result[1]) + await self.model.initialize_sources(self.view.stream_log) + self.view.progress_bar.setValue(3) + if mode == ConnectionConfigController.REGISTER: + self.view.display_info(self.tr("Broadcasting identity...")) + self.view.stream_log("Broadcasting identity...") + password = await self.password_asker.async_exec() + result = await self.model.publish_selfcert(self.model.connection.salt, password) + if result[0]: + self.view.show_success(self.model.notification()) + else: + self.view.show_error(self.model.notification(), result[1]) self._logger.debug("Validate changes") self.accept() @@ -191,7 +194,7 @@ class ConnectionConfigController(ComponentController): @asyncify async def check_connect(self, checked=False): self._logger.debug("Is valid ? ") - self.view.display_info.setText(self.tr("connecting...")) + self.view.display_info(self.tr("connecting...")) try: salt = self.view.edit_salt.text() password = self.view.edit_password.text() @@ -226,7 +229,7 @@ Yours : {0}, the network : {1}""".format(registered[1], registered[2]))) self.view.display_info(self.tr("""Your pubkey or UID was already found on the network. Yours : {0}, the network : {1}""".format(registered[1], registered[2]))) else: - self.display_info("Your account already exists on the network") + self.view.display_info("Your account already exists on the network") except NoPeerAvailable: self.view.display_info(self.tr("Could not connect. Check node peering entry")) diff --git a/src/sakia/gui/dialogs/connection_cfg/model.py b/src/sakia/gui/dialogs/connection_cfg/model.py index f9135a6e8c0d99a611113e051a86785b6458c72c..bb5e4dd39f83e6d19f9e12849976a709505eba17 100644 --- a/src/sakia/gui/dialogs/connection_cfg/model.py +++ b/src/sakia/gui/dialogs/connection_cfg/model.py @@ -5,7 +5,7 @@ from duniterpy.api import bma, errors from duniterpy.key import SigningKey from sakia.data.entities import Connection, Identity, Blockchain, Node from sakia.data.connectors import NodeConnector, BmaConnector -from sakia.data.processors import ConnectionsProcessor, NodesProcessor, BlockchainProcessor +from sakia.data.processors import ConnectionsProcessor, NodesProcessor, BlockchainProcessor, SourcesProcessor from sakia.gui.component.model import ComponentModel @@ -59,10 +59,18 @@ class ConnectionConfigModel(ComponentModel): :param function log_stream: a method to log data in the screen :return: """ - blockchain_processor = BlockchainProcessor(self.app.db.blockchains_repo, - BmaConnector(NodesProcessor(self.app.db.nodes_repo))) + blockchain_processor = BlockchainProcessor.instanciate(self.app) await blockchain_processor.initialize_blockchain(self.node_connector.node.currency, log_stream) + async def initialize_sources(self, log_stream): + """ + Download sources information locally + :param function log_stream: a method to log data in the screen + :return: + """ + sources_processor = SourcesProcessor.instanciate(self.app) + await sources_processor.initialize_sources(self.node_connector.node.currency, self.connection.pubkey, log_stream) + async def publish_selfcert(self, salt, password): """" Publish the self certification of the connection identity diff --git a/src/sakia/gui/navigation/informations/controller.py b/src/sakia/gui/navigation/informations/controller.py index 5998a8aed2e79a11f349fe23ad26a9c264223030..5c2107fc0b28b2f1d252974c45cc542455d77234 100644 --- a/src/sakia/gui/navigation/informations/controller.py +++ b/src/sakia/gui/navigation/informations/controller.py @@ -22,7 +22,6 @@ class InformationsController(ComponentController): :param sakia.gui.informations.model.InformationsModel model: the model """ super().__init__(parent, view, model) - self.init_view_text() @property def informations_view(self): @@ -33,13 +32,15 @@ class InformationsController(ComponentController): @classmethod def create(cls, parent, app, **kwargs): - account = kwargs['account'] - community = kwargs['community'] + connection = kwargs['connection'] + blockchain_service = kwargs['blockchain_service'] + sources_service = kwargs['sources_service'] view = InformationsView(parent.view) - model = InformationsModel(None, app, account, community) + model = InformationsModel(None, app, connection, blockchain_service, sources_service) informations = cls(parent, view, model) model.setParent(informations) + informations.init_view_text() return informations @property diff --git a/src/sakia/gui/navigation/informations/model.py b/src/sakia/gui/navigation/informations/model.py index 2e7ede63aca751ce1a8650d159d8d7ca171fe2d2..1f668dea948cc128a38f92e26ba63aefa461718b 100644 --- a/src/sakia/gui/navigation/informations/model.py +++ b/src/sakia/gui/navigation/informations/model.py @@ -4,6 +4,7 @@ import math from PyQt5.QtCore import QLocale, QDateTime, pyqtSignal from sakia.errors import NoPeerAvailable +from sakia.money.currency import shortened from sakia.gui.component.model import ComponentModel from sakia.money import Referentials @@ -14,111 +15,109 @@ class InformationsModel(ComponentModel): """ localized_data_changed = pyqtSignal(dict) - def __init__(self, parent, app, account, community): + def __init__(self, parent, app, connection, blockchain_service, sources_service): """ Constructor of an component :param sakia.gui.informations.controller.InformationsController parent: the controller - :param sakia.core.Application app: the app - :param sakia.core.Account account: the account - :param sakia.core.Community community: the community + :param sakia.app.Application app: the app + :param sakia.data.entities.Connection connection: the user connection of this node + :param sakia.services.BlockchainService blockchain_service: the service watching the blockchain state + :param sakia.services.SourcesService sources_service: the service watching the sources states """ super().__init__(parent) self.app = app - self.account = account - self.community = community + self.connection = connection + self.blockchain_service = blockchain_service + self.sources_service = sources_service async def get_localized_data(self): localized_data = {} # try to request money parameters try: - params = await self.community.parameters() + params = self.blockchain_service.parameters() except NoPeerAvailable as e: logging.debug('community parameters error : ' + str(e)) return None - localized_data['growth'] = params['c'] - localized_data['days_per_dividend'] = params['dt'] / 86400 + localized_data['growth'] = params.c + localized_data['days_per_dividend'] = params.dt / 86400 - try: - block_ud = await self.community.get_ud_block() - except NoPeerAvailable as e: - logging.debug('community get_ud_block error : ' + str(e)) - - try: - block_ud_minus_1 = await self.community.get_ud_block(x=1) - except NoPeerAvailable as e: - logging.debug('community get_ud_block error : ' + str(e)) + last_ud, last_ud_base = self.blockchain_service.last_ud() + members_count = self.blockchain_service.last_members_count() + previous_ud, previous_ud_base = self.blockchain_service.previous_ud() + previous_ud_time = self.blockchain_service.previous_ud_time() + previous_monetary_mass = self.blockchain_service.previous_monetary_mass() + previous_members_count = self.blockchain_service.previous_members_count() - localized_data['units'] = self.account.current_ref.instance(0, self.community, self.app, None).units - localized_data['diff_units'] = self.account.current_ref.instance(0, self.community, self.app, None).diff_units + localized_data['units'] = self.app.current_ref.instance(0, self.connection.currency, self.app, None).units + localized_data['diff_units'] = self.app.current_ref.instance(0, self.connection.currency, self.app, None).diff_units - if block_ud: + if last_ud: # display float values - localized_data['ud'] = await self.account.current_ref.instance(block_ud['dividend'] * math.pow(10, block_ud['unitbase']), - self.community, + localized_data['ud'] = await self.app.current_ref.instance(last_ud * math.pow(10, last_ud_base), + self.connection.currency, self.app) \ - .diff_localized(True, self.app.preferences['international_system_of_units']) + .diff_localized(True, self.app.parameters.international_system_of_units) - localized_data['members_count'] = block_ud['membersCount'] + localized_data['members_count'] = self.blockchain_service.current_members_count() - computed_dividend = await self.community.computed_dividend() + computed_dividend = self.blockchain_service.computed_dividend() # display float values - localized_data['ud_plus_1'] = await self.account.current_ref.instance(computed_dividend, - self.community, self.app) \ - .diff_localized(True, self.app.preferences['international_system_of_units']) + localized_data['ud_plus_1'] = await self.app.current_ref.instance(computed_dividend, + self.connection.currency, self.app) \ + .diff_localized(True, self.app.parameters.international_system_of_units) - localized_data['mass'] = await self.account.current_ref.instance(block_ud['monetaryMass'], - self.community, self.app) \ - .diff_localized(True, self.app.preferences['international_system_of_units']) + localized_data['mass'] = await self.app.current_ref.instance(self.blockchain_service.current_mass(), + self.connection.currency, self.app) \ + .diff_localized(True, self.app.parameters.international_system_of_units) localized_data['ud_median_time'] = QLocale.toString( QLocale(), - QDateTime.fromTime_t(block_ud['medianTime']), + QDateTime.fromTime_t(self.blockchain_service.last_ud_time()), QLocale.dateTimeFormat(QLocale(), QLocale.ShortFormat) ) localized_data['next_ud_median_time'] = QLocale.toString( QLocale(), - QDateTime.fromTime_t(block_ud['medianTime'] + params['dt']), + QDateTime.fromTime_t(self.blockchain_service.last_ud_time() + params.dt), QLocale.dateTimeFormat(QLocale(), QLocale.ShortFormat) ) - if block_ud_minus_1: - mass_minus_1 = (float(0) if block_ud['membersCount'] == 0 else - block_ud_minus_1['monetaryMass'] / block_ud['membersCount']) - localized_data['mass_minus_1_per_member'] = await self.account.current_ref.instance(mass_minus_1, - self.community, self.app) \ - .diff_localized(True, self.app.preferences['international_system_of_units']) - localized_data['mass_minus_1'] = await self.account.current_ref.instance(block_ud_minus_1['monetaryMass'], - self.community, self.app) \ - .diff_localized(True, self.app.preferences['international_system_of_units']) + if previous_ud: + mass_minus_1_per_member = (float(0) if previous_ud == 0 else + previous_monetary_mass / previous_members_count) + localized_data['mass_minus_1_per_member'] = await self.app.current_ref.instance(mass_minus_1_per_member, + self.connection.currency, self.app) \ + .diff_localized(True, self.app.parameters.international_system_of_units) + localized_data['mass_minus_1'] = await self.app.current_ref.instance(previous_monetary_mass, + self.connection.currency, self.app) \ + .diff_localized(True, self.app.parameters.international_system_of_units) # avoid divide by zero ! - if block_ud['membersCount'] == 0 or block_ud_minus_1['monetaryMass'] == 0: + if members_count == 0 or previous_members_count == 0: localized_data['actual_growth'] = float(0) else: - localized_data['actual_growth'] = (block_ud['dividend'] * math.pow(10, block_ud['unitbase'])) / ( - block_ud_minus_1['monetaryMass'] / block_ud['membersCount']) + localized_data['actual_growth'] = (last_ud * math.pow(10, last_ud_base)) / ( + previous_monetary_mass / members_count) localized_data['ud_median_time_minus_1'] = QLocale.toString( QLocale(), - QDateTime.fromTime_t(block_ud_minus_1['medianTime']), + QDateTime.fromTime_t(previous_ud_time), QLocale.dateTimeFormat(QLocale(), QLocale.ShortFormat) ) return localized_data async def get_identity_data(self): - amount = await self.app.current_account.amount(self.community) - localized_amount = await self.app.current_account.current_ref.instance(amount, - self.community, self.app).localized( - units=True, - international_system=self.app.preferences['international_system_of_units']) - account_identity = await self.app.current_account.identity(self.community) + amount = self.sources_service.amount(self.connection.pubkey) + localized_amount = await self.app.current_ref.instance(amount, self.connection.currency, self.app)\ + .localized(units=True, + international_system=self.app.parameters.international_system_of_units) + account_identity = await self.app.current_account.identity(self.connection.currency) mstime_remaining_text = self.tr("Expired or never published") outdistanced_text = self.tr("Outdistanced") - requirements = await account_identity.requirements(self.community) + requirements = await account_identity.requirements(self.connection.currency) mstime_remaining = 0 nb_certs = 0 if requirements: @@ -149,13 +148,7 @@ class InformationsModel(ComponentModel): """ Get community parameters """ - # try to request money parameters - try: - params = await self.community.parameters() - except NoPeerAvailable as e: - logging.debug('community parameters error : ' + str(e)) - return None - return params + return self.blockchain_service.parameters() def referentials(self): """ @@ -165,7 +158,7 @@ class InformationsModel(ComponentModel): """ refs_instances = [] for ref_class in Referentials: - refs_instances.append(ref_class(0, self.community, self.app, None)) + refs_instances.append(ref_class(0, self.connection.currency, self.app, None)) return refs_instances def short_currency(self): @@ -173,4 +166,4 @@ class InformationsModel(ComponentModel): Get community currency :return: the community in short currency format """ - return self.community.short_currency \ No newline at end of file + return shortened(self.connection.currency) \ No newline at end of file diff --git a/src/sakia/gui/navigation/informations/view.py b/src/sakia/gui/navigation/informations/view.py index c75957718437ea851fa8b955f5beb4c068e16ac9..9d61cb02a64178b5cb15d60598764157094c5313 100644 --- a/src/sakia/gui/navigation/informations/view.py +++ b/src/sakia/gui/navigation/informations/view.py @@ -186,7 +186,7 @@ class InformationsView(QWidget, Ui_InformationsWidget): def set_money_text(self, params, currency): """ Set text from money parameters - :param dict params: Parameters of the currency + :param sakia.data.entities.BlockchainParameters params: Parameters of the currency :param str currency: The currency """ @@ -204,23 +204,23 @@ class InformationsView(QWidget, Ui_InformationsWidget): <tr><td align="right"><b>{:2.0%}</b></td><td>{:}</td></tr> </table> """).format( - params['c'], - params['dt'] / 86400, + params.c, + params.dt / 86400, self.tr('Fundamental growth (c)'), - params['ud0'], + params.ud0, self.tr('Initial Universal Dividend UD(0) in'), currency, - params['dt'] / 86400, + params.dt / 86400, self.tr('Time period (dt) in days (86400 seconds) between two UD'), - params['medianTimeBlocks'], + params.median_time_blocks, self.tr('Number of blocks used for calculating median time'), - params['avgGenTime'], + params.avg_gen_time, self.tr('The average time in seconds for writing 1 block (wished time)'), - params['dtDiffEval'], + params.dt_diff_eval, self.tr('The number of blocks required to evaluate again PoWMin value'), - params['blocksRot'], + params.blocks_rot, self.tr('The number of previous blocks to check for personalized difficulty'), - params['percentRot'], + params.percent_rot, self.tr('The percent of previous issuers to reach for personalized difficulty') ) ) @@ -228,7 +228,7 @@ class InformationsView(QWidget, Ui_InformationsWidget): def set_wot_text(self, params): """ Set wot text from currency parameters - :param dict parameters: + :param sakia.data.entities.BlockchainParameters params: Parameters of the currency :return: """ @@ -246,19 +246,19 @@ class InformationsView(QWidget, Ui_InformationsWidget): <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> </table> """).format( - params['sigPeriod'] / 86400, + params.sig_period / 86400, self.tr('Minimum delay between 2 certifications (in days)'), - params['sigValidity'] / 86400, + params.sig_validity / 86400, self.tr('Maximum age of a valid signature (in days)'), - params['sigQty'], + params.sig_qty, self.tr('Minimum quantity of signatures to be part of the WoT'), - params['sigStock'], + params.sig_stock, self.tr('Maximum quantity of active certifications made by member.'), - params['sigWindow'], + params.sig_window, self.tr('Maximum delay a certification can wait before being expired for non-writing.'), - params['xpercent'], + params.xpercent, self.tr('Minimum percent of sentries to reach to match the distance rule'), - params['msValidity'] / 86400, + params.ms / 86400, self.tr('Maximum age of a valid membership (in days)'), params['stepMax'], self.tr('Maximum distance between each WoT member and a newcomer'), diff --git a/src/sakia/gui/navigation/model.py b/src/sakia/gui/navigation/model.py index 2947ede00a70b2293a759765100e2cc7127e1718..6725e62e1c5ba1e1fd5d2b9faf412a4c81d8b959 100644 --- a/src/sakia/gui/navigation/model.py +++ b/src/sakia/gui/navigation/model.py @@ -38,36 +38,38 @@ class NavigationModel(ComponentModel): 'title': connection.currency, 'component': "Informations", 'blockchain_service': self.app.blockchain_services[connection.currency], + 'sources_service': self.app.sources_services[connection.currency], + 'connection':connection, }, 'children': [ - { - 'node': { - 'title': self.tr('Transfers'), - 'icon': ':/icons/tx_icon', - 'component': "TxHistory", - } - }, - { - 'node': { - 'title': self.tr('Network'), - 'icon': ':/icons/network_icon', - 'component': "Network", - } - }, - { - 'node': { - 'title': self.tr('Identities'), - 'icon': ':/icons/members_icon', - 'component': "Identities", - } - }, - { - 'node': { - 'title': self.tr('Web of Trust'), - 'icon': ':/icons/wot_icon', - 'component': "Wot", - } - } + # { + # 'node': { + # 'title': self.tr('Transfers'), + # 'icon': ':/icons/tx_icon', + # 'component': "TxHistory", + # } + # }, + # { + # 'node': { + # 'title': self.tr('Network'), + # 'icon': ':/icons/network_icon', + # 'component': "Network", + # } + # }, + # { + # 'node': { + # 'title': self.tr('Identities'), + # 'icon': ':/icons/members_icon', + # 'component': "Identities", + # } + # }, + # { + # 'node': { + # 'title': self.tr('Web of Trust'), + # 'icon': ':/icons/wot_icon', + # 'component': "Wot", + # } + # } ] }) return self.navigation