mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 01:11:35 +00:00
Hopefully fix label corruption.
This commit is contained in:
parent
c503a97c83
commit
7f37c093b6
1 changed files with 58 additions and 46 deletions
|
@ -1,6 +1,7 @@
|
||||||
from electrum.util import print_error
|
from electrum.util import print_error
|
||||||
from electrum_gui.i18n import _
|
from electrum_gui.i18n import _
|
||||||
import httplib, urllib
|
import httplib, urllib
|
||||||
|
import socket
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
from urlparse import urlparse, parse_qs
|
from urlparse import urlparse, parse_qs
|
||||||
|
@ -21,7 +22,7 @@ from electrum_gui.gui_classic import HelpButton
|
||||||
|
|
||||||
class Plugin(BasePlugin):
|
class Plugin(BasePlugin):
|
||||||
def version(self):
|
def version(self):
|
||||||
return "0.2"
|
return "0.2.1"
|
||||||
|
|
||||||
def encode(self, message):
|
def encode(self, message):
|
||||||
encrypted = aes.encryptData(self.encode_password, unicode(message))
|
encrypted = aes.encryptData(self.encode_password, unicode(message))
|
||||||
|
@ -73,16 +74,19 @@ To get started visit http://labelectrum.herokuapp.com/ to sign up for an account
|
||||||
def set_label(self, item,label, changed):
|
def set_label(self, item,label, changed):
|
||||||
if not changed:
|
if not changed:
|
||||||
return
|
return
|
||||||
|
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'})
|
||||||
|
|
||||||
bundle = {"label": {"external_id": self.encode(item), "text": self.encode(label)}}
|
response = connection.getresponse()
|
||||||
params = json.dumps(bundle)
|
if response.reason == httplib.responses[httplib.NOT_FOUND]:
|
||||||
connection = httplib.HTTPConnection(self.target_host)
|
return
|
||||||
connection.request("POST", ("/api/wallets/%s/labels.json?auth_token=%s" % (self.wallet_id, self.auth_token())), params, {'Content-Type': 'application/json'})
|
response = json.loads(response.read())
|
||||||
|
except socket.gaierror as e:
|
||||||
response = connection.getresponse()
|
print_error('Error connecting to service: %s ' % e)
|
||||||
if response.reason == httplib.responses[httplib.NOT_FOUND]:
|
return False
|
||||||
return
|
|
||||||
response = json.loads(response.read())
|
|
||||||
|
|
||||||
def settings_dialog(self):
|
def settings_dialog(self):
|
||||||
def check_for_api_key(api_key):
|
def check_for_api_key(api_key):
|
||||||
|
@ -163,47 +167,55 @@ To get started visit http://labelectrum.herokuapp.com/ to sign up for an account
|
||||||
self.gui.update_contacts_tab()
|
self.gui.update_contacts_tab()
|
||||||
|
|
||||||
def do_full_push(self):
|
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:
|
try:
|
||||||
response = json.loads(response.read())
|
bundle = {"labels": {}}
|
||||||
except ValueError as e:
|
for key, value in self.labels.iteritems():
|
||||||
return False
|
encoded = self.encode(key)
|
||||||
|
bundle["labels"][encoded] = self.encode(value)
|
||||||
|
|
||||||
if "error" in response:
|
params = json.dumps(bundle)
|
||||||
QMessageBox.warning(None, _("Error"),_("Could not sync labels: %s" % response["error"]))
|
connection = httplib.HTTPConnection(self.target_host)
|
||||||
return False
|
connection.request("POST", ("/api/wallets/%s/labels/batch.json?auth_token=%s" % (self.wallet_id, self.auth_token())), params, {'Content-Type': 'application/json'})
|
||||||
|
|
||||||
return True
|
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
|
||||||
|
|
||||||
def do_full_pull(self, force = False):
|
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:
|
try:
|
||||||
response = json.loads(response.read())
|
connection = httplib.HTTPConnection(self.target_host)
|
||||||
except ValueError as e:
|
connection.request("GET", ("/api/wallets/%s/labels.json?auth_token=%s" % (self.wallet_id, self.auth_token())),"", {'Content-Type': 'application/json'})
|
||||||
return False
|
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:
|
if "error" in response:
|
||||||
QMessageBox.warning(None, _("Error"),_("Could not sync labels: %s" % response["error"]))
|
QMessageBox.warning(None, _("Error"),_("Could not sync labels: %s" % response["error"]))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for label in response:
|
for label in response:
|
||||||
decoded_key = self.decode(label["external_id"])
|
decoded_key = self.decode(label["external_id"])
|
||||||
decoded_label = self.decode(label["text"])
|
decoded_label = self.decode(label["text"])
|
||||||
if force or not self.labels.get(decoded_key):
|
if force or not self.labels.get(decoded_key):
|
||||||
self.labels[decoded_key] = decoded_label
|
self.labels[decoded_key] = decoded_label
|
||||||
return True
|
return True
|
||||||
|
except socket.gaierror as e:
|
||||||
|
print_error('Error connecting to service: %s ' % e)
|
||||||
|
return False
|
||||||
|
|
Loading…
Add table
Reference in a new issue