electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 80284d55168fc9edd9710fbf160aeb77af337cd6
parent 18d16ba82c8c0a543b71d88c654a3a53d8956281
Author: ThomasV <thomasv@gitorious>
Date:   Tue, 24 Feb 2015 18:41:29 +0100

updates for the old android GUI

Diffstat:
Mcontrib/make_android | 18+++++++++---------
Mcontrib/make_download | 21++++++++++++++++++---
Melectrum | 7++++---
Mgui/android.py | 76++++++++++++++++++++++++++++++++++++----------------------------------------
Mlib/util.py | 10+++++++---
5 files changed, 74 insertions(+), 58 deletions(-)

diff --git a/contrib/make_android b/contrib/make_android @@ -7,19 +7,20 @@ if __name__ == '__main__': os.chdir(os.path.dirname(os.path.realpath(__file__))) os.chdir('..') - imp.load_module('electrum', *imp.find_module('../lib')) - from electrum.version import ELECTRUM_VERSION as version + v = imp.load_source('version', 'lib/version.py') + version = v.ELECTRUM_VERSION if not ( os.path.exists('packages')): print "The packages directory is missing." sys.exit() - os.system('rm -rf dist/e4a-%s'%version) os.mkdir('dist/e4a-%s'%version) shutil.copyfile("electrum",'dist/e4a-%s/e4a.py'%version) - shutil.copytree("packages",'dist/e4a-%s/packages'%version) - shutil.copytree("lib",'dist/e4a-%s/lib'%version) + shutil.copytree("packages",'dist/e4a-%s/packages'%version, ignore=shutil.ignore_patterns('*.pyc')) + shutil.copytree("lib",'dist/e4a-%s/lib'%version, ignore=shutil.ignore_patterns('*.pyc')) + # dns is not used by android app + os.system('rm -rf dist/e4a-%s/packages/dns') os.mkdir('dist/e4a-%s/gui'%version) for n in ['android.py']: shutil.copy("gui/%s"%n,'dist/e4a-%s/gui'%version) @@ -27,13 +28,12 @@ if __name__ == '__main__': os.chdir("dist") # create the zip file - os.system( "zip -r e4a-%s.zip e4a-%s"%(version, version) ) + os.system( "zip -qr e4a-%s.zip e4a-%s"%(version, version) ) os.system( "rm -rf e4a-%s"%(version) ) # change filename because some 3G carriers do not allow users to download a zip file... e4a_name = "e4a-%s.zip"%version e4a_name2 = e4a_name.replace(".","") - os.system( "mv %s %s"%(e4a_name, e4a_name2) ) - print "dist/%s "%e4a_name2 - + os.system("mv %s %s"%(e4a_name, e4a_name2)) + print "dist/%s"%e4a_name2 diff --git a/contrib/make_download b/contrib/make_download @@ -3,9 +3,10 @@ import sys import hashlib import os -from versions import version, version_win, version_mac, template_path, dl_path +from versions import version, version_win, version_mac +from versions import download_template, download_page -with open(template_path) as f: +with open(download_template) as f: string = f.read() _tgz = "Electrum-%s.tar.gz" % version @@ -38,6 +39,20 @@ string = string.replace("##md5_win##", md5_win) string = string.replace("##md5_win_setup##", md5_win_setup) string = string.replace("##md5_win_portable##", md5_win_portable) -with open(dl_path,'w') as f: +with open(download_page,'w') as f: f.write(string) + +# android + +from versions import android_template, android_page +with open(android_template) as f: + string = f.read() + +e4a_name = "e4a-%s.zip"%version +e4a_zipname = e4a_name.replace(".","") +string = string.replace("##VERSION##",version) +string = string.replace("##ZIPNAME##",e4a_zipname) + +with open(android_page,'w') as f: + f.write(string) diff --git a/electrum b/electrum @@ -27,12 +27,13 @@ import sys import time import traceback +script_dir = os.path.dirname(os.path.realpath(__file__)) is_bundle = getattr(sys, 'frozen', False) -is_local = not is_bundle and os.path.dirname(os.path.realpath(__file__)) == os.getcwd() +is_local = not is_bundle and script_dir == os.getcwd() is_android = 'ANDROID_DATA' in os.environ -if is_local: - sys.path.insert(0, 'packages') +if is_local or is_android: + sys.path.insert(0, os.path.join(script_dir, 'packages')) elif is_bundle and sys.platform=='darwin': sys.path.insert(0, os.getcwd() + "/lib/python2.7/packages") diff --git a/gui/android.py b/gui/android.py @@ -22,7 +22,7 @@ from __future__ import absolute_import import android -from electrum import SimpleConfig, Wallet, WalletStorage, format_satoshis, mnemonic_encode, mnemonic_decode +from electrum import SimpleConfig, Wallet, WalletStorage, format_satoshis from electrum.bitcoin import is_valid from electrum import util from decimal import Decimal @@ -98,7 +98,6 @@ def select_from_contacts(): return 'newcontact' result = response.get('item') - print result if result is not None: addr = wallet.addressbook[result] return addr @@ -124,9 +123,7 @@ def select_from_addresses(): def protocol_name(p): if p == 't': return 'TCP' - if p == 'h': return 'HTTP' if p == 's': return 'SSL' - if p == 'g': return 'HTTPS' def protocol_dialog(host, protocol, z): @@ -134,7 +131,7 @@ def protocol_dialog(host, protocol, z): if z: protocols = z.keys() else: - protocols = 'thsg' + protocols = 'ts' l = [] current = protocols.index(protocol) for p in protocols: @@ -147,8 +144,10 @@ def protocol_dialog(host, protocol, z): selected_item = droid.dialogGetSelectedItems().result droid.dialogDismiss() - if not response: return - if not selected_item: return + if not response: + return + if not selected_item: + return if response.get('which') == 'positive': return protocols[selected_item[0]] @@ -211,7 +210,8 @@ def make_layout(s, scrollable = False): def main_layout(): - return make_layout(""" + h = get_history_layout(15) + l = make_layout(""" <TextView android:id="@+id/balanceTextView" android:layout_width="match_parent" android:text="" @@ -229,8 +229,8 @@ def main_layout(): android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical|center_horizontal|center"> </TextView> - - %s """%get_history_layout(15),True) + %s """%h,True) + return l @@ -350,7 +350,7 @@ def get_history_values(n): conf_str = 'v' if conf else 'o' label, is_default_label = wallet.get_label(tx_hash) - values.append((conf_str, ' ' + time_str, ' ' + format_satoshis(value,True), ' ' + label )) + values.append((conf_str, ' ' + time_str, ' ' + format_satoshis(value,True), ' ' )) return values @@ -616,15 +616,18 @@ def payto_loop(): code = droid.scanBarcode() r = code.result if r: - data = r['extras']['SCAN_RESULT'] + data = str(r['extras']['SCAN_RESULT']) if data: if re.match('^bitcoin:', data): payto, amount, label, _, _ = util.parse_URI(data) - droid.fullSetProperty("recipient", "text",payto) + amount = str(amount/100000000) + droid.fullSetProperty("recipient", "text", payto) droid.fullSetProperty("amount", "text", amount) droid.fullSetProperty("label", "text", label) - else: + elif bitcoin.is_address(data): droid.fullSetProperty("recipient", "text", data) + else: + modal_dialog('Error','cannot parse QR code\n'+data) elif event["name"] in menu_commands: @@ -717,13 +720,12 @@ def show_seed(): password = None try: - seed = wallet.get_seed(password) + seed = wallet.get_mnemonic(password) except Exception: modal_dialog('error','incorrect password') return - modal_dialog('Your seed is',seed) - modal_dialog('Mnemonic code:', ' '.join(mnemonic_encode(seed)) ) + modal_dialog('Your seed is', seed) def change_password_dialog(): if wallet.use_encryption: @@ -733,7 +735,7 @@ def change_password_dialog(): password = None try: - wallet.get_seed(password) + wallet.check_password(password) except Exception: modal_dialog('error','incorrect password') return @@ -760,8 +762,8 @@ def settings_loop(): def set_listview(): - host, port, p = network.default_server.split(':') - fee = str( Decimal( wallet.fee)/100000000 ) + host, port, p, proxy_config, auto_connect = network.get_parameters() + fee = str( Decimal( wallet.fee_per_kb)/100000000 ) is_encrypted = 'yes' if wallet.use_encryption else 'no' protocol = protocol_name(p) droid.fullShow(settings_layout) @@ -783,7 +785,7 @@ def settings_loop(): if name == "itemclick": pos = event["data"]["position"] - host, port, protocol = network.default_server.split(':') + host, port, protocol, proxy_config, auto_connect = network.get_parameters() network_changed = False if pos == "0": #server @@ -796,9 +798,10 @@ def settings_loop(): elif pos == "1": #protocol if host in servers: protocol = protocol_dialog(host, protocol, servers[host]) - z = servers[host] - port = z[protocol] - network_changed = True + if protocol: + z = servers[host] + port = z[protocol] + network_changed = True elif pos == "2": #port a_port = modal_input('Port number', 'If you use a public server, this field is set automatically when you set the protocol', port, "number") @@ -807,7 +810,8 @@ def settings_loop(): network_changed = True elif pos == "3": #fee - fee = modal_input('Transaction fee', 'The fee will be this amount multiplied by the number of inputs in your transaction. ', str( Decimal( wallet.fee)/100000000 ), "numberDecimal") + fee = modal_input('Transaction fee', 'The fee will be this amount multiplied by the number of inputs in your transaction. ', + str(Decimal(wallet.fee_per_kb)/100000000 ), "numberDecimal") if fee: try: fee = int( 100000000 * Decimal(fee) ) @@ -861,17 +865,15 @@ def add_menu(s): #droid.addOptionsMenuItem("Delete","deletecontact",None,"") -def make_bitmap(addr): +def make_bitmap(data): # fixme: this is highly inefficient droid.dialogCreateSpinnerProgress("please wait") droid.dialogShow() try: - import pyqrnative, bmp - qr = pyqrnative.QRCode(4, pyqrnative.QRErrorCorrectLevel.L) - qr.addData(addr) - qr.make() - k = qr.getModuleCount() - assert k == 33 + import qrcode + from electrum import bmp + qr = qrcode.QRCode() + qr.add_data(data) bmp.save_qrcode(qr,"/sdcard/sl4a/qrcode.bmp") finally: droid.dialogDismiss() @@ -975,7 +977,7 @@ class ElectrumGui: def seed_dialog(self): - if modal_question("Enter your seed","Input method",'QR Code', 'mnemonic'): + if modal_question("Enter your seed", "Input method", 'QR Code', 'mnemonic'): code = droid.scanBarcode() r = code.result if r: @@ -984,11 +986,6 @@ class ElectrumGui: return else: m = modal_input('Mnemonic','please enter your code') - try: - seed = mnemonic_decode(m.split(' ')) - except Exception: - modal_dialog('error: could not decode this seed') - return return str(seed) @@ -998,8 +995,7 @@ class ElectrumGui: def show_seed(self): - modal_dialog('Your seed is:', wallet.seed) - modal_dialog('Mnemonic code:', ' '.join(mnemonic_encode(wallet.seed)) ) + modal_dialog('Your seed is:', wallet.get_mnemonic(None)) def password_dialog(self): diff --git a/lib/util.py b/lib/util.py @@ -151,9 +151,13 @@ def parse_URI(uri): assert u.scheme == 'bitcoin' address = u.path - valid_address = bitcoin.is_address(address) - pq = urlparse.parse_qs(u.query) + # python for android fails to parse query + if address.find('?') > 0: + address, query = u.path.split('?') + pq = urlparse.parse_qs(query) + else: + pq = urlparse.parse_qs(u.query) for k, v in pq.items(): if len(v)!=1: @@ -178,7 +182,7 @@ def parse_URI(uri): if request_url != '': return address, amount, label, message, request_url - assert valid_address + assert bitcoin.is_address(address) return address, amount, label, message, request_url