labels plugin: use self.print_error
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
from electrum.util import print_error
|
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import requests
|
import requests
|
||||||
import threading
|
import threading
|
||||||
@@ -49,7 +47,7 @@ class Plugin(BasePlugin):
|
|||||||
return decoded_message
|
return decoded_message
|
||||||
|
|
||||||
def set_nonce(self, nonce):
|
def set_nonce(self, nonce):
|
||||||
print_error("Set nonce to", nonce)
|
self.print_error("Set nonce to", nonce)
|
||||||
self.wallet.storage.put("wallet_nonce", nonce, True)
|
self.wallet.storage.put("wallet_nonce", nonce, True)
|
||||||
self.wallet_nonce = nonce
|
self.wallet_nonce = nonce
|
||||||
|
|
||||||
@@ -63,7 +61,7 @@ class Plugin(BasePlugin):
|
|||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
|
|
||||||
self.wallet_nonce = self.wallet.storage.get("wallet_nonce")
|
self.wallet_nonce = self.wallet.storage.get("wallet_nonce")
|
||||||
print_error("Wallet nonce is", self.wallet_nonce)
|
self.print_error("Wallet nonce is", self.wallet_nonce)
|
||||||
if self.wallet_nonce is None:
|
if self.wallet_nonce is None:
|
||||||
self.set_nonce(1)
|
self.set_nonce(1)
|
||||||
|
|
||||||
@@ -84,7 +82,7 @@ class Plugin(BasePlugin):
|
|||||||
try:
|
try:
|
||||||
self.pull_thread()
|
self.pull_thread()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print_error("could not retrieve labels:", e)
|
self.print_error("could not retrieve labels:", e)
|
||||||
t = threading.Thread(target=do_pull_thread)
|
t = threading.Thread(target=do_pull_thread)
|
||||||
t.setDaemon(True)
|
t.setDaemon(True)
|
||||||
t.start()
|
t.start()
|
||||||
@@ -163,18 +161,14 @@ class Plugin(BasePlugin):
|
|||||||
encoded_key = self.encode(key)
|
encoded_key = self.encode(key)
|
||||||
encoded_value = self.encode(value)
|
encoded_value = self.encode(value)
|
||||||
except:
|
except:
|
||||||
print_error('cannot encode', repr(key), repr(value))
|
self.print_error('cannot encode', repr(key), repr(value))
|
||||||
continue
|
continue
|
||||||
bundle["labels"].append({'encryptedLabel': encoded_value, 'externalId': encoded_key})
|
bundle["labels"].append({'encryptedLabel': encoded_value, 'externalId': encoded_key})
|
||||||
self.do_request("POST", "/labels", True, bundle)
|
self.do_request("POST", "/labels", True, bundle)
|
||||||
|
|
||||||
def pull_thread(self, force = False):
|
def pull_thread(self, force = False):
|
||||||
if force:
|
wallet_nonce = 1 if force else self.wallet_nonce - 1
|
||||||
wallet_nonce = 1
|
self.print_error("Asking for labels since nonce", wallet_nonce)
|
||||||
else:
|
|
||||||
wallet_nonce = self.wallet_nonce - 1
|
|
||||||
|
|
||||||
print_error("Asking for labels since nonce", wallet_nonce)
|
|
||||||
response = self.do_request("GET", ("/labels/since/%d/for/%s" % (wallet_nonce, self.wallet_id) ))
|
response = self.do_request("GET", ("/labels/since/%d/for/%s" % (wallet_nonce, self.wallet_id) ))
|
||||||
result = {}
|
result = {}
|
||||||
if not response["labels"] is None:
|
if not response["labels"] is None:
|
||||||
@@ -188,7 +182,7 @@ class Plugin(BasePlugin):
|
|||||||
json.dumps(key)
|
json.dumps(key)
|
||||||
json.dumps(value)
|
json.dumps(value)
|
||||||
except:
|
except:
|
||||||
print_error('error: no json', key)
|
self.print_error('error: no json', key)
|
||||||
continue
|
continue
|
||||||
result[key] = value
|
result[key] = value
|
||||||
|
|
||||||
@@ -201,4 +195,4 @@ class Plugin(BasePlugin):
|
|||||||
|
|
||||||
self.window.emit(SIGNAL('labels:pulled'))
|
self.window.emit(SIGNAL('labels:pulled'))
|
||||||
self.set_nonce(response["nonce"] + 1)
|
self.set_nonce(response["nonce"] + 1)
|
||||||
print_error("received %d labels"%len(response))
|
self.print_error("received %d labels"%len(response))
|
||||||
|
|||||||
Reference in New Issue
Block a user