From d7f78e1a6b2fc08c780e8701f7958ad37107474e Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Sat, 31 Jan 2015 11:52:21 +0100 Subject: [PATCH] Fixed a bug in history table + versionned cache --- src/cutecoin/core/app.py | 16 +++++++++++----- src/cutecoin/core/wallet.py | 6 ++++-- src/cutecoin/gui/currency_tab.py | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/cutecoin/core/app.py b/src/cutecoin/core/app.py index e351f3ef..16aaab65 100644 --- a/src/cutecoin/core/app.py +++ b/src/cutecoin/core/app.py @@ -9,9 +9,10 @@ import logging import json import tarfile -from cutecoin.core import config -from cutecoin.tools.exceptions import NameAlreadyExists, BadAccountFile -from cutecoin.core.account import Account +from . import config +from ..tools.exceptions import NameAlreadyExists, BadAccountFile +from .account import Account +from .. import __version__ class Application(object): @@ -90,7 +91,10 @@ class Application(object): if os.path.exists(wallet_path): with open(wallet_path, 'r') as json_data: data = json.load(json_data) - wallet.load_caches(data) + if 'version' in data and data['version'] == __version__: + wallet.load_caches(data) + else: + os.remove(wallet_path) for community in account.communities: wallet.refresh_cache(community) @@ -112,7 +116,9 @@ class Application(object): wallet_path = os.path.join(config.parameters['home'], account.name, '__cache__', wallet.pubkey) with open(wallet_path, 'w') as outfile: - json.dump(wallet.jsonify_caches(), outfile, indent=4, sort_keys=True) + data = wallet.jsonify_caches() + data['version'] = __version__ + json.dump(data, outfile, indent=4, sort_keys=True) def import_account(self, file, name): with tarfile.open(file, "r") as tar: diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index 785fa332..87121814 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -27,6 +27,7 @@ class Cache(): self.tx_received = [] self.tx_sent = [] self.awaiting_tx = [] + logging.debug(data) data_received = data['received'] for r in data_received: @@ -164,8 +165,9 @@ class Wallet(object): def load_caches(self, json_data): for currency in json_data: - self.caches[currency] = Cache(self) - self.caches[currency].load_from_json(json_data[currency]) + if currency != 'version': + self.caches[currency] = Cache(self) + self.caches[currency].load_from_json(json_data[currency]) def jsonify_caches(self): data = {} diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index d26eb081..5fa02a66 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -208,7 +208,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): copy_pubkey.triggered.connect(self.copy_pubkey_to_clipboard) copy_pubkey.setData(person) - menu.addAction(copy_pubkey) + menu.addAction(copy_pubkey) # Show the context menu. menu.exec_(self.table_history.mapToGlobal(point)) -- GitLab