Browse Source

start wallet threads from wallet class

283
ThomasV 11 years ago
parent
commit
046ec58d24
  1. 22
      electrum
  2. 31
      gui/gui_classic.py
  3. 15
      gui/gui_text.py
  4. 13
      lib/wallet.py

22
electrum

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

31
gui/gui_classic.py

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

15
gui/gui_text.py

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

13
lib/wallet.py

@ -1296,6 +1296,19 @@ class Wallet:
return True 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): class WalletSynchronizer(threading.Thread):

Loading…
Cancel
Save