start wallet threads from wallet class

This commit is contained in:
ThomasV 2013-09-01 18:44:19 +02:00
parent d47892b690
commit 046ec58d24
4 changed files with 33 additions and 48 deletions

View File

@ -201,13 +201,11 @@ if __name__ == '__main__':
if not interface.start(wait=True):
print_msg("Not connected, aborting. Try option -o if you want to restore offline.")
sys.exit(1)
wallet.interface = interface
verifier = WalletVerifier(interface, config)
verifier.start()
wallet.set_verifier(verifier)
blockchain = BlockchainVerifier(interface, config)
blockchain.start()
wallet.start_threads(interface, blockchain)
print_msg("Recovering wallet...")
WalletSynchronizer(wallet).start()
wallet.update()
if wallet.is_found():
print_msg("Recovery successful")
@ -327,15 +325,13 @@ if __name__ == '__main__':
if cmd not in offline_commands and not options.offline:
interface = Interface(config)
interface.register_callback('connected', lambda: sys.stderr.write("Connected to " + interface.connection_msg + "\n"))
if not interface.start(wait=True):
print_msg("Not connected, aborting.")
sys.exit(1)
wallet.interface = interface
verifier = WalletVerifier(interface, config)
verifier.start()
wallet.set_verifier(verifier)
synchronizer = WalletSynchronizer(wallet)
synchronizer.start()
blockchain = BlockchainVerifier(interface, config)
blockchain.start()
wallet.start_threads(interface, blockchain)
wallet.update()
@ -395,8 +391,8 @@ if __name__ == '__main__':
if cmd not in offline_commands and not options.offline:
verifier.stop()
synchronizer.stop()
wallet.stop_threads()
interface.stop()
blockchain.stop()
time.sleep(0.1)
sys.exit(0)

View File

@ -42,8 +42,8 @@ except:
from electrum.wallet import format_satoshis
from electrum.bitcoin import Transaction, is_valid
from electrum import mnemonic
from electrum import util, bitcoin, commands, Interface, Wallet, TxVerifier, WalletSynchronizer
from electrum import SimpleConfig, Wallet, WalletSynchronizer, WalletStorage
from electrum import util, bitcoin, commands, Interface, Wallet
from electrum import SimpleConfig, Wallet, WalletStorage
import bmp, pyqrnative
@ -351,20 +351,11 @@ class ElectrumWindow(QMainWindow):
interface = self.wallet.interface
blockchain = self.wallet.verifier.blockchain
self.wallet.verifier.stop()
self.wallet.synchronizer.stop()
self.wallet.stop_threads()
# create wallet
# create new wallet
wallet = Wallet(storage)
wallet.interface = interface
verifier = TxVerifier(interface, blockchain, storage)
verifier.start()
wallet.set_verifier(verifier)
synchronizer = WalletSynchronizer(wallet)
synchronizer.start()
wallet.start_threads(interface, blockchain)
self.load_wallet(wallet)
@ -2237,14 +2228,7 @@ class ElectrumGui:
else:
wallet = Wallet(storage)
wallet.interface = self.interface
verifier = TxVerifier(self.interface, self.blockchain, storage)
verifier.start()
wallet.set_verifier(verifier)
synchronizer = WalletSynchronizer(wallet)
synchronizer.start()
wallet.start_threads(self.interface, self.blockchain)
s = Timer()
s.start()
@ -2260,7 +2244,6 @@ class ElectrumGui:
self.app.exec_()
verifier.stop()
synchronizer.stop()
wallet.stop_threads()

View File

@ -5,14 +5,14 @@ _ = lambda x:x
from electrum.util import format_satoshis, set_verbosity
from electrum.bitcoin import is_valid
from electrum import Wallet, WalletVerifier, WalletSynchronizer, WalletStorage
from electrum import Wallet, WalletStorage
import tty, sys
class ElectrumGui:
def __init__(self, config, interface):
def __init__(self, config, interface, blockchain):
self.config = config
storage = WalletStorage(config)
@ -20,15 +20,8 @@ class ElectrumGui:
print "Wallet not found. try 'electrum create'"
exit()
wallet = Wallet(storage)
wallet.interface = interface
self.wallet = wallet
verifier = WalletVerifier(interface, config)
verifier.start()
wallet.set_verifier(verifier)
synchronizer = WalletSynchronizer(wallet)
synchronizer.start()
self.wallet = Wallet(storage)
self.wallet.start_threads(interface, blockchain)
self.stdscr = curses.initscr()
curses.noecho()

View File

@ -1296,6 +1296,19 @@ class Wallet:
return True
def start_threads(self, interface, blockchain):
from verifier import TxVerifier
self.interface = interface
self.verifier = TxVerifier(interface, blockchain, self.storage)
self.verifier.start()
self.synchronizer = WalletSynchronizer(self)
self.synchronizer.start()
def stop_threads(self):
self.verifier.stop()
self.synchronizer.stop()
class WalletSynchronizer(threading.Thread):