commit aa1671e0382d6ed8610ee7a92a2eeba5f820bf65
parent bf303ef50cbd9b68336c7a6668f8cf467ed7d002
Author: thomasv <thomasv@gitorious>
Date: Tue, 14 Feb 2012 12:45:39 +0100
set_url
Diffstat:
4 files changed, 54 insertions(+), 43 deletions(-)
diff --git a/client/electrum b/client/electrum
@@ -23,10 +23,6 @@ from wallet import Wallet
from interface import Interface
from decimal import Decimal
-# URL decode
-_ud = re.compile('%([0-9a-hA-H]{2})', re.MULTILINE)
-urldecode = lambda x: _ud.sub(lambda m: chr(int(m.group(1), 16)), x)
-
from wallet import format_satoshis
@@ -36,6 +32,7 @@ if __name__ == '__main__':
usage = "usage: %prog [options] command args\nCommands: "+ (', '.join(known_commands))
parser = OptionParser(usage=usage)
+ parser.add_option("-g", "--gui", dest="gui", default="gtk", help="gui")
parser.add_option("-w", "--wallet", dest="wallet_path", help="wallet path (default: electrum.dat)")
parser.add_option("-a", "--all", action="store_true", dest="show_all", default=False, help="show all addresses")
parser.add_option("-b", "--balance", action="store_true", dest="show_balance", default=False, help="show the balance at listed addresses")
@@ -49,15 +46,24 @@ if __name__ == '__main__':
wallet = Wallet(interface)
wallet.set_path(options.wallet_path)
- cmd = args[0] if len(args) > 0 else 'qt'
- firstarg = args[1] if len(args) > 1 else ''
-
-
- if cmd in ['gtk','qt'] or re.match('^bitcoin:', cmd):
- if cmd == 'gtk':
+ if len(args)==0:
+ url = None
+ cmd = 'gui'
+ elif len(args)==1 and re.match('^bitcoin:', args[0]):
+ url = args[0]
+ cmd = 'gui'
+ else:
+ cmd = args[0]
+ firstarg = args[1] if len(args) > 1 else ''
+
+ if cmd == 'gui':
+ if options.gui=='gtk':
import gui
- else:
+ elif options.gui=='qt':
import gui_qt as gui
+ else:
+ print "unknown gui", options.gui
+ exit(1)
interface.get_servers()
gui = gui.ElectrumGui(wallet)
@@ -75,34 +81,7 @@ if __name__ == '__main__':
if not found: exit(1)
interface.start(wallet)
- gui.main()
- sys.exit(0)
-
- if re.match('^bitcoin:', cmd):
-
- o = cmd[8:].split('?')
- address = o[0]
- if len(o)>1:
- params = o[1].split('&')
- else:
- params = []
-
- amount = label = message = signature = identity = ''
- for p in params:
- k,v = p.split('=')
- uv = urldecode(v)
- if k == 'amount': amount = uv
- elif k == 'message': message = uv
- elif k == 'label': label = uv
- elif k == 'signature':
- identity, signature = uv.split(':')
- cmd = cmd.replace('&%s=%s'%(k,v),'')
- else:
- print k,v
-
- gui.set_send_tab(address, amount, message, label, identity, signature, cmd)
-
- gui.main()
+ gui.main(url)
wallet.save()
sys.exit(0)
diff --git a/client/gui.py b/client/gui.py
@@ -695,7 +695,9 @@ class ElectrumWindow:
entry.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff"))
- def set_send_tab(self, payto, amount, message, label, identity, signature, cmd):
+ def set_url(self, url):
+
+ payto, amount, label, message, signature, identity = self.wallet.parse_url(url)
self.notebook.set_current_page(1)
if signature:
@@ -1228,8 +1230,9 @@ class ElectrumGui():
def __init__(self, wallet):
self.wallet = wallet
- def main(self):
- ElectrumWindow(self.wallet)
+ def main(self, url=None):
+ ew = ElectrumWindow(self.wallet)
+ if url: ew.set_url(url)
gtk.main()
def restore_or_create(self):
diff --git a/client/gui_qt.py b/client/gui_qt.py
@@ -751,10 +751,11 @@ class ElectrumGui():
return True
- def main(self):
+ def main(self,url):
s = Sender()
s.start()
w = ElectrumWindow(self.wallet)
+ if url: w.set_url(url)
w.app = self.app
w.connect_slots(s)
self.app.exec_()
diff --git a/client/wallet.py b/client/wallet.py
@@ -143,6 +143,10 @@ def ASecretToSecret(key):
########### end pywallet functions #######################
+# URL decode
+_ud = re.compile('%([0-9a-hA-H]{2})', re.MULTILINE)
+urldecode = lambda x: _ud.sub(lambda m: chr(int(m.group(1), 16)), x)
+
def int_to_hex(i, length=1):
s = hex(i)[2:].rstrip('L')
@@ -809,3 +813,27 @@ class Wallet:
self.aliases[alias] = (signing_address, target)
return target
+
+
+ def parse_url(self, url):
+ o = url[8:].split('?')
+ address = o[0]
+ if len(o)>1:
+ params = o[1].split('&')
+ else:
+ params = []
+
+ amount = label = message = signature = identity = ''
+ for p in params:
+ k,v = p.split('=')
+ uv = urldecode(v)
+ if k == 'amount': amount = uv
+ elif k == 'message': message = uv
+ elif k == 'label': label = uv
+ elif k == 'signature':
+ identity, signature = uv.split(':')
+ url = url.replace('&%s=%s'%(k,v),'')
+ else:
+ print k,v
+
+ return address, amount, label, message, signature, identity