From 2973f5d2c3ec7de9cc638886f5614c6494116d00 Mon Sep 17 00:00:00 2001 From: Maran Date: Sun, 10 Mar 2013 18:14:21 +0100 Subject: [PATCH] more label sync wip --- lib/simple_config.py | 1 - plugins/labels.py | 25 ++++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/simple_config.py b/lib/simple_config.py index 8927b2879..68fb71945 100644 --- a/lib/simple_config.py +++ b/lib/simple_config.py @@ -151,7 +151,6 @@ a SimpleConfig instance then reads the wallet file. except ConfigParser.NoSectionError: pass - def init_path(self, path): """Set the path of the wallet.""" diff --git a/plugins/labels.py b/plugins/labels.py index 6ccd62ffa..6d0b17c5e 100644 --- a/plugins/labels.py +++ b/plugins/labels.py @@ -14,9 +14,16 @@ import PyQt4.QtCore as QtCore import PyQt4.QtGui as QtGui target_host = 'labelectrum.herokuapp.com' -auth_token = 'naFniLDwQpHzoMkpwB8H' def init(gui): + """If you want to give this a spin create a account at the target_host url and put it in your user dir config + file with the label_api_key.""" + + global auth_token + auth_token = gui.config.get("label_api_key") + if not auth_token: + return + cloud_wallet = CloudWallet(gui.wallet) gui.set_hook('create_settings_tab', add_settings_tab) gui.set_hook('label_changed', label_changed) @@ -32,7 +39,8 @@ def label_changed(gui,item,label): bundle = {"label": {"external_id": hashed, "text": label}} params = json.dumps(bundle) connection = httplib.HTTPConnection(target_host) - connection.request("POST", ("/api/wallets/%s/labels.json?auth_token=%s" % (wallet_id(gui.wallet), auth_token)), params, {'Content-Type': 'application/json'}) + wallet = wallet_id(gui.wallet) + connection.request("POST", ("/api/wallets/%s/labels.json?auth_token=%s" % (wallet, auth_token)), params, {'Content-Type': 'application/json'}) response = connection.getresponse() if response.reason == httplib.responses[httplib.NOT_FOUND]: @@ -43,7 +51,7 @@ def add_settings_tab(gui, tabs): cloud_tab = QWidget() layout = QGridLayout(cloud_tab) layout.addWidget(QLabel("API Key: "),0,0) - layout.addWidget(QLineEdit("jEnsNBb5fAR5rYSBNYnR"), 0,2) + layout.addWidget(QLineEdit(auth_token), 0,2) layout.addWidget(QLabel("Label sync options: "),1,0) @@ -64,14 +72,14 @@ def full_push(wallet): def full_pull(wallet): cloud_wallet = CloudWallet(wallet) - cloud_wallet.full_pull() + cloud_wallet.full_pull(True) print "Labels pulled, please restart your client" def show(): print 'showing' def get_info(): - return 'Label sync', "Syncs your labels with LabElectrum. Labels are not encrypted, transactions and addresses are however." + return 'Label sync', "Syncs your labels with LabElectrum. Labels are not encrypted, transactions and addresses are however. This code might increase the load of your wallet with a few micoseconds as it will sync labels on each startup." def is_enabled(): return True @@ -94,14 +102,13 @@ class CloudWallet(): self.addresses = addresses - def full_pull(self): + def full_pull(self, force = False): global target_host, auth_token connection = httplib.HTTPConnection(target_host) connection.request("GET", ("/api/wallets/%s/labels.json?auth_token=%s" % (self.mpk, auth_token)),"", {'Content-Type': 'application/json'}) response = connection.getresponse() if response.reason == httplib.responses[httplib.NOT_FOUND]: return - try: response = json.loads(response.read()) except ValueError as e: @@ -111,12 +118,12 @@ class CloudWallet(): for key in self.addresses: target_hashed = hashlib.sha256(key).digest().encode('hex') if label["external_id"] == target_hashed: - if not self.labels.get(key): + if force or not self.labels.get(key): self.labels[key] = label["text"] for key, value in self.transactions.iteritems(): target_hashed = hashlib.sha256(key).digest().encode('hex') if label["external_id"] == target_hashed: - if not self.labels.get(key): + if force or not self.labels.get(key): self.labels[key] = label["text"] def full_push(self):