electrum-bitcoinprivate/client/electrum4a.py

853 lines
25 KiB
Python
Raw Normal View History

2012-04-03 08:32:08 -07:00
#!/usr/bin/env python
#
# Electrum - lightweight Bitcoin client
# Copyright (C) 2011 thomasv@gitorious
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import android
from interface import WalletSynchronizer
from wallet import Wallet
from wallet import format_satoshis
from decimal import Decimal
2012-04-05 12:28:38 -07:00
import mnemonic
2012-04-03 11:51:50 -07:00
2012-04-03 16:13:12 -07:00
import datetime
2012-04-03 11:51:50 -07:00
2012-04-03 08:32:08 -07:00
2012-04-05 12:28:38 -07:00
def modal_dialog(title, msg = ''):
2012-04-05 09:34:50 -07:00
droid.dialogCreateAlert(title,msg)
droid.dialogSetPositiveButtonText('OK')
droid.dialogShow()
droid.dialogGetResponse()
droid.dialogDismiss()
2012-04-03 08:32:08 -07:00
2012-04-05 09:34:50 -07:00
def modal_question(q,msg):
droid.dialogCreateAlert(q, msg)
droid.dialogSetPositiveButtonText('OK')
droid.dialogSetNegativeButtonText('Cancel')
droid.dialogShow()
response = droid.dialogGetResponse().result
droid.dialogDismiss()
return response.get('which') == 'positive'
2012-04-03 08:32:08 -07:00
2012-04-04 13:04:43 -07:00
def select_from_contacts():
title = 'Contacts:'
droid.dialogCreateAlert(title)
2012-04-05 05:04:30 -07:00
droid.dialogSetPositiveButtonText('New contact')
2012-04-04 13:04:43 -07:00
droid.dialogSetItems(wallet.addressbook)
droid.dialogShow()
2012-04-05 05:04:30 -07:00
response = droid.dialogGetResponse().result
2012-04-04 13:04:43 -07:00
droid.dialogDismiss()
2012-04-05 05:04:30 -07:00
if response.get('which') == 'positive':
return 'newcontact'
result = response.get('item')
print result
2012-04-04 13:04:43 -07:00
if result is not None:
addr = wallet.addressbook[result]
return addr
2012-04-03 08:32:08 -07:00
2012-04-04 13:04:43 -07:00
def select_from_addresses():
2012-04-03 08:32:08 -07:00
droid.dialogCreateAlert("Addresses:")
l = []
for i in range(len(wallet.addresses)):
addr = wallet.addresses[i]
l.append( wallet.labels.get(addr,'') + ' ' + addr)
droid.dialogSetItems(l)
droid.dialogShow()
2012-04-04 13:04:43 -07:00
response = droid.dialogGetResponse()
result = response.result.get('item')
2012-04-03 08:32:08 -07:00
droid.dialogDismiss()
2012-04-04 13:04:43 -07:00
if result is not None:
addr = wallet.addresses[result]
return addr
2012-04-03 08:32:08 -07:00
2012-04-05 09:34:50 -07:00
def protocol_dialog(host, z):
droid.dialogCreateAlert('Protocol',host)
protocols = z.keys()
l = []
for p in protocols:
if p == 't': l.append('TCP/stratum')
if p == 'h': l.append('HTTP/Stratum')
if p == 'n': l.append('TCP/native')
droid.dialogSetSingleChoiceItems(l)
droid.dialogSetPositiveButtonText('OK')
droid.dialogSetNegativeButtonText('Cancel')
droid.dialogShow()
response = droid.dialogGetResponse().result
if response.get('which') == 'positive':
response = droid.dialogGetSelectedItems().result[0]
droid.dialogDismiss()
p = protocols[response]
port = z[p]
return host + ':' + port + ':' + p
2012-04-03 08:32:08 -07:00
2012-04-05 05:04:30 -07:00
def qr_code_layout(addr):
return """<html>
<head>
<title>QR code</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ecdsa.org/jquery.qrcode.min.js"></script>
<script>
var address = '%s';
var droid = new Android();
var cb = function() {
droid.eventPost("main", "");
}
</script>
</head>
<body>
<div id="qrcode"></div>
<div id="address"></div>
<script>
jQuery('#address').html("bitcoin:"+address);
jQuery('#qrcode').qrcode("bitcoin:"+address);
</script>
<form onsubmit="cb(); return false;">
2012-04-05 09:34:50 -07:00
<input type="submit" value="Back" />
2012-04-05 05:04:30 -07:00
</form>
</body>
</html>"""%addr
2012-04-04 09:47:17 -07:00
title = """
2012-04-05 09:34:50 -07:00
"""
def make_layout(s, scrollable):
content = """
2012-04-04 09:47:17 -07:00
<TextView android:id="@+id/titleTextView"
android:layout_width="match_parent"
2012-04-04 13:04:43 -07:00
android:layout_height="100"
2012-04-04 09:47:17 -07:00
android:text="Electrum"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:textColor="0xff0055ff"
android:textSize="30" >
</TextView>
2012-04-03 08:32:08 -07:00
2012-04-05 09:34:50 -07:00
%s """%s
if scrollable:
content = """
<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
%s
</LinearLayout>
</ScrollView>
"""%content
2012-04-05 05:04:30 -07:00
return """<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff000022">
2012-04-05 09:34:50 -07:00
%s
</LinearLayout>"""%content
2012-04-05 05:04:30 -07:00
2012-04-03 08:32:08 -07:00
2012-04-04 09:47:17 -07:00
2012-04-05 09:34:50 -07:00
def main_layout():
return make_layout("""
2012-04-04 09:47:17 -07:00
<TextView android:id="@+id/balanceTextView"
2012-04-03 08:32:08 -07:00
android:layout_width="match_parent"
android:layout_height="wrap_content"
2012-04-04 09:47:17 -07:00
android:text=""
2012-04-03 08:32:08 -07:00
android:textAppearance="?android:attr/textAppearanceLarge"
2012-04-04 09:47:17 -07:00
android:gravity="left"
android:textColor="0xffffffff"
android:padding="10"
android:textSize="18" >
2012-04-03 08:32:08 -07:00
</TextView>
2012-04-04 09:47:17 -07:00
<TextView android:id="@+id/historyTextView"
2012-04-03 08:32:08 -07:00
android:layout_width="match_parent"
2012-04-04 09:47:17 -07:00
android:layout_height="70"
android:text="Recent transactions"
2012-04-03 08:32:08 -07:00
android:textAppearance="?android:attr/textAppearanceLarge"
2012-04-04 09:47:17 -07:00
android:gravity="center_vertical|center_horizontal|center">
2012-04-03 08:32:08 -07:00
</TextView>
2012-04-05 09:34:50 -07:00
%s """%get_history_layout(15),True)
2012-04-03 08:32:08 -07:00
2012-04-04 13:35:35 -07:00
payto_layout = make_layout("""
2012-04-05 09:34:50 -07:00
2012-04-03 08:32:08 -07:00
<TextView android:id="@+id/recipientTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pay to:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="left">
</TextView>
2012-04-03 16:13:12 -07:00
2012-04-03 08:32:08 -07:00
<EditText android:id="@+id/recipient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
2012-04-05 09:34:50 -07:00
android:tag="Tag Me" android:inputType="text">
2012-04-03 08:32:08 -07:00
</EditText>
2012-04-03 16:13:12 -07:00
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/buttonQR" android:layout_width="wrap_content"
2012-04-05 05:04:30 -07:00
android:layout_height="wrap_content" android:text="From QR code"></Button>
2012-04-03 16:13:12 -07:00
<Button android:id="@+id/buttonContacts" android:layout_width="wrap_content"
2012-04-05 05:04:30 -07:00
android:layout_height="wrap_content" android:text="From Contacts"></Button>
2012-04-03 16:13:12 -07:00
</LinearLayout>
2012-04-03 08:32:08 -07:00
<TextView android:id="@+id/labelTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Description:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="left">
</TextView>
<EditText android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
2012-04-05 09:34:50 -07:00
android:tag="Tag Me" android:inputType="text">
2012-04-03 08:32:08 -07:00
</EditText>
<TextView android:id="@+id/amountLabelTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Amount:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="left">
</TextView>
<EditText android:id="@+id/amount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
2012-04-03 16:13:12 -07:00
android:tag="Tag Me" android:inputType="numberDecimal">
2012-04-03 08:32:08 -07:00
</EditText>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/linearLayout1">
<Button android:id="@+id/buttonPay" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Send"></Button>
2012-04-05 09:34:50 -07:00
</LinearLayout>""",False)
2012-04-04 13:04:43 -07:00
2012-04-04 09:47:17 -07:00
2012-04-05 05:04:30 -07:00
settings_layout = make_layout("""
2012-04-03 08:32:08 -07:00
<TextView android:id="@+id/serverTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Server:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="left">
</TextView>
<EditText android:id="@+id/server"
android:layout_width="match_parent"
android:layout_height="wrap_content"
2012-04-05 05:04:30 -07:00
android:tag="Tag Me"
2012-04-05 09:34:50 -07:00
android:inputType="text">
2012-04-03 08:32:08 -07:00
</EditText>
<LinearLayout android:layout_width="match_parent"
2012-04-05 05:04:30 -07:00
android:layout_height="wrap_content"
android:id="@+id/linearLayout1">
<Button android:id="@+id/buttonServer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Public servers">
</Button>
<Button android:id="@+id/buttonProtocol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Protocol">
</Button>
</LinearLayout>
2012-04-05 12:28:38 -07:00
<TextView android:id="@+id/feeTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fee:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="left">
</TextView>
<EditText android:id="@+id/fee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="Tag Me"
android:inputType="numberDecimal">
</EditText>
2012-04-05 05:04:30 -07:00
<Button android:id="@+id/buttonSave" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Save"></Button>
2012-04-05 09:34:50 -07:00
""",False)
2012-04-03 08:32:08 -07:00
2012-04-04 09:47:17 -07:00
def get_history_values(n):
values = []
h = wallet.get_tx_history()
for i in range(n):
line = h[-i-1]
v = line['value']
try:
dt = datetime.datetime.fromtimestamp( line['timestamp'] )
if dt.date() == dt.today().date():
time_str = str( dt.time() )
else:
time_str = str( dt.date() )
conf = 'v'
except:
print line['timestamp']
time_str = 'pending'
conf = 'o'
2012-04-05 09:44:09 -07:00
tx_hash = line['tx_hash']
label = wallet.labels.get(tx_hash)
2012-04-04 09:47:17 -07:00
is_default_label = (label == '') or (label is None)
if is_default_label: label = line['default_label']
values.append((conf, ' ' + time_str, ' ' + format_satoshis(v,True), ' ' + label ))
return values
def get_history_layout(n):
rows = ""
i = 0
values = get_history_values(n)
for v in values:
a,b,c,d = v
color = "0xff00ff00" if a == 'v' else "0xffff0000"
rows += """
<TableRow>
<TextView
android:id="@+id/hl_%d_col1"
android:layout_column="0"
android:text="%s"
android:textColor="%s"
android:padding="3" />
<TextView
android:id="@+id/hl_%d_col2"
android:layout_column="1"
android:text="%s"
android:padding="3" />
<TextView
android:id="@+id/hl_%d_col3"
android:layout_column="2"
android:text="%s"
android:padding="3" />
<TextView
android:id="@+id/hl_%d_col4"
android:layout_column="3"
android:text="%s"
android:padding="4" />
</TableRow>"""%(i,a,color,i,b,i,c,i,d)
i += 1
output = """
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0,1,2,3">
%s
</TableLayout>"""% rows
return output
def set_history_layout(n):
values = get_history_values(n)
i = 0
for v in values:
a,b,c,d = v
droid.fullSetProperty("hl_%d_col1"%i,"text", a)
if a == 'v':
droid.fullSetProperty("hl_%d_col1"%i, "textColor","0xff00ff00")
else:
droid.fullSetProperty("hl_%d_col1"%i, "textColor","0xffff0000")
droid.fullSetProperty("hl_%d_col2"%i,"text", b)
droid.fullSetProperty("hl_%d_col3"%i,"text", c)
droid.fullSetProperty("hl_%d_col4"%i,"text", d)
i += 1
2012-04-05 05:04:30 -07:00
2012-04-04 09:47:17 -07:00
def update_layout():
if not wallet.interface.is_connected:
text = "Not connected..."
elif wallet.blocks == 0:
text = "Server not ready"
elif not wallet.up_to_date:
text = "Synchronizing..."
else:
c, u = wallet.get_balance()
text = "Balance:"+format_satoshis(c)
2012-04-04 14:16:51 -07:00
if u : text += ' [' + format_satoshis(u,True).strip() + ']'
2012-04-04 09:47:17 -07:00
droid.fullSetProperty("balanceTextView", "text", text)
if wallet.was_updated and wallet.up_to_date:
2012-04-04 14:16:51 -07:00
global first_time_update
if not first_time_update:
droid.vibrate()
else:
first_time_update = False
2012-04-04 09:47:17 -07:00
wallet.was_updated = False
set_history_layout(15)
2012-04-03 08:32:08 -07:00
def pay_to(recipient, amount, fee, label):
if wallet.use_encryption:
password = droid.dialogGetPassword('Password').result
print "password", password
else:
password = None
droid.dialogCreateSpinnerProgress("Electrum", "signing transaction...")
droid.dialogShow()
2012-04-05 09:34:50 -07:00
try:
tx = wallet.mktx( recipient, amount, label, password, fee)
except:
droid.dialogDismiss()
return 'error'
2012-04-03 08:32:08 -07:00
print tx
droid.dialogDismiss()
if tx:
r, h = wallet.sendtx( tx )
2012-04-05 09:34:50 -07:00
modal_dialog('tx sent', h)
2012-04-03 08:32:08 -07:00
return h
else:
return 'error'
2012-04-05 05:04:30 -07:00
def recover():
2012-04-05 09:34:50 -07:00
if not modal_question("Wallet not found","restore from seed?"):
exit(1)
2012-04-03 08:32:08 -07:00
2012-04-03 16:13:12 -07:00
code = droid.scanBarcode()
r = code.result
if r:
seed = r['extras']['SCAN_RESULT']
else:
exit(1)
2012-04-05 12:28:38 -07:00
if not modal_question('Seed', seed ):
2012-04-05 09:34:50 -07:00
exit(1)
2012-04-03 08:32:08 -07:00
2012-04-03 16:13:12 -07:00
wallet.seed = str(seed)
wallet.init_mpk( wallet.seed )
2012-04-05 12:28:38 -07:00
change_password_dialog()
2012-04-04 09:47:17 -07:00
droid.dialogCreateSpinnerProgress("Electrum", "recovering wallet...")
2012-04-03 16:13:12 -07:00
droid.dialogShow()
WalletSynchronizer(wallet,True).start()
wallet.update()
wallet.save()
droid.dialogDismiss()
droid.vibrate()
if wallet.is_found():
# history and addressbook
wallet.update_tx_history()
wallet.fill_addressbook()
2012-04-05 09:34:50 -07:00
modal_dialog("recovery successful")
2012-04-03 16:13:12 -07:00
else:
2012-04-05 12:28:38 -07:00
if not modal_question("no transactions found for this seed","do you want to keep this wallet?"):
exit(1)
wallet.save()
2012-04-03 08:32:08 -07:00
2012-04-03 10:03:58 -07:00
2012-04-05 05:04:30 -07:00
def make_new_contact():
code = droid.scanBarcode()
r = code.result
if r:
address = r['extras']['SCAN_RESULT']
if address:
if wallet.is_valid(address):
2012-04-05 09:34:50 -07:00
if modal_question('Add to contacts?', address):
2012-04-05 05:04:30 -07:00
wallet.addressbook.append(address)
wallet.save()
else:
2012-04-05 09:34:50 -07:00
modal_dialog('Invalid address', address)
2012-04-03 08:32:08 -07:00
2012-04-03 10:03:58 -07:00
def main_loop():
2012-04-04 09:47:17 -07:00
update_layout()
2012-04-03 08:32:08 -07:00
out = None
while out is None:
2012-04-04 09:47:17 -07:00
event = droid.eventWait(1000).result # wait for 1 second
if not event:
update_layout()
continue
2012-04-03 08:32:08 -07:00
print "got event in main loop", event
if event["name"]=="click":
id=event["data"]["id"]
elif event["name"]=="settings":
out = 'settings'
2012-04-04 09:47:17 -07:00
elif event["name"]=="key":
if event["data"]["key"] == '4':
out = 'quit'
2012-04-05 05:04:30 -07:00
elif event["name"] in menu_commands:
out = event["name"]
if out == 'contacts':
global contact_addr
contact_addr = select_from_contacts()
if contact_addr == 'newcontact':
make_new_contact()
contact_addr = None
if not contact_addr:
out = None
elif out == "receive":
global receive_addr
receive_addr = select_from_addresses()
if not receive_addr:
out = None
2012-04-03 08:32:08 -07:00
return out
2012-04-05 09:34:50 -07:00
2012-04-03 08:32:08 -07:00
def payto_loop():
out = None
while out is None:
event = droid.eventWait().result
print "got event in payto loop", event
if event["name"] == "click":
id = event["data"]["id"]
if id=="buttonPay":
droid.fullQuery()
recipient = droid.fullQueryDetail("recipient").result.get('text')
label = droid.fullQueryDetail("label").result.get('text')
amount = droid.fullQueryDetail('amount').result.get('text')
fee = '0.001'
2012-04-05 09:34:50 -07:00
try:
amount = int( 100000000 * Decimal(amount) )
except:
modal_dialog('Error','invalid amount')
continue
2012-04-03 08:32:08 -07:00
fee = int( 100000000 * Decimal(fee) )
result = pay_to(recipient, amount, fee, label)
2012-04-05 09:34:50 -07:00
modal_dialog('result',result)
2012-04-03 08:32:08 -07:00
out = 'main'
elif id=="buttonContacts":
2012-04-04 13:04:43 -07:00
addr = select_from_contacts()
2012-04-03 08:32:08 -07:00
droid.fullSetProperty("recipient","text",addr)
2012-04-03 11:51:50 -07:00
elif id=="buttonQR":
code = droid.scanBarcode()
r = code.result
if r:
addr = r['extras']['SCAN_RESULT']
if addr:
droid.fullSetProperty("recipient","text",addr)
2012-04-05 05:04:30 -07:00
elif event["name"] in menu_commands:
out = event["name"]
2012-04-03 08:32:08 -07:00
2012-04-04 09:47:17 -07:00
elif event["name"]=="key":
if event["data"]["key"] == '4':
out = 'main'
2012-04-03 08:32:08 -07:00
#elif event["name"]=="screen":
# if event["data"]=="destroy":
# out = 'main'
return out
2012-04-04 13:04:43 -07:00
receive_addr = ''
contact_addr = ''
def receive_loop():
2012-04-03 08:32:08 -07:00
out = None
while out is None:
event = droid.eventWait().result
2012-04-04 13:04:43 -07:00
print "got event", event
2012-04-05 05:04:30 -07:00
out = 'main'
2012-04-04 13:04:43 -07:00
return out
def contacts_loop():
out = None
while out is None:
event = droid.eventWait().result
print "got event", event
2012-04-05 05:04:30 -07:00
out = 'main'
2012-04-03 08:32:08 -07:00
return out
2012-04-04 13:04:43 -07:00
2012-04-03 08:32:08 -07:00
def server_dialog(plist):
droid.dialogCreateAlert("servers")
droid.dialogSetItems( plist.keys() )
droid.dialogShow()
i = droid.dialogGetResponse().result.get('item')
droid.dialogDismiss()
if i is not None:
response = plist.keys()[i]
return response
2012-04-04 13:04:43 -07:00
2012-04-05 12:28:38 -07:00
def seed_dialog():
if wallet.use_encryption:
password = droid.dialogGetPassword('Password').result
if not password: return
else:
password = None
try:
seed = wallet.pw_decode( wallet.seed, password)
except:
modal_dialog('error','incorrect password')
return
modal_dialog('Your seed is',seed)
modal_dialog('Mnemonic code:', ' '.join(mnemonic.mn_encode(seed)) )
def change_password_dialog():
if wallet.use_encryption:
password = droid.dialogGetPassword('Current password').result
if not password: return
else:
password = None
try:
seed = wallet.pw_decode( wallet.seed, password)
except:
modal_dialog('error','incorrect password')
return
new_password = droid.dialogGetPassword('Choose a password').result
password2 = droid.dialogGetPassword('Confirm new password').result
if new_password != password2:
modal_dialog('error','passwords do not match')
return
2012-04-05 12:38:25 -07:00
wallet.update_password(seed, new_password)
2012-04-05 12:28:38 -07:00
if new_password:
2012-04-05 12:38:25 -07:00
modal_dialog('Password updated','your wallet is encrypted')
else:
modal_dialog('Password removed','your wallet is not encrypted')
2012-04-03 08:32:08 -07:00
def settings_loop():
droid.fullSetProperty("server","text",wallet.server)
2012-04-05 09:34:50 -07:00
droid.fullSetProperty("fee","text", "%s"% str( Decimal( wallet.fee)/100000000 ) )
2012-04-03 08:32:08 -07:00
out = None
while out is None:
event = droid.eventWait().result
2012-04-05 05:04:30 -07:00
print "got event", event
2012-04-05 09:34:50 -07:00
plist = {}
for item in wallet.interface.servers:
host, pp = item
z = {}
for item2 in pp:
protocol, port = item2
z[protocol] = port
plist[host] = z
2012-04-03 08:32:08 -07:00
2012-04-05 09:34:50 -07:00
if event["name"] == "click":
2012-04-03 08:32:08 -07:00
id = event["data"]["id"]
if id=="buttonServer":
host = server_dialog(plist)
2012-04-04 13:35:35 -07:00
if host:
p = plist[host]
port = p['t']
srv = host + ':' + port + ':t'
droid.fullSetProperty("server","text",srv)
2012-04-03 08:32:08 -07:00
2012-04-05 09:34:50 -07:00
elif id=="buttonProtocol":
droid.fullQuery()
srv = droid.fullQueryDetail("server").result.get('text')
host = srv.split(':')[0]
if host in plist:
server = protocol_dialog(host, plist[host])
if server:
droid.fullSetProperty("server","text",server)
2012-04-05 09:34:50 -07:00
2012-04-05 12:28:38 -07:00
elif id=="buttonSave":
2012-04-03 08:32:08 -07:00
droid.fullQuery()
srv = droid.fullQueryDetail("server").result.get('text')
2012-04-05 09:34:50 -07:00
fee = droid.fullQueryDetail("fee").result.get('text')
2012-04-03 08:32:08 -07:00
try:
wallet.set_server(srv)
except:
2012-04-05 09:34:50 -07:00
modal_dialog('error','invalid server')
try:
fee = int( 100000000 * Decimal(fee) )
if wallet.fee != fee:
wallet.fee = fee
wallet.save()
except:
modal_dialog('error','invalid fee value')
2012-04-05 12:28:38 -07:00
elif event["name"] in menu_commands:
out = event["name"]
2012-04-05 09:34:50 -07:00
2012-04-05 12:28:38 -07:00
elif event["name"] == 'password':
change_password_dialog()
elif event["name"] == 'seed':
seed_dialog()
elif event["name"] == 'cancel':
out = 'main'
2012-04-03 08:32:08 -07:00
elif event["name"] == "key":
if event["data"]["key"] == '4':
out = 'main'
return out
2012-04-05 05:04:30 -07:00
menu_commands = ["send", "receive", "settings", "contacts", "main"]
first_time_update = True
droid = android.Android()
wallet = Wallet()
wallet.set_path("/sdcard/electrum.dat")
wallet.read()
if not wallet.file_exists:
recover()
else:
WalletSynchronizer(wallet,True).start()
2012-04-03 08:32:08 -07:00
s = 'main'
2012-04-05 05:04:30 -07:00
def add_menu(s):
droid.clearOptionsMenu()
if s == 'main':
droid.addOptionsMenuItem("Send","send",None,"")
droid.addOptionsMenuItem("Receive","receive",None,"")
droid.addOptionsMenuItem("Contacts","contacts",None,"")
droid.addOptionsMenuItem("Settings","settings",None,"")
2012-04-05 09:34:50 -07:00
elif s == 'receive':
droid.addOptionsMenuItem("Back","main",None,"")
2012-04-05 05:04:30 -07:00
elif s == 'contacts':
2012-04-05 09:34:50 -07:00
droid.addOptionsMenuItem("Back","main",None,"")
#droid.addOptionsMenuItem("Pay to","paytocontact",None,"")
#droid.addOptionsMenuItem("Edit label","editcontact",None,"")
#droid.addOptionsMenuItem("Delete","removecontact",None,"")
2012-04-05 05:04:30 -07:00
elif s == 'settings':
2012-04-05 12:28:38 -07:00
droid.addOptionsMenuItem("Password","password",None,"")
droid.addOptionsMenuItem("Seed","seed",None,"")
2012-04-05 05:04:30 -07:00
2012-04-05 12:28:38 -07:00
2012-04-03 08:32:08 -07:00
while True:
2012-04-05 05:04:30 -07:00
add_menu(s)
2012-04-03 08:32:08 -07:00
if s == 'main':
2012-04-05 05:04:30 -07:00
droid.fullShow(main_layout())
2012-04-03 08:32:08 -07:00
s = main_loop()
2012-04-05 05:04:30 -07:00
droid.fullDismiss()
2012-04-05 09:34:50 -07:00
2012-04-05 05:04:30 -07:00
elif s == 'send':
droid.fullShow(payto_layout)
2012-04-03 08:32:08 -07:00
s = payto_loop()
2012-04-05 05:04:30 -07:00
droid.fullDismiss()
2012-04-04 13:04:43 -07:00
elif s == 'receive':
2012-04-05 05:04:30 -07:00
f = open('/sdcard/sl4a/scripts/recv.html',"w")
f.write(qr_code_layout(receive_addr))
f.close()
2012-04-05 09:34:50 -07:00
wvs = droid.webViewShow("file:///sdcard/sl4a/scripts/recv.html")
2012-04-04 13:04:43 -07:00
s = receive_loop()
2012-04-05 05:04:30 -07:00
2012-04-04 13:04:43 -07:00
elif s == 'contacts':
2012-04-05 05:04:30 -07:00
f = open('/sdcard/sl4a/scripts/recv.html',"w")
f.write(qr_code_layout(contact_addr))
f.close()
2012-04-05 05:11:26 -07:00
droid.webViewShow("file:///sdcard/sl4a/scripts/recv.html")
2012-04-04 13:04:43 -07:00
s = contacts_loop()
2012-04-05 05:04:30 -07:00
2012-04-03 08:32:08 -07:00
elif s == 'settings':
2012-04-05 05:04:30 -07:00
droid.fullShow(settings_layout)
2012-04-03 08:32:08 -07:00
s = settings_loop()
2012-04-05 05:04:30 -07:00
droid.fullDismiss()
2012-04-03 08:32:08 -07:00
else:
break
droid.makeToast("Bye!")