Merge branch 'master' of git://gitorious.org/electrum/electrum

This commit is contained in:
thomasv 2012-02-06 10:10:59 +01:00
commit 4a884cc8d9
3 changed files with 26 additions and 21 deletions

View file

@ -21,13 +21,14 @@ import re, sys, getpass
from optparse import OptionParser from optparse import OptionParser
from wallet import Wallet from wallet import Wallet
from interface import Interface from interface import Interface
from decimal import Decimal
# URL decode # URL decode
_ud = re.compile('%([0-9a-hA-H]{2})', re.MULTILINE) _ud = re.compile('%([0-9a-hA-H]{2})', re.MULTILINE)
urldecode = lambda x: _ud.sub(lambda m: chr(int(m.group(1), 16)), x) urldecode = lambda x: _ud.sub(lambda m: chr(int(m.group(1), 16)), x)
from wallet import format_satoshis
if __name__ == '__main__': if __name__ == '__main__':
known_commands = ['help', 'validateaddress', 'balance', 'contacts', 'create', 'payto', 'sendtx', 'password', 'newaddress', 'addresses', 'history', 'label', 'gui', 'mktx','seed','import','signmessage','verifymessage','list'] known_commands = ['help', 'validateaddress', 'balance', 'contacts', 'create', 'payto', 'sendtx', 'password', 'newaddress', 'addresses', 'history', 'label', 'gui', 'mktx','seed','import','signmessage','verifymessage','list']
@ -110,7 +111,7 @@ if __name__ == '__main__':
host = raw_input("server (default:%s):"%wallet.interface.host) host = raw_input("server (default:%s):"%wallet.interface.host)
port = raw_input("port (default:%d):"%wallet.interface.port) port = raw_input("port (default:%d):"%wallet.interface.port)
fee = raw_input("fee (default:%f):"%(wallet.fee*1e-8)) fee = raw_input("fee (default:%s):"%( str(Decimal(wallet.fee)/100000000)) )
if fee: wallet.fee = float(fee) if fee: wallet.fee = float(fee)
if host: wallet.interface.host = host if host: wallet.interface.host = host
if port: wallet.interface.port = int(port) if port: wallet.interface.port = int(port)
@ -223,16 +224,16 @@ if __name__ == '__main__':
if addrs == []: if addrs == []:
c, u = wallet.get_balance() c, u = wallet.get_balance()
if u: if u:
print c*1e-8, u*1e-8 print Decimal( c ) / 100000000 , Decimal( u ) / 100000000
else: else:
print c*1e-8 print Decimal( c ) / 100000000
else: else:
for addr in addrs: for addr in addrs:
c, u = wallet.get_addr_balance(addr) c, u = wallet.get_addr_balance(addr)
if u: if u:
print "%s %s, %s" % (addr, c*1e-8, u*1e-8) print "%s %s, %s" % (addr, str(Decimal(c)/100000000), str(Decimal(u)/100000000))
else: else:
print "%s %s" % (addr, c*1e-8) print "%s %s" % (addr, str(Decimal(c)/100000000))
elif cmd in [ 'contacts']: elif cmd in [ 'contacts']:
for addr in wallet.addressbook: for addr in wallet.addressbook:
@ -257,7 +258,7 @@ if __name__ == '__main__':
for item in h: for item in h:
if item['is_in']: ni += 1 if item['is_in']: ni += 1
else: no += 1 else: no += 1
b = "%d %d %f"%(no, ni, wallet.get_addr_balance(addr)[0]*1e-8) b = "%d %d %s"%(no, ni, str(Decimal(wallet.get_addr_balance(addr)[0])/100000000))
else: b='' else: b=''
if options.show_keys: if options.show_keys:
pk = wallet.get_private_key2(addr, password) pk = wallet.get_private_key2(addr, password)
@ -269,9 +270,8 @@ if __name__ == '__main__':
b = 0 b = 0
for line in lines: for line in lines:
import datetime import datetime
v = 1.*line['value']/1e8 v = line['value']
b += v b += v
v_str = "%f"%v if v<0 else "+%f"%v
try: try:
time_str = datetime.datetime.fromtimestamp( line['nTime']) time_str = datetime.datetime.fromtimestamp( line['nTime'])
except: except:
@ -281,8 +281,8 @@ if __name__ == '__main__':
if not label: label = line['tx_hash'] if not label: label = line['tx_hash']
else: label = label + ' '*(64 - len(label) ) else: label = label + ' '*(64 - len(label) )
print time_str, " ", label, " ", v_str, " ", "%f"%b print time_str , " " + label + " " + format_satoshis(v)+ " "+ format_satoshis(b)
print "# balance: ", b print "# balance: ", format_satoshis(b)
elif cmd == 'label': elif cmd == 'label':
try: try:

View file

@ -28,12 +28,7 @@ from decimal import Decimal
gtk.gdk.threads_init() gtk.gdk.threads_init()
APP_NAME = "Electrum" APP_NAME = "Electrum"
def format_satoshis(x): from wallet import format_satoshis
s = str( Decimal(x) /100000000 )
if not '.' in s: s += '.'
p = s.find('.')
s += " "*( 9 - ( len(s) - p ))
return s
def numbify(entry, is_int = False): def numbify(entry, is_int = False):
text = entry.get_text().strip() text = entry.get_text().strip()
@ -1117,7 +1112,7 @@ class BitcoinGUI:
self.status_image.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU) self.status_image.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU)
self.network_button.set_tooltip_text("Trying to contact %s.\n%d blocks"%(self.wallet.interface.host, self.wallet.interface.blocks)) self.network_button.set_tooltip_text("Trying to contact %s.\n%d blocks"%(self.wallet.interface.host, self.wallet.interface.blocks))
text = "Balance: %s "%( format_satoshis(c) ) text = "Balance: %s "%( format_satoshis(c) )
if u: text += "[+ %s unconfirmed]"%( format_satoshis(u) ) if u: text += "[%s unconfirmed]"%( format_satoshis(u,True) )
if self.error: text = self.error if self.error: text = self.error
self.status_bar.pop(self.context_id) self.status_bar.pop(self.context_id)
self.status_bar.push(self.context_id, text) self.status_bar.push(self.context_id, text)
@ -1175,7 +1170,7 @@ class BitcoinGUI:
details+= "Outputs:\n-"+ '\n-'.join(tx['outputs']) details+= "Outputs:\n-"+ '\n-'.join(tx['outputs'])
self.history_list.prepend( [tx_hash, conf_icon, time_str, label, is_default_label, self.history_list.prepend( [tx_hash, conf_icon, time_str, label, is_default_label,
('+' if v>0 else '') + format_satoshis(v), format_satoshis(balance), tooltip, details] ) format_satoshis(v,True), format_satoshis(balance), tooltip, details] )
if cursor: self.history_treeview.set_cursor( cursor ) if cursor: self.history_treeview.set_cursor( cursor )

View file

@ -213,12 +213,22 @@ def raw_tx( inputs, outputs, for_sig = None ):
def format_satoshis(x, is_diff=False):
from decimal import Decimal
s = str( Decimal(x) /100000000 )
if is_diff and x>0:
s = "+" + s
if not '.' in s: s += '.'
p = s.find('.')
s += " "*( 9 - ( len(s) - p ))
s = " "*( 5 - ( p )) + s
return s
from version import ELECTRUM_VERSION, SEED_VERSION from version import ELECTRUM_VERSION, SEED_VERSION
class Wallet: class Wallet:
def __init__(self, interface): def __init__(self, interface):