1
0

Improved in network callbacks:

* Pass arguments
 * Don't redraw history when a tx is verified.
 * Fix new tx notifications.
This commit is contained in:
ThomasV
2015-08-16 11:35:39 +02:00
parent 438bc94dce
commit bfae04e6f0
6 changed files with 73 additions and 57 deletions

View File

@@ -40,7 +40,6 @@ class NetworkProxy(util.DaemonThread):
self.subscriptions = {}
self.debug = False
self.lock = threading.Lock()
self.pending_transactions_for_notifications = []
self.callbacks = {}
if socket:
@@ -100,7 +99,10 @@ class NetworkProxy(util.DaemonThread):
self.servers = value
elif key == 'interfaces':
self.interfaces = value
self.trigger_callback(key)
if key in ['status', 'updated']:
self.trigger_callback(key)
else:
self.trigger_callback(key, (value,))
return
msg_id = response.get('id')
@@ -227,8 +229,8 @@ class NetworkProxy(util.DaemonThread):
self.callbacks[event] = []
self.callbacks[event].append(callback)
def trigger_callback(self, event):
def trigger_callback(self, event, params=()):
with self.lock:
callbacks = self.callbacks.get(event,[])[:]
if callbacks:
[callback() for callback in callbacks]
[callback(*params) for callback in callbacks]

View File

@@ -126,16 +126,14 @@ class WalletSynchronizer():
except Exception:
self.print_msg("cannot deserialize transaction, skipping", tx_hash)
return
self.wallet.receive_tx_callback(tx_hash, tx, tx_height)
self.requested_tx.remove((tx_hash, tx_height))
self.print_error("received tx:", tx_hash, len(tx.raw))
# callbacks
self.network.trigger_callback('new_transaction', (tx,))
if not self.requested_tx:
self.network.trigger_callback('updated')
# Updated gets called too many times from other places as
# well; if we used that signal we get the notification
# three times
self.network.trigger_callback("new_transaction")
def request_missing_txs(self, hist):
# "hist" is a list of [tx_hash, tx_height] lists

View File

@@ -424,7 +424,9 @@ class Abstract_Wallet(object):
with self.lock:
self.verified_tx[tx_hash] = info # (tx_height, timestamp, pos)
self.storage.put('verified_tx3', self.verified_tx, True)
self.network.trigger_callback('updated')
conf, timestamp = self.get_confirmations(tx_hash)
self.network.trigger_callback('verified', (tx_hash, conf, timestamp))
def get_unverified_txs(self):
'''Returns a list of tuples (tx_hash, height) that are unverified and not beyond local height'''
@@ -771,12 +773,10 @@ class Abstract_Wallet(object):
def receive_tx_callback(self, tx_hash, tx, tx_height):
self.add_transaction(tx_hash, tx)
#self.network.pending_transactions_for_notifications.append(tx)
self.add_unverified_tx(tx_hash, tx_height)
def receive_history_callback(self, addr, hist):
with self.lock:
old_hist = self.history.get(addr, [])
for tx_hash, height in old_hist: