Merge pull request #650 from wozz/URI-bug
Bitcoin URL Handling closes #649
This commit is contained in:
commit
4a79769af4
|
@ -948,7 +948,11 @@ class ElectrumWindow(QMainWindow):
|
||||||
|
|
||||||
|
|
||||||
def set_url(self, url):
|
def set_url(self, url):
|
||||||
address, amount, label, message, signature, identity, url = util.parse_url(url)
|
try:
|
||||||
|
address, amount, label, message, signature, identity, url = util.parse_url(url)
|
||||||
|
except Exception:
|
||||||
|
QMessageBox.warning(self, _('Error'), _('Invalid bitcoin URL'), _('OK'))
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if amount and self.base_unit() == 'mBTC': amount = str( 1000* Decimal(amount))
|
if amount and self.base_unit() == 'mBTC': amount = str( 1000* Decimal(amount))
|
||||||
|
|
47
lib/util.py
47
lib/util.py
|
@ -8,7 +8,7 @@ is_verbose = False
|
||||||
class MyEncoder(json.JSONEncoder):
|
class MyEncoder(json.JSONEncoder):
|
||||||
def default(self, obj):
|
def default(self, obj):
|
||||||
from transaction import Transaction
|
from transaction import Transaction
|
||||||
if isinstance(obj, Transaction):
|
if isinstance(obj, Transaction):
|
||||||
return obj.as_dict()
|
return obj.as_dict()
|
||||||
return super(MyEncoder, self).default(obj)
|
return super(MyEncoder, self).default(obj)
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@ def print_json(obj):
|
||||||
s = repr(obj)
|
s = repr(obj)
|
||||||
sys.stdout.write(s + "\n")
|
sys.stdout.write(s + "\n")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
def user_dir():
|
def user_dir():
|
||||||
if "HOME" in os.environ:
|
if "HOME" in os.environ:
|
||||||
|
@ -49,7 +48,7 @@ def user_dir():
|
||||||
return "/sdcard/electrum/"
|
return "/sdcard/electrum/"
|
||||||
else:
|
else:
|
||||||
#raise Exception("No home directory found in environment variables.")
|
#raise Exception("No home directory found in environment variables.")
|
||||||
return
|
return
|
||||||
|
|
||||||
def appdata_dir():
|
def appdata_dir():
|
||||||
"""Find the path to the application data directory; add an electrum folder and return path."""
|
"""Find the path to the application data directory; add an electrum folder and return path."""
|
||||||
|
@ -88,7 +87,7 @@ def format_satoshis(x, is_diff=False, num_zeros = 0, decimal_point = 8, whitespa
|
||||||
digits.insert(0,'0')
|
digits.insert(0,'0')
|
||||||
digits.insert(-decimal_point,'.')
|
digits.insert(-decimal_point,'.')
|
||||||
s = ''.join(digits).rstrip('0')
|
s = ''.join(digits).rstrip('0')
|
||||||
if sign:
|
if sign:
|
||||||
s = '-' + s
|
s = '-' + s
|
||||||
elif is_diff:
|
elif is_diff:
|
||||||
s = "+" + s
|
s = "+" + s
|
||||||
|
@ -97,7 +96,7 @@ def format_satoshis(x, is_diff=False, num_zeros = 0, decimal_point = 8, whitespa
|
||||||
s += "0"*( 1 + num_zeros - ( len(s) - p ))
|
s += "0"*( 1 + num_zeros - ( len(s) - p ))
|
||||||
if whitespaces:
|
if whitespaces:
|
||||||
s += " "*( 1 + decimal_point - ( len(s) - p ))
|
s += " "*( 1 + decimal_point - ( len(s) - p ))
|
||||||
s = " "*( 13 - decimal_point - ( p )) + s
|
s = " "*( 13 - decimal_point - ( p )) + s
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
@ -166,27 +165,31 @@ def parse_url(url):
|
||||||
else:
|
else:
|
||||||
params = []
|
params = []
|
||||||
|
|
||||||
|
kv = {}
|
||||||
|
|
||||||
amount = label = message = signature = identity = ''
|
amount = label = message = signature = identity = ''
|
||||||
for p in params:
|
for p in params:
|
||||||
k,v = p.split('=')
|
k,v = p.split('=')
|
||||||
uv = urldecode(v)
|
uv = urldecode(v)
|
||||||
if k == 'amount':
|
if k in kv:
|
||||||
amount = uv
|
raise Exception('Duplicate Keys')
|
||||||
m = re.match('([0-9\.]+)X([0-9])', uv)
|
kv[k] = uv
|
||||||
if m:
|
|
||||||
k = int(m.group(2)) - 8
|
if 'amount' in kv:
|
||||||
amount = Decimal(m.group(1)) * pow( Decimal(10) , k)
|
am = kv['amount']
|
||||||
else:
|
m = re.match('([0-9\.]+)X([0-9])', am)
|
||||||
amount = Decimal(uv)
|
if m:
|
||||||
elif k == 'message':
|
k = int(m.group(2)) - 8
|
||||||
message = uv
|
amount = Decimal(m.group(1)) * pow( Decimal(10) , k)
|
||||||
elif k == 'label':
|
else:
|
||||||
label = uv
|
amount = Decimal(am)
|
||||||
elif k == 'signature':
|
if 'message' in kv:
|
||||||
identity, signature = uv.split(':')
|
message = kv['message']
|
||||||
url = url.replace('&%s=%s'%(k,v),'')
|
if 'label' in kv:
|
||||||
else:
|
label = kv['label']
|
||||||
print k,v
|
if 'signature' in kv:
|
||||||
|
identity, signature = kv['signature'].split(':')
|
||||||
|
url = url.replace('&%s=%s'%('signature',kv['signature']),'')
|
||||||
|
|
||||||
return address, amount, label, message, signature, identity, url
|
return address, amount, label, message, signature, identity, url
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue