start_interface method

This commit is contained in:
ThomasV 2012-03-23 18:30:06 +01:00
parent a0a67221bb
commit 0532264ff1
3 changed files with 27 additions and 34 deletions

View File

@ -25,7 +25,7 @@ from decimal import Decimal
import thread
from wallet import format_satoshis
from interface import loop_interfaces_thread, new_interface
from interface import loop_interfaces_thread
known_commands = ['help', 'validateaddress', 'balance', 'contacts', 'create', 'restore', 'payto', 'sendtx', 'password', 'addresses', 'history', 'label', 'mktx','seed','import','signmessage','verifymessage','eval']
offline_commands = ['password', 'mktx', 'history', 'label', 'contacts', 'help', 'validateaddress', 'signmessage', 'verifymessage', 'eval', 'create', 'addresses', 'import', 'seed']
@ -50,7 +50,6 @@ if __name__ == '__main__':
wallet.set_path(options.wallet_path)
wallet.read()
wallet.remote_url = options.remote_url
interface = wallet.interface = new_interface(wallet)
if len(args)==0:
url = None
@ -71,13 +70,14 @@ if __name__ == '__main__':
print "unknown gui", options.gui
exit(1)
thread.start_new_thread(loop_interfaces_thread, (wallet,))
gui = gui.ElectrumGui(wallet)
thread.start_new_thread(loop_interfaces_thread, (wallet,))
try:
found = wallet.file_exists
if not found:
found = gui.restore_or_create()
except BaseException, e:
import traceback
traceback.print_exc(file=sys.stdout)
@ -165,9 +165,7 @@ if __name__ == '__main__':
# open session
if cmd not in offline_commands:
addresses = wallet.all_addresses()
version = wallet.electrum_version
interface.start_session(addresses, version)
wallet.start_interface()
thread.start_new_thread(wallet.run, ())
wallet.update()
wallet.save()

View File

@ -338,38 +338,13 @@ class AsynchronousInterface(Interface):
def new_interface(wallet):
if wallet.host:
host = wallet.host
else:
host = random.choice( DEFAULT_SERVERS ) # random choice when the wallet is created
port = wallet.port
if port == 50000:
InterfaceClass = NativeInterface
elif port == 50001:
InterfaceClass = AsynchronousInterface
elif port in [80, 81, 8080, 8081]:
InterfaceClass = HttpInterface
else:
print "unknown port number: %d. using native protocol."%port
InterfaceClass = NativeInterface
interface = InterfaceClass(host, port)
return interface
def loop_interfaces_thread(wallet):
while True:
interface = wallet.interface
try:
addresses = wallet.all_addresses()
version = wallet.electrum_version
interface.start_session(addresses, version)
wallet.start_interface()
wallet.run()
print "Disconnected"
except socket.error:
print "socket error"
@ -379,5 +354,3 @@ def loop_interfaces_thread(wallet):
time.sleep(5)
continue
print "Starting new session: %s:%d"%(wallet.host,wallet.port)
wallet.interface = new_interface(wallet)

View File

@ -1002,3 +1002,25 @@ class Wallet:
response = self.interface.responses.get()
self.handle_response(response)
def start_interface(self):
from interface import NativeInterface, AsynchronousInterface, HttpInterface, DEFAULT_SERVERS
import random
if not self.host:
self.host = random.choice( DEFAULT_SERVERS ) # random choice when the wallet is created
if self.port == 50000:
InterfaceClass = NativeInterface
elif self.port == 50001:
InterfaceClass = AsynchronousInterface
elif self.port in [80, 81, 8080, 8081]:
InterfaceClass = HttpInterface
else:
print "unknown port number: %d. using native protocol."%self.port
InterfaceClass = NativeInterface
self.interface = InterfaceClass(self.host, self.port)
addresses = self.all_addresses()
version = self.electrum_version
self.interface.start_session(addresses, version)
print "Starting new session: %s:%d"%(self.host,self.port)