Skip to content
Snippets Groups Projects
Commit d7f78e1a authored by inso's avatar inso
Browse files

Fixed a bug in history table + versionned cache

parent ddb2361d
Branches
Tags
No related merge requests found
...@@ -9,9 +9,10 @@ import logging ...@@ -9,9 +9,10 @@ import logging
import json import json
import tarfile import tarfile
from cutecoin.core import config from . import config
from cutecoin.tools.exceptions import NameAlreadyExists, BadAccountFile from ..tools.exceptions import NameAlreadyExists, BadAccountFile
from cutecoin.core.account import Account from .account import Account
from .. import __version__
class Application(object): class Application(object):
...@@ -90,7 +91,10 @@ class Application(object): ...@@ -90,7 +91,10 @@ class Application(object):
if os.path.exists(wallet_path): if os.path.exists(wallet_path):
with open(wallet_path, 'r') as json_data: with open(wallet_path, 'r') as json_data:
data = json.load(json_data) data = json.load(json_data)
if 'version' in data and data['version'] == __version__:
wallet.load_caches(data) wallet.load_caches(data)
else:
os.remove(wallet_path)
for community in account.communities: for community in account.communities:
wallet.refresh_cache(community) wallet.refresh_cache(community)
...@@ -112,7 +116,9 @@ class Application(object): ...@@ -112,7 +116,9 @@ class Application(object):
wallet_path = os.path.join(config.parameters['home'], wallet_path = os.path.join(config.parameters['home'],
account.name, '__cache__', wallet.pubkey) account.name, '__cache__', wallet.pubkey)
with open(wallet_path, 'w') as outfile: 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): def import_account(self, file, name):
with tarfile.open(file, "r") as tar: with tarfile.open(file, "r") as tar:
......
...@@ -27,6 +27,7 @@ class Cache(): ...@@ -27,6 +27,7 @@ class Cache():
self.tx_received = [] self.tx_received = []
self.tx_sent = [] self.tx_sent = []
self.awaiting_tx = [] self.awaiting_tx = []
logging.debug(data)
data_received = data['received'] data_received = data['received']
for r in data_received: for r in data_received:
...@@ -164,6 +165,7 @@ class Wallet(object): ...@@ -164,6 +165,7 @@ class Wallet(object):
def load_caches(self, json_data): def load_caches(self, json_data):
for currency in json_data: for currency in json_data:
if currency != 'version':
self.caches[currency] = Cache(self) self.caches[currency] = Cache(self)
self.caches[currency].load_from_json(json_data[currency]) self.caches[currency].load_from_json(json_data[currency])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment