diff --git a/src/cutecoin/core/community.py b/src/cutecoin/core/community.py index 1f83bb477ef084a901100c30f2ae58f42ec7da27..ed478ee669a294130757939d01ab12a43823baeb 100644 --- a/src/cutecoin/core/community.py +++ b/src/cutecoin/core/community.py @@ -112,11 +112,12 @@ class Community(object): block = bma.blockchain.Current(e.conn_handler()).get() self.last_block = {"request_ts": time.time(), "number": block['number']} - elif self.last_block["request_ts"] < time.time() - 300: + elif self.last_block["request_ts"] + 60 < time.time(): + logging.debug("{0} > {1}".format(self.last_block["request_ts"] + 60, time.time())) + self.last_block["request_ts"] = time.time() block = bma.blockchain.Current(e.conn_handler()).get() if block['number'] > self.last_block['number']: - self.last_block = {"request_ts": time.time(), - "number": block['number']} + self.last_block["number"] = block['number'] self.requests_cache = {} cache_key = (hash(request), diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index 21d10fb9685e84edef585acbea8bc921011a819c..888f0e429921a2d60f0843aa3b4ecfd3076322ee 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -59,23 +59,22 @@ class Cache(): 'awaiting': data_awaiting} def latest_sent(self, community): - self._refresh(community) return self.tx_sent def awaiting(self, community): - self._refresh(community) return self.awaiting_tx def latest_received(self, community): - self._refresh(community) return self.tx_received - def _refresh(self, community): + def refresh(self, community): current_block = community.request(bma.blockchain.Current) with_tx = community.request(bma.blockchain.TX) # We parse only blocks with transactions parsed_blocks = reversed(range(self.latest_block + 1, current_block['number'] + 1)) + logging.debug("Refresh from {0} to {1}".format(self.latest_block + 1, + current_block['number'] + 1)) parsed_blocks = [n for n in parsed_blocks if n in with_tx['result']['blocks']] diff --git a/src/cutecoin/gui/certification.py b/src/cutecoin/gui/certification.py index 4a3f4c3c4bd4edc0bb324448940b3dcfc1164159..6d87765d7a1c3d9cc68c88afc01ac5479323c316 100644 --- a/src/cutecoin/gui/certification.py +++ b/src/cutecoin/gui/certification.py @@ -40,6 +40,8 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): pubkey = self.edit_pubkey.text() password = self.password_asker.ask() + if password == "": + return try: self.certifier.certify(password, self.community, pubkey) diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index 26533ba8dbee4408f983bcb202774a49cc2e8912..23c904fefa8a341dc9b176fa9b247daaa098bb0d 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -20,8 +20,9 @@ from ..models.wallet import WalletListModel class BlockchainInspector(QThread): - def __init__(self, community): + def __init__(self, account, community): QThread.__init__(self) + self.account = account self.community = community self.exiting = False self.last_block = self.community.request(bma.blockchain.Current)['number'] @@ -31,10 +32,16 @@ class BlockchainInspector(QThread): self.wait() def run(self): + logging.debug("Runs.") while not self.exiting: + logging.debug("Sleep.") time.sleep(10) current_block = self.community.request(bma.blockchain.Current) + logging.debug("Current block... {0}".format(current_block['number'])) if self.last_block != current_block['number']: + for w in self.account.wallets: + w.cache.refresh(self.community) + logging.debug("New block, {0} mined in {1}".format(self.last_block, self.community.currency)) self.new_block_mined.emit(current_block['number']) @@ -61,9 +68,10 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.tab_community = CommunityTabWidget(self.app.current_account, self.community, self.password_asker) - bc_inspector = BlockchainInspector(community) - bc_inspector.new_block_mined.connect(self.refresh_block) - bc_inspector.start() + self.bc_inspector = BlockchainInspector(self.app.current_account, + community) + self.bc_inspector.new_block_mined.connect(self.refresh_block) + self.bc_inspector.start() def refresh(self): if self.app.current_account is None: @@ -77,12 +85,14 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.list_transactions_received.setModel( ReceivedListModel(self.app.current_account, self.community)) self.tab_community = CommunityTabWidget(self.app.current_account, - self.community, self.password_asker) + self.community, + self.password_asker) 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)) + self.label_current_block.setText("Current Block : {0}" + .format(block_number)) @pyqtSlot(int) def refresh_block(self, block_number): @@ -108,7 +118,9 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): QModelIndex(), QModelIndex(), []) - self.label_current_block.setText("Current Block : {0}".format(block_number)) + + self.label_current_block.setText("Current Block : {0}" + .format(block_number)) def refresh_wallets(self): wallets_list_model = WalletsListModel(self.app.current_account, diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py index f1f97a253a5f9825e59b6a600e6c33d01b5dc752..7f0673d9b42867918e8e860ccfa441259f500b8d 100644 --- a/src/cutecoin/gui/mainwindow.py +++ b/src/cutecoin/gui/mainwindow.py @@ -100,7 +100,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.action_configure_parameters.setEnabled(False) self.action_set_as_default.setEnabled(False) else: - self.action_set_as_default.setEnabled(self.app.current_account.name != self.app.default_account) + self.action_set_as_default.setEnabled(self.app.current_account.name + != self.app.default_account) self.password_asker = PasswordAskerDialog(self.app.current_account) self.menu_contacts.setEnabled(True) self.action_configure_parameters.setEnabled(True) diff --git a/src/cutecoin/gui/transfer.py b/src/cutecoin/gui/transfer.py index 1c952f94d08d770f5c091ea865e3312c749abbbc..146aa4722765beae202f6522be458566474bd473 100644 --- a/src/cutecoin/gui/transfer.py +++ b/src/cutecoin/gui/transfer.py @@ -51,6 +51,8 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): amount = self.spinbox_amount.value() password = self.password_asker.ask() + if password == "": + return try: self.wallet.send_money(self.sender.salt, password, self.community,