From deefd74c3751d1f7e84dbdfe6812db460f7124d5 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Tue, 1 Dec 2015 17:29:24 +0100 Subject: [PATCH] labels sync for kivy --- gui/kivy/main_window.py | 1 + lib/plugins.py | 6 ------ plugins/labels/kivy.py | 13 ++++++++++++- plugins/labels/labels.py | 19 +++++++++++++++---- plugins/labels/qt.py | 16 +--------------- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py index d31490adf..063c1680d 100644 --- a/gui/kivy/main_window.py +++ b/gui/kivy/main_window.py @@ -404,6 +404,7 @@ class ElectrumWindow(App): # since the callback has been called before the GUI was initialized self.update_history_tab() self.notify_transactions() + run_hook('load_wallet', wallet, self) def update_status(self, *dt): if not self.wallet: diff --git a/lib/plugins.py b/lib/plugins.py index 90ba13d87..c544440bb 100644 --- a/lib/plugins.py +++ b/lib/plugins.py @@ -194,12 +194,6 @@ class BasePlugin(PrintError): def thread_jobs(self): return [] - @hook - def load_wallet(self, wallet, window): pass - - @hook - def close_wallet(self): pass - def is_enabled(self): return self.is_available() and self.config.get('use_'+self.name) is True diff --git a/plugins/labels/kivy.py b/plugins/labels/kivy.py index d548bda7d..2bdc78891 100644 --- a/plugins/labels/kivy.py +++ b/plugins/labels/kivy.py @@ -1,3 +1,14 @@ from labels import LabelsPlugin +from electrum.plugins import hook + class Plugin(LabelsPlugin): - pass + + @hook + def load_wallet(self, wallet, window): + self.window = window + self.start_wallet(wallet) + + def on_pulled(self, wallet): + self.print_error('on pulled') + self.window.update_history_tab() + diff --git a/plugins/labels/labels.py b/plugins/labels/labels.py index 1619b7381..28a51b716 100644 --- a/plugins/labels/labels.py +++ b/plugins/labels/labels.py @@ -1,3 +1,4 @@ +import hashlib import requests import threading import json @@ -132,7 +133,17 @@ class LabelsPlugin(BasePlugin): traceback.print_exc(file=sys.stderr) self.print_error("could not retrieve labels") - - - - + def start_wallet(self, wallet): + nonce = self.get_nonce(wallet) + self.print_error("wallet", wallet.basename(), "nonce is", nonce) + mpk = ''.join(sorted(wallet.get_master_public_keys().values())) + if not mpk: + return + password = hashlib.sha1(mpk).digest().encode('hex')[:32] + iv = hashlib.sha256(password).digest()[:16] + wallet_id = hashlib.sha256(mpk).digest().encode('hex') + self.wallets[wallet] = (password, iv, wallet_id) + # If there is an auth token we can try to actually start syncing + t = threading.Thread(target=self.pull_thread, args=(wallet, False)) + t.setDaemon(True) + t.start() diff --git a/plugins/labels/qt.py b/plugins/labels/qt.py index 582468144..728f57e62 100644 --- a/plugins/labels/qt.py +++ b/plugins/labels/qt.py @@ -1,4 +1,3 @@ -import hashlib import threading from functools import partial @@ -59,20 +58,7 @@ class Plugin(LabelsPlugin): @hook def on_new_window(self, window): window.connect(window.app, SIGNAL('labels_changed'), window.update_tabs) - wallet = window.wallet - nonce = self.get_nonce(wallet) - self.print_error("wallet", wallet.basename(), "nonce is", nonce) - mpk = ''.join(sorted(wallet.get_master_public_keys().values())) - if not mpk: - return - password = hashlib.sha1(mpk).digest().encode('hex')[:32] - iv = hashlib.sha256(password).digest()[:16] - wallet_id = hashlib.sha256(mpk).digest().encode('hex') - self.wallets[wallet] = (password, iv, wallet_id) - # If there is an auth token we can try to actually start syncing - t = threading.Thread(target=self.pull_thread, args=(wallet, False)) - t.setDaemon(True) - t.start() + self.start_wallet(window.wallet) @hook def on_close_window(self, window):