electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 0532264ff1986578a5780b07b4a62f6b0a98ecfe
parent a0a67221bb4c3e072b410d63d8a2ea28bff75942
Author: ThomasV <thomasv@gitorious>
Date:   Fri, 23 Mar 2012 18:30:06 +0100

start_interface method

Diffstat:
Mclient/electrum | 10++++------
Mclient/interface.py | 29+----------------------------
Mclient/wallet.py | 22++++++++++++++++++++++
3 files changed, 27 insertions(+), 34 deletions(-)

diff --git a/client/electrum b/client/electrum @@ -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() diff --git a/client/interface.py b/client/interface.py @@ -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) diff --git a/client/wallet.py b/client/wallet.py @@ -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)