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

This commit is contained in:
root 2011-11-11 13:32:01 +03:00
commit c874890908
2 changed files with 16 additions and 9 deletions

View File

@ -254,6 +254,7 @@ class Wallet:
# not saved
self.message = ''
self.tx_history = {}
self.rtime = 0
def new_seed(self, password):
seed = "%032x"%ecdsa.util.randrange( pow(2,128) )
@ -404,11 +405,14 @@ class Wallet:
unconf += u
return conf, unconf
def use_http(self):
return self.port in [80,8080]
def request(self, request ):
import time
t1 = time.time()
use_http = self.port in [80,81]
if use_http:
if self.use_http():
import httplib, urllib
params = urllib.urlencode({'q':request})
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
@ -419,7 +423,6 @@ class Wallet:
out = response.read()
else: out = ''
conn.close()
else:
request += "#"
s = socket.socket( socket.AF_INET, socket.SOCK_STREAM)
@ -432,6 +435,7 @@ class Wallet:
else: break
s.close()
self.rtime = time.time() - t1
return out
def retrieve_message(self):

View File

@ -18,6 +18,7 @@
import datetime
import thread, time, ast, sys
import socket, traceback
import pygtk
pygtk.require('2.0')
import gtk, gobject
@ -351,6 +352,7 @@ class BitcoinGUI:
def __init__(self, wallet):
self.error = ''
self.wallet = wallet
self.period = 5
self.update_time = 0
self.window = MyWindow(gtk.WINDOW_TOPLEVEL)
@ -433,17 +435,18 @@ class BitcoinGUI:
time.sleep(0.5)
def update_wallet_thread():
import socket, traceback, sys
while True:
try:
self.wallet.new_session()
except:
self.error = "Not connected"
time.sleep(5)
time.sleep(self.period)
continue
self.info.set_text( self.wallet.message)
while True:
self.period = 15 if self.wallet.use_http() else 5
try:
u = self.wallet.update()
except socket.gaierror:
@ -459,7 +462,7 @@ class BitcoinGUI:
if u:
self.wallet.save()
gobject.idle_add( self.update_history_tab )
time.sleep(5)
time.sleep(self.period)
thread.start_new_thread(update_wallet_thread, ())
thread.start_new_thread(update_status_bar_thread, ())
@ -745,9 +748,9 @@ class BitcoinGUI:
def update_status_bar(self):
c, u = self.wallet.get_balance()
dt = time.time() - self.update_time
if dt < 15:
if dt < 2*self.period:
self.status_image.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU)
self.status_image.set_tooltip_text("Connected to %s.\n%d blocks"%(self.wallet.host, self.wallet.blocks))
self.status_image.set_tooltip_text("Connected to %s.\n%d blocks\nrequest time: %f"%(self.wallet.host, self.wallet.blocks, self.wallet.rtime))
else:
self.status_image.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU)
self.status_image.set_tooltip_text("Trying to contact %s.\n%d blocks"%(self.wallet.host, self.wallet.blocks))