Browse Source

change 'new_transaction' notification to include wallet

3.3.3.1
SomberNight 6 years ago
parent
commit
a9197236a2
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 4
      electrum/gui/kivy/main_window.py
  2. 17
      electrum/gui/qt/main_window.py
  3. 2
      electrum/synchronizer.py

4
electrum/gui/kivy/main_window.py

@ -677,7 +677,9 @@ class ElectrumWindow(App):
elif event == 'status': elif event == 'status':
self._trigger_update_status() self._trigger_update_status()
elif event == 'new_transaction': elif event == 'new_transaction':
self._trigger_update_wallet() wallet, tx = args
if wallet == self.wallet:
self._trigger_update_wallet()
elif event == 'verified': elif event == 'verified':
self._trigger_update_wallet() self._trigger_update_wallet()

17
electrum/gui/qt/main_window.py

@ -300,9 +300,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
self.gui_object.network_updated_signal_obj.network_updated_signal \ self.gui_object.network_updated_signal_obj.network_updated_signal \
.emit(event, args) .emit(event, args)
elif event == 'new_transaction': elif event == 'new_transaction':
# FIXME maybe this event should also include which wallet wallet, tx = args
# the tx is for. now all wallets get this. if wallet == self.wallet:
self.tx_notification_queue.put(args[0]) self.tx_notification_queue.put(tx)
elif event in ['status', 'banner', 'verified', 'fee', 'fee_histogram']: elif event in ['status', 'banner', 'verified', 'fee', 'fee_histogram']:
# Handle in GUI thread # Handle in GUI thread
self.network_signal.emit(event, args) self.network_signal.emit(event, args)
@ -589,12 +589,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
def notify_transactions(self): def notify_transactions(self):
# note: during initial history sync for a wallet, many txns will be # note: during initial history sync for a wallet, many txns will be
# received multiple times. hence the "total amount received" will be # received multiple times. hence the "total amount received" can be
# a lot higher than should be. this is expected though not intended # a lot different than should be. this is expected though not intended
if self.tx_notification_queue.qsize() == 0: if self.tx_notification_queue.qsize() == 0:
return return
now = time.time() now = time.time()
if self.tx_notification_last_time + 5 > now: rate_limit = 20 # seconds
if self.tx_notification_last_time + rate_limit > now:
return return
self.tx_notification_last_time = now self.tx_notification_last_time = now
self.print_error("Notifying GUI about new transactions") self.print_error("Notifying GUI about new transactions")
@ -609,14 +610,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
total_amount = 0 total_amount = 0
for tx in txns: for tx in txns:
is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(tx) is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(tx)
if v > 0: if is_relevant:
total_amount += v total_amount += v
self.notify(_("{} new transactions received: Total amount received in the new transactions {}") self.notify(_("{} new transactions received: Total amount received in the new transactions {}")
.format(len(txns), self.format_amount_and_units(total_amount))) .format(len(txns), self.format_amount_and_units(total_amount)))
else: else:
for tx in txns: for tx in txns:
is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(tx) is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(tx)
if v > 0: if is_relevant:
self.notify(_("New transaction received: {}").format(self.format_amount_and_units(v))) self.notify(_("New transaction received: {}").format(self.format_amount_and_units(v)))
def notify(self, message): def notify(self, message):

2
electrum/synchronizer.py

@ -134,7 +134,7 @@ class Synchronizer(PrintError):
self.print_error("received tx %s height: %d bytes: %d" % self.print_error("received tx %s height: %d bytes: %d" %
(tx_hash, tx_height, len(tx.raw))) (tx_hash, tx_height, len(tx.raw)))
# callbacks # callbacks
self.wallet.network.trigger_callback('new_transaction', tx) self.wallet.network.trigger_callback('new_transaction', self.wallet, tx)
async def subscribe_to_address(self, addr): async def subscribe_to_address(self, addr):
h = address_to_scripthash(addr) h = address_to_scripthash(addr)

Loading…
Cancel
Save