electrum

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

commit 9c7a3c83293e71f00dcef4d76a6028fbec19df84
parent c9c5c0d3bdd334c54d517ffd48aae75ff4f8bd0c
Author: thomasv <thomasv@gitorious>
Date:   Fri,  4 May 2012 09:28:44 +0200

simplification

Diffstat:
Minterface.py | 11++++-------
Mwallet.py | 19++-----------------
2 files changed, 6 insertions(+), 24 deletions(-)

diff --git a/interface.py b/interface.py @@ -51,7 +51,7 @@ class Interface(threading.Thread): #json self.message_id = 0 self.responses = Queue.Queue() - self.methods = {} + self.unanswered_requests = {} def poke(self): # push a fake response so that the getting thread exits its loop @@ -68,7 +68,7 @@ class Interface(threading.Thread): return if msg_id is not None: - method, params = self.methods.pop(msg_id) + method, params = self.unanswered_requests.pop(msg_id) result = c.get('result') else: # notification @@ -163,7 +163,7 @@ class HttpStratumInterface(PollingInterface): method, params = m if type(params) != type([]): params = [params] data.append( { 'method':method, 'id':self.message_id, 'params':params } ) - self.methods[self.message_id] = method, params + self.unanswered_requests[self.message_id] = method, params self.message_id += 1 if data: @@ -256,7 +256,7 @@ class TcpStratumInterface(Interface): for m in messages: method, params = m request = json.dumps( { 'id':self.message_id, 'method':method, 'params':params } ) - self.methods[self.message_id] = method, params + self.unanswered_requests[self.message_id] = method, params #print "-->",request self.message_id += 1 out += request + '\n' @@ -362,9 +362,6 @@ class WalletSynchronizer(threading.Thread): new_addresses = self.wallet.synchronize() if new_addresses: self.interface.subscribe(new_addresses) - for addr in new_addresses: - with self.wallet.lock: - self.wallet.addresses_waiting_for_status.append(addr) if self.wallet.is_up_to_date(): if not self.wallet.up_to_date: diff --git a/wallet.py b/wallet.py @@ -283,9 +283,6 @@ class Wallet: self.lock = threading.Lock() self.tx_event = threading.Event() - # - self.addresses_waiting_for_status = [] - self.addresses_waiting_for_history = [] self.pick_random_server() @@ -294,8 +291,7 @@ class Wallet: self.server = random.choice( DEFAULT_SERVERS ) # random choice when the wallet is created def is_up_to_date(self): - return self.interface.responses.empty() and not ( self.addresses_waiting_for_status or self.addresses_waiting_for_history ) - + return self.interface.responses.empty() and not self.interface.unanswered_requests def set_server(self, server): # raise an error if the format isnt correct @@ -719,10 +715,7 @@ class Wallet: with self.lock: if self.get_status(addr) != status: #print "updating status for", addr, status - self.addresses_waiting_for_history.append(addr) self.interface.get_history(addr) - if addr in self.addresses_waiting_for_status: - self.addresses_waiting_for_status.remove(addr) def receive_history_callback(self, addr, data): #print "updating history for", addr @@ -730,7 +723,6 @@ class Wallet: self.history[addr] = data self.update_tx_history() self.save() - if addr in self.addresses_waiting_for_history: self.addresses_waiting_for_history.remove(addr) def get_tx_history(self): lines = self.tx_history.values() @@ -953,15 +945,8 @@ class Wallet: def start_session(self, interface): self.interface = interface - with self.lock: - self.addresses_waiting_for_status = [] - self.addresses_waiting_for_history = [] - addresses = self.all_addresses() - for addr in addresses: - self.addresses_waiting_for_status.append(addr) - self.interface.send([('server.banner',[]), ('blockchain.numblocks.subscribe',[]), ('server.peers.subscribe',[])]) - self.interface.subscribe(addresses) + self.interface.subscribe(self.all_addresses())