from electrum.util import print_error
-from electrum_gui.i18n import _
+
import httplib, urllib
+import socket
import hashlib
import json
from urlparse import urlparse, parse_qs
import PyQt4.QtGui as QtGui
import aes
import base64
-from electrum_gui import bmp, pyqrnative, BasePlugin
-from electrum_gui.i18n import _
+from electrum import bmp, pyqrnative
+from electrum.plugins import BasePlugin
+from electrum.i18n import _
+
from electrum_gui.gui_classic import HelpButton
class Plugin(BasePlugin):
+
+ def fullname(self):
+ return _('Label Sync')
+
+ def description(self):
+ return '%s\n\n%s%s%s' % (_("This plugin can sync your labels across multiple Electrum installs by using a remote database to save your data. Labels, transactions and addresses are all sent and stored encrypted on the remote server. This code might increase the load of your wallet with a few microseconds as it will sync labels on each startup."), _("To get started visit"), " http://labelectrum.herokuapp.com/ ", _(" to sign up for an account."))
+
def version(self):
- return "0.2"
+ return "0.2.1"
def encode(self, message):
encrypted = aes.encryptData(self.encode_password, unicode(message))
return decoded_message
- def __init__(self, gui):
- self.target_host = 'labelectrum.herokuapp.com'
- BasePlugin.__init__(self, gui, 'labels', _('Label Sync'),_('This plugin can sync your labels accross multiple Electrum installs by using a remote database to save your data. 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.\n\n\
-To get started visit http://labelectrum.herokuapp.com/ to sign up for an account.'))
- self.wallet = gui.wallet
- self.gui = gui
- self.config = gui.config
+ def init(self):
+ self.target_host = 'labelectrum.herokuapp.com'
+ self.wallet = self.gui.wallet
self.labels = self.wallet.labels
self.transactions = self.wallet.transactions
- self.encode_password = hashlib.sha1(self.config.get("master_public_key")).digest().encode('hex')[:32]
-
- self.wallet_id = hashlib.sha256(str(self.config.get("master_public_key"))).digest().encode('hex')
+ mpk = self.wallet.master_public_keys["m/0'/"][1]
+ self.encode_password = hashlib.sha1(mpk).digest().encode('hex')[:32]
+ self.wallet_id = hashlib.sha256(mpk).digest().encode('hex')
addresses = []
- for k, account in self.wallet.accounts.items():
- for address in account[0]:
+ for account in self.wallet.accounts.values():
+ for address in account.get_addresses(0):
addresses.append(address)
self.addresses = addresses
- def auth_token(self):
- return self.config.get("plugin_label_api_key")
-
- def init_gui(self):
- if self.is_enabled() and self.auth_token():
+ if self.auth_token():
# If there is an auth token we can try to actually start syncing
self.full_pull()
+ def auth_token(self):
+ return self.config.get("plugin_label_api_key")
+
def is_available(self):
return True
def set_label(self, item,label, changed):
if not changed:
return
-
- bundle = {"label": {"external_id": self.encode(item), "text": self.encode(label)}}
- params = json.dumps(bundle)
- connection = httplib.HTTPConnection(self.target_host)
- connection.request("POST", ("/api/wallets/%s/labels.json?auth_token=%s" % (self.wallet_id, self.auth_token())), params, {'Content-Type': 'application/json'})
-
- response = connection.getresponse()
- if response.reason == httplib.responses[httplib.NOT_FOUND]:
- return
- response = json.loads(response.read())
+ try:
+ bundle = {"label": {"external_id": self.encode(item), "text": self.encode(label)}}
+ params = json.dumps(bundle)
+ connection = httplib.HTTPConnection(self.target_host)
+ connection.request("POST", ("/api/wallets/%s/labels.json?auth_token=%s" % (self.wallet_id, self.auth_token())), params, {'Content-Type': 'application/json'})
+
+ response = connection.getresponse()
+ if response.reason == httplib.responses[httplib.NOT_FOUND]:
+ return
+ response = json.loads(response.read())
+ except socket.gaierror as e:
+ print_error('Error connecting to service: %s ' % e)
+ return False
def settings_dialog(self):
def check_for_api_key(api_key):
else:
return False
- def toggle(self):
- enabled = not self.is_enabled()
- self.set_enabled(enabled)
- self.init_gui()
-
- if not self.auth_token() and enabled: # First run, throw plugin settings in your face
+ def enable(self):
+ if not self.auth_token(): # First run, throw plugin settings in your face
+ self.init()
if self.settings_dialog():
- self.set_enabled(True)
- return True
+ self.set_enabled(True)
+ return True
else:
- self.set_enabled(False)
- return False
+ self.set_enabled(False)
+ return False
return enabled
def full_push(self):
self.gui.update_contacts_tab()
def do_full_push(self):
- bundle = {"labels": {}}
- for key, value in self.labels.iteritems():
- encoded = self.encode(key)
- bundle["labels"][encoded] = self.encode(value)
-
- params = json.dumps(bundle)
- connection = httplib.HTTPConnection(self.target_host)
- connection.request("POST", ("/api/wallets/%s/labels/batch.json?auth_token=%s" % (self.wallet_id, self.auth_token())), params, {'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:
- return False
-
- if "error" in response:
- QMessageBox.warning(None, _("Error"),_("Could not sync labels: %s" % response["error"]))
+ bundle = {"labels": {}}
+ for key, value in self.labels.iteritems():
+ encoded = self.encode(key)
+ bundle["labels"][encoded] = self.encode(value)
+
+ params = json.dumps(bundle)
+ connection = httplib.HTTPConnection(self.target_host)
+ connection.request("POST", ("/api/wallets/%s/labels/batch.json?auth_token=%s" % (self.wallet_id, self.auth_token())), params, {'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:
+ return False
+
+ if "error" in response:
+ QMessageBox.warning(None, _("Error"),_("Could not sync labels: %s" % response["error"]))
+ return False
+
+ return True
+ except socket.gaierror as e:
+ print_error('Error connecting to service: %s ' % e)
return False
- return True
-
def do_full_pull(self, force = False):
- connection = httplib.HTTPConnection(self.target_host)
- connection.request("GET", ("/api/wallets/%s/labels.json?auth_token=%s" % (self.wallet_id, self.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:
+ connection = httplib.HTTPConnection(self.target_host)
+ connection.request("GET", ("/api/wallets/%s/labels.json?auth_token=%s" % (self.wallet_id, self.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:
+ return False
+
+ if "error" in response:
+ QMessageBox.warning(None, _("Error"),_("Could not sync labels: %s" % response["error"]))
+ return False
+
+ for label in response:
+ decoded_key = self.decode(label["external_id"])
+ decoded_label = self.decode(label["text"])
+ if force or not self.labels.get(decoded_key):
+ self.labels[decoded_key] = decoded_label
+ return True
+ except socket.gaierror as e:
+ print_error('Error connecting to service: %s ' % e)
return False
-
- if "error" in response:
- QMessageBox.warning(None, _("Error"),_("Could not sync labels: %s" % response["error"]))
- return False
-
- for label in response:
- decoded_key = self.decode(label["external_id"])
- decoded_label = self.decode(label["text"])
- if force or not self.labels.get(decoded_key):
- self.labels[decoded_key] = decoded_label
- return True