diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py index eb6ae82250caafc9b395a02cd43c102eda264100..25d89b89632983f006ee23729771957992ff1436 100644 --- a/src/cutecoin/core/account.py +++ b/src/cutecoin/core/account.py @@ -113,12 +113,18 @@ class Account(object): def certify(self, password, community, pubkey): certified = Person.lookup(pubkey, community) - block = community.get_block() - block_hash = hashlib.sha1(block.signed_raw().encode("ascii")).hexdigest().upper() + + try: + block = community.get_block() + block_number = block.number + block_hash = hashlib.sha1(block.signed_raw().encode("ascii")).hexdigest().upper() + except ValueError as e: + block_number = 0 + block_hash = "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709" certification = Certification(PROTOCOL_VERSION, community.currency, self.pubkey, certified.pubkey, - block_hash, block.number, None) + block_hash, block_number, None) selfcert = certified.selfcert(community) logging.debug("SelfCertification : {0}".format(selfcert.raw())) @@ -202,10 +208,11 @@ class Account(object): try: block = community.get_block() block_hash = hashlib.sha1(block.signed_raw().encode("ascii")).hexdigest().upper() - block_number = block['number'] + block_number = block.number except ValueError as e: block_number = 0 block_hash = "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709" + membership = Membership(PROTOCOL_VERSION, community.currency, selfcert.pubkey, block_number, block_hash, type, selfcert.uid, diff --git a/src/cutecoin/core/community.py b/src/cutecoin/core/community.py index 7f38061cb69bc13c2bed374b303bd1c60d5cc788..b1fce9fd625d38117c8a79ac192944cb1dfef7cc 100644 --- a/src/cutecoin/core/community.py +++ b/src/cutecoin/core/community.py @@ -126,12 +126,11 @@ class Community(object): def request(self, request, req_args={}, get_args={}, cached=True): for peer in self.peers: e = next(e for e in peer.endpoints if type(e) is BMAEndpoint) - if cached: + self.check_current_block(e) + if cached and self.last_block["number"] != 0: try: # We request the current block every five minutes # If a new block is mined we reset the cache - - self.check_current_block(e) cache_key = (hash(request), hash(tuple(frozenset(sorted(req_args.keys())))), hash(tuple(frozenset(sorted(req_args.items())))), diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index 27afe43765f5d9d8228819d17cc6513e39f0db98..3c48bf67c1442aa2cdf88d2f3d3528487f21eb1e 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -167,8 +167,10 @@ class Wallet(object): self.caches[currency].load_from_json(json_data[currency]) def jsonify_caches(self): + data = {} for currency in self.caches: - return {currency: self.caches[currency].jsonify()} + data[currency] = self.caches[currency].jsonify() + return data def refresh_cache(self, community): if community.currency not in self.caches: diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py index 09ebb8adb0443c5e920547619bdf072add9e70e5..153d0584328319a816fc9f5eee26bf6f122f2734 100644 --- a/src/cutecoin/gui/community_tab.py +++ b/src/cutecoin/gui/community_tab.py @@ -104,7 +104,7 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): self.account.send_membership(password, self.community, 'IN') except ValueError as e: QMessageBox.critical(self, "Join demand error", - e.message) + str(e)) except PersonNotFoundError as e: QMessageBox.critical(self, "Key not sent to community", "Your key wasn't sent in the community. \ diff --git a/src/cutecoin/gui/process_cfg_account.py b/src/cutecoin/gui/process_cfg_account.py index e5b0210887e989057e6ef4e53ae2a0fe23f4c59a..8843f1c874189de0c07eff095d2edcabbb34eb63 100644 --- a/src/cutecoin/gui/process_cfg_account.py +++ b/src/cutecoin/gui/process_cfg_account.py @@ -200,7 +200,7 @@ class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog): def open_process_edit_community(self, index): community = self.account.communities[index.row()] - dialog = ProcessConfigureCommunity(self.account, community) + dialog = ProcessConfigureCommunity(self.account, community, self.password_asker) dialog.accepted.connect(self.action_edit_community) dialog.exec_() diff --git a/src/cutecoin/gui/transfer.py b/src/cutecoin/gui/transfer.py index 9e2497016f278a2f83242a617f7c1aa7c6563639..c903e5ed7b01f66dedfdaefcf5275aa324eeb783 100644 --- a/src/cutecoin/gui/transfer.py +++ b/src/cutecoin/gui/transfer.py @@ -3,7 +3,7 @@ Created on 2 févr. 2014 @author: inso ''' -from PyQt5.QtWidgets import QDialog, QErrorMessage, QInputDialog, QLineEdit, QMessageBox +from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QMessageBox from ..tools.exceptions import NotEnoughMoneyError from ..core.person import Person @@ -41,6 +41,11 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): for contact in sender.contacts: self.combo_contact.addItem(contact.name) + if len(self.sender.contacts) == 0: + self.combo_contact.setEnabled(False) + self.radio_contact.setEnabled(False) + self.radio_pubkey.setChecked(True) + def accept(self): comment = self.edit_message.text() @@ -94,13 +99,19 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): self.label_total.setText(self.wallet.get_text(self.community)) self.spinbox_amount.setSuffix(" " + self.community.currency) self.spinbox_amount.setValue(0) - self.spinbox_amount.setMaximum(self.wallet.value(self.community)) + amount = self.wallet.value(self.community) + relative = amount / self.dividend + self.spinbox_amount.setMaximum(amount) + self.spinbox_relative.setMaximum(relative) def change_displayed_wallet(self, index): self.wallet = self.sender.wallets[index] self.label_total.setText(self.wallet.get_text(self.community)) self.spinbox_amount.setValue(0) - self.spinbox_amount.setMaximum(self.wallet.value(self.community)) + amount = self.wallet.value(self.community) + relative = amount / self.dividend + self.spinbox_amount.setMaximum(amount) + self.spinbox_relative.setMaximum(relative) def recipient_mode_changed(self, pubkey_toggled): self.edit_pubkey.setEnabled(pubkey_toggled)