electrum

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

commit 0b76e16d04dd28fbda32b2855dfe8cb9b8a4953a
parent 82531131ee6c0d588a3425ac16714f08d6399f45
Author: thomasv <thomasv@gitorious>
Date:   Mon, 22 Oct 2012 13:43:58 +0200

allow multiple callbacks for a given name

Diffstat:
Melectrum | 6++----
Mlib/gui_lite.py | 2++
Mlib/interface.py | 12++++++------
Mlib/wallet.py | 13+++++++++----
4 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/electrum b/electrum @@ -185,15 +185,13 @@ if __name__ == '__main__': sys.exit("Error: Unknown GUI: " + pref_gui ) interface = Interface(config, True) - interface.start() wallet.interface = interface - gui = gui.ElectrumGui(wallet, config) interface.register_callback('peers', gui.server_list_changed) - # need to wait until interface is connected.. + + interface.start() WalletSynchronizer(wallet, config).start() WalletVerifier(wallet, config).start() - try: found = config.wallet_file_exists diff --git a/lib/gui_lite.py b/lib/gui_lite.py @@ -801,6 +801,8 @@ class MiniDriver(QObject): self.window = window self.wallet.interface.register_callback('updated',self.update_callback) + self.wallet.interface.register_callback('connected', self.update_callback) + self.wallet.interface.register_callback('disconnected', self.update_callback) self.state = None diff --git a/lib/interface.py b/lib/interface.py @@ -49,15 +49,15 @@ class Interface(threading.Thread): def register_callback(self, event, callback): with self.lock: - self.callbacks[event] = callback + if not self.callbacks.get(event): + self.callbacks[event] = [] + self.callbacks[event].append(callback) def trigger_callback(self, event): with self.lock: - callback = self.callbacks.get(event) - if callback: - callback() - - + callbacks = self.callbacks.get(event,[])[:] + if callbacks: + [callback() for callback in callbacks] def init_server(self, host, port, proxy=None, use_ssl=True): self.host = host diff --git a/lib/wallet.py b/lib/wallet.py @@ -844,9 +844,6 @@ class WalletSynchronizer(threading.Thread): self.wallet.up_to_date = False self.wallet.was_updated = True - if self.wallet.was_updated: - self.interface.trigger_callback('updated') - self.wallet.was_updated = False def subscribe_to_addresses(self, addresses): @@ -868,6 +865,10 @@ class WalletSynchronizer(threading.Thread): # 1. send new requests self.synchronize_wallet() + if self.wallet.was_updated: + self.interface.trigger_callback('updated') + self.wallet.was_updated = False + # 2. get a response r = self.interface.get_response('synchronizer') if not r: continue @@ -918,11 +919,15 @@ class WalletSynchronizer(threading.Thread): elif method == 'server.banner': self.wallet.banner = result - self.interface.trigger_callback('updated') + self.wallet.was_updated = True else: print_error("Error: Unknown message:" + method + ", " + repr(params) + ", " + repr(result) ) + if self.wallet.was_updated: + self.interface.trigger_callback('updated') + self.wallet.was_updated = False + encode = lambda x: x[::-1].encode('hex') decode = lambda x: x.decode('hex')[::-1]