diff --git a/res/ui/currency_tab.ui b/res/ui/currency_tab.ui index 8218af48ed277e794265950b98bfee2f45e6fd16..c41d3366ce4f03aa3d1a49733be23aa38b86922e 100644 --- a/res/ui/currency_tab.ui +++ b/res/ui/currency_tab.ui @@ -100,6 +100,13 @@ </layout> </widget> </item> + <item> + <widget class="QLabel" name="label_current_block"> + <property name="text"> + <string/> + </property> + </widget> + </item> </layout> </widget> <resources> diff --git a/src/cutecoin/core/app.py b/src/cutecoin/core/app.py index ea365405cef8b24f5f4197f907bcb6ad58796305..8546bb17dfeba0a18d2de1ada9d595b73c64cc35 100644 --- a/src/cutecoin/core/app.py +++ b/src/cutecoin/core/app.py @@ -121,7 +121,6 @@ class Application(object): tar.getmember(obj) except KeyError: raise BadAccountFile(file) - return tar.extractall(path) account_path = os.path.join(config.parameters['home'], diff --git a/src/cutecoin/core/community.py b/src/cutecoin/core/community.py index f7ec25dd95932df2e8a2be736462614acafd669f..1f83bb477ef084a901100c30f2ae58f42ec7da27 100644 --- a/src/cutecoin/core/community.py +++ b/src/cutecoin/core/community.py @@ -114,9 +114,10 @@ class Community(object): "number": block['number']} elif self.last_block["request_ts"] < time.time() - 300: block = bma.blockchain.Current(e.conn_handler()).get() - self.last_block = {"request_ts": time.time(), - "number": block['number']} - self.requests_cache = {} + if block['number'] > self.last_block['number']: + self.last_block = {"request_ts": time.time(), + "number": block['number']} + self.requests_cache = {} cache_key = (hash(request), hash(tuple(frozenset(sorted(req_args.keys())))), diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index 4d65c372ee2778e03838ff9b49869a5b5d24f154..0d395ec587510aabeecbeefab31dfbccfb7b8f0b 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -91,17 +91,15 @@ class Cache(): in_inputs = [i for i in tx.issuers if i == self.wallet.pubkey] if len(in_inputs) > 0: - logging.debug("TX:{0}".format(tx.compact())) # remove from waiting transactions list the one which were # validated in the blockchain - confirmed_tx = [awaiting for awaiting in self.awaiting_tx - if awaiting.compact() == tx.compact()] - for c in confirmed_tx: - logging.debug("Awaiting:{0}".format(c.compact())) self.awaiting_tx = [awaiting for awaiting in self.awaiting_tx if awaiting.compact() != tx.compact()] self.tx_sent.append(tx) + self.tx_sent = self.tx_sent[:50] + self.tx_received = self.tx_received[:50] + self.latest_block = current_block['number'] diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py index e17f8ae74f5d9fb6092caf4e2e675293824d5a2b..045387904647846942c3be47bdd506ef31b153af 100644 --- a/src/cutecoin/gui/community_tab.py +++ b/src/cutecoin/gui/community_tab.py @@ -59,7 +59,7 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): send_money.triggered.connect(self.send_money_to_member) send_money.setData(member) - certify = QAction("Certify individual", self) + certify = QAction("Certify identity", self) certify.triggered.connect(self.certify_member) certify.setData(member) diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index 46fec4a2e0e139586bacf920219aeaf6821466bd..df6adf0b179d3064633bdad4f33136dede1a0699 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -5,14 +5,15 @@ Created on 2 févr. 2014 ''' import logging +from ucoinpy.api import bma from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication -from PyQt5.QtCore import QModelIndex, Qt +from PyQt5.QtCore import QModelIndex, Qt, pyqtSlot from PyQt5.QtGui import QIcon -from cutecoin.gen_resources.currency_tab_uic import Ui_CurrencyTabWidget -from cutecoin.gui.community_tab import CommunityTabWidget -from cutecoin.models.sent import SentListModel -from cutecoin.models.received import ReceivedListModel -from cutecoin.models.wallets import WalletsListModel +from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget +from .community_tab import CommunityTabWidget +from ..models.sent import SentListModel +from ..models.received import ReceivedListModel +from ..models.wallets import WalletsListModel from ..models.wallet import WalletListModel @@ -30,6 +31,8 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.setupUi(self) self.app = app self.community = community + self.tab_community = CommunityTabWidget(self.app.current_account, + self.community) def refresh(self): if self.app.current_account is None: @@ -42,11 +45,40 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): SentListModel(self.app.current_account, self.community)) self.list_transactions_received.setModel( ReceivedListModel(self.app.current_account, self.community)) - tab_community = CommunityTabWidget(self.app.current_account, + self.tab_community = CommunityTabWidget(self.app.current_account, self.community) - self.tabs_account.addTab(tab_community, + self.tabs_account.addTab(self.tab_community, QIcon(':/icons/community_icon'), "Community") + block_number = self.community.request(bma.blockchain.Current)['number'] + self.label_current_block.setText("Current Block : {0}".format(block_number)) + + @pyqtSlot(int) + def refresh_block(self, block_number): + if self.list_wallet_content.model(): + self.list_wallet_content.model().dataChanged.emit( + QModelIndex(), + QModelIndex(), + []) + if self.list_wallet_content.model(): + self.list_transactions_sent.model().dataChanged.emit( + QModelIndex(), + QModelIndex(), + []) + + if self.list_transactions_received.model(): + self.list_transactions_received.model().dataChanged.emit( + QModelIndex(), + QModelIndex(), + []) + + if self.tab_community.list_community_members.model(): + self.tab_community.list_community_members.model().dataChanged.emit( + QModelIndex(), + QModelIndex(), + []) + + self.label_current_block.setText("Current Block : {0}".format(block_number)) def refresh_wallets(self): wallets_list_model = WalletsListModel(self.app.current_account, @@ -65,7 +97,6 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): model = self.list_wallets.model() if index.row() < model.rowCount(None): wallet = model.wallets[index.row()] - logging.debug(wallet) menu = QMenu(model.data(index, Qt.DisplayRole), self) rename = QAction("Rename", self) diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py index ad505cd28e88a6b884c92f458333de53090d58f9..8add61f6d72d7bab2802a9e74616f82aadbc93d6 100644 --- a/src/cutecoin/gui/mainwindow.py +++ b/src/cutecoin/gui/mainwindow.py @@ -5,7 +5,7 @@ Created on 1 févr. 2014 ''' from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow from PyQt5.QtWidgets import QMainWindow, QAction, QFileDialog -from PyQt5.QtCore import QSignalMapper, QModelIndex +from PyQt5.QtCore import QSignalMapper, QModelIndex, QThread, pyqtSignal from PyQt5.QtGui import QIcon from cutecoin.gui.process_cfg_account import ProcessConfigureAccount from cutecoin.gui.transfer import TransferMoneyDialog @@ -14,7 +14,34 @@ from cutecoin.gui.add_contact import AddContactDialog from cutecoin.gui.import_account import ImportAccountDialog from cutecoin.gui.certification import CertificationDialog +from ucoinpy.api import bma + import logging +import time + + +class BlockchainInspector(QThread): + def __init__(self, community): + QThread.__init__(self) + self.community = community + self.exiting = False + self.last_block = self.community.request(bma.blockchain.Current)['number'] + + def __del__(self): + self.exiting = True + self.wait() + + def run(self): + while not self.exiting: + time.sleep(10) + current_block = self.community.request(bma.blockchain.Current) + if self.last_block != current_block['number']: + logging.debug("New block, {0} mined in {1}".format(self.last_block, + self.community.currency)) + self.new_block_mined.emit(current_block) + self.last_block = current_block['number'] + + new_block_mined = pyqtSignal(int) class MainWindow(QMainWindow, Ui_MainWindow): @@ -97,6 +124,9 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.currencies_tabwidget.clear() for community in self.app.current_account.communities: tab_currency = CurrencyTabWidget(self.app, community) + bc_inspector = BlockchainInspector(community) + bc_inspector.new_block_mined.connect(tab_currency.refresh_block) + bc_inspector.start() tab_currency.refresh() self.currencies_tabwidget.addTab(tab_currency, QIcon(":/icons/currency_icon"),