time
This commit is contained in:
parent
182baaca4d
commit
cb84c62292
|
@ -254,6 +254,7 @@ class Wallet:
|
||||||
# not saved
|
# not saved
|
||||||
self.message = ''
|
self.message = ''
|
||||||
self.tx_history = {}
|
self.tx_history = {}
|
||||||
|
self.rtime = 0
|
||||||
|
|
||||||
def new_seed(self, password):
|
def new_seed(self, password):
|
||||||
seed = "%032x"%ecdsa.util.randrange( pow(2,128) )
|
seed = "%032x"%ecdsa.util.randrange( pow(2,128) )
|
||||||
|
@ -404,11 +405,14 @@ class Wallet:
|
||||||
unconf += u
|
unconf += u
|
||||||
return conf, unconf
|
return conf, unconf
|
||||||
|
|
||||||
|
def use_http(self):
|
||||||
|
return self.port in [80,8080]
|
||||||
|
|
||||||
def request(self, request ):
|
def request(self, request ):
|
||||||
|
import time
|
||||||
|
t1 = time.time()
|
||||||
|
|
||||||
use_http = self.port in [80,8080]
|
if self.use_http():
|
||||||
|
|
||||||
if use_http:
|
|
||||||
import httplib, urllib
|
import httplib, urllib
|
||||||
params = urllib.urlencode({'q':request})
|
params = urllib.urlencode({'q':request})
|
||||||
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
|
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
|
||||||
|
@ -419,7 +423,6 @@ class Wallet:
|
||||||
out = response.read()
|
out = response.read()
|
||||||
else: out = ''
|
else: out = ''
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
request += "#"
|
request += "#"
|
||||||
s = socket.socket( socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket( socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
@ -432,6 +435,7 @@ class Wallet:
|
||||||
else: break
|
else: break
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
|
self.rtime = time.time() - t1
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def retrieve_message(self):
|
def retrieve_message(self):
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import thread, time, ast, sys
|
import thread, time, ast, sys
|
||||||
|
import socket, traceback
|
||||||
import pygtk
|
import pygtk
|
||||||
pygtk.require('2.0')
|
pygtk.require('2.0')
|
||||||
import gtk, gobject
|
import gtk, gobject
|
||||||
|
@ -351,6 +352,7 @@ class BitcoinGUI:
|
||||||
def __init__(self, wallet):
|
def __init__(self, wallet):
|
||||||
self.error = ''
|
self.error = ''
|
||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
|
self.period = 5
|
||||||
|
|
||||||
self.update_time = 0
|
self.update_time = 0
|
||||||
self.window = MyWindow(gtk.WINDOW_TOPLEVEL)
|
self.window = MyWindow(gtk.WINDOW_TOPLEVEL)
|
||||||
|
@ -433,17 +435,18 @@ class BitcoinGUI:
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
def update_wallet_thread():
|
def update_wallet_thread():
|
||||||
import socket, traceback, sys
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
self.wallet.new_session()
|
self.wallet.new_session()
|
||||||
except:
|
except:
|
||||||
self.error = "Not connected"
|
self.error = "Not connected"
|
||||||
time.sleep(5)
|
time.sleep(self.period)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.info.set_text( self.wallet.message)
|
self.info.set_text( self.wallet.message)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
self.period = 15 if self.wallet.use_http() else 5
|
||||||
try:
|
try:
|
||||||
u = self.wallet.update()
|
u = self.wallet.update()
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
|
@ -459,7 +462,7 @@ class BitcoinGUI:
|
||||||
if u:
|
if u:
|
||||||
self.wallet.save()
|
self.wallet.save()
|
||||||
gobject.idle_add( self.update_history_tab )
|
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_wallet_thread, ())
|
||||||
thread.start_new_thread(update_status_bar_thread, ())
|
thread.start_new_thread(update_status_bar_thread, ())
|
||||||
|
@ -745,9 +748,9 @@ class BitcoinGUI:
|
||||||
def update_status_bar(self):
|
def update_status_bar(self):
|
||||||
c, u = self.wallet.get_balance()
|
c, u = self.wallet.get_balance()
|
||||||
dt = time.time() - self.update_time
|
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_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:
|
else:
|
||||||
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.status_image.set_tooltip_text("Trying to contact %s.\n%d blocks"%(self.wallet.host, self.wallet.blocks))
|
self.status_image.set_tooltip_text("Trying to contact %s.\n%d blocks"%(self.wallet.host, self.wallet.blocks))
|
||||||
|
|
Loading…
Reference in New Issue