tPass wallet to invoice_status/request_status (#6595) - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 6bd1a04aee3d1adc052731793e7ebfb5023f7f56 DIR parent ddc94197aa6888e7d32846fd10479ec660125780 HTML Author: MrNaif2018 <39452697+MrNaif2018@users.noreply.github.com> Date: Fri, 18 Sep 2020 20:28:51 +0300 Pass wallet to invoice_status/request_status (#6595) * Pass wallet to invoice_status/request_status * Check for same wallet in qt gui Co-authored-by: ghost43 <somber.night@protonmail.com> Diffstat: M electrum/daemon.py | 2 +- M electrum/gui/kivy/main_window.py | 4 ++-- M electrum/gui/qt/main_window.py | 8 ++++++-- M electrum/lnworker.py | 12 ++++++------ M electrum/wallet.py | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) --- DIR diff --git a/electrum/daemon.py b/electrum/daemon.py t@@ -318,7 +318,7 @@ class PayServer(Logger): # FIXME specify wallet somehow? return list(self.daemon.get_wallets().values())[0] - async def on_payment(self, evt, key, status): + async def on_payment(self, evt, wallet, key, status): if status == PR_PAID: self.pending[key].set() DIR diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py t@@ -249,7 +249,7 @@ class ElectrumWindow(App): def on_fee_histogram(self, *args): self._trigger_update_history() - def on_request_status(self, event, key, status): + def on_request_status(self, event, wallet, key, status): if key not in self.wallet.receive_requests: return self.update_tab('receive') t@@ -259,7 +259,7 @@ class ElectrumWindow(App): self.show_info(_('Payment Received') + '\n' + key) self._trigger_update_history() - def on_invoice_status(self, event, key): + def on_invoice_status(self, event, wallet, key): req = self.wallet.get_invoice(key) if req is None: return DIR diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py t@@ -1513,14 +1513,18 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): self.wallet.thread.add(task) self.invoice_list.update() - def on_request_status(self, key, status): + def on_request_status(self, wallet, key, status): + if wallet != self.wallet: + return if key not in self.wallet.receive_requests: return if status == PR_PAID: self.notify(_('Payment received') + '\n' + key) self.need_update.set() - def on_invoice_status(self, key): + def on_invoice_status(self, wallet, key): + if wallet != self.wallet: + return req = self.wallet.get_invoice(key) if req is None: return DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py t@@ -891,10 +891,10 @@ class LNWallet(LNWorker): # note: path-finding runs in a separate thread so that we don't block the asyncio loop # graph updates might occur during the computation self.set_invoice_status(key, PR_ROUTING) - util.trigger_callback('invoice_status', key) + util.trigger_callback('invoice_status', self.wallet, key) route = await run_in_thread(partial(self._create_route_from_invoice, lnaddr, full_path=full_path)) self.set_invoice_status(key, PR_INFLIGHT) - util.trigger_callback('invoice_status', key) + util.trigger_callback('invoice_status', self.wallet, key) payment_attempt_log = await self._pay_to_route(route, lnaddr) except Exception as e: log.append(PaymentAttemptLog(success=False, exception=e)) t@@ -907,7 +907,7 @@ class LNWallet(LNWorker): break else: reason = _('Failed after {} attempts').format(attempts) - util.trigger_callback('invoice_status', key) + util.trigger_callback('invoice_status', self.wallet, key) if success: util.trigger_callback('payment_succeeded', self.wallet, key) else: t@@ -1247,7 +1247,7 @@ class LNWallet(LNWorker): else: chan.logger.info('received unexpected payment_failed, probably from previous session') key = payment_hash.hex() - util.trigger_callback('invoice_status', key) + util.trigger_callback('invoice_status', self.wallet, key) util.trigger_callback('payment_failed', self.wallet, key, '') util.trigger_callback('ln_payment_failed', payment_hash, chan.channel_id) t@@ -1263,13 +1263,13 @@ class LNWallet(LNWorker): else: chan.logger.info('received unexpected payment_sent, probably from previous session') key = payment_hash.hex() - util.trigger_callback('invoice_status', key) + util.trigger_callback('invoice_status', self.wallet, key) util.trigger_callback('payment_succeeded', self.wallet, key) util.trigger_callback('ln_payment_completed', payment_hash, chan.channel_id) def payment_received(self, chan, payment_hash: bytes): self.set_payment_status(payment_hash, PR_PAID) - util.trigger_callback('request_status', payment_hash.hex(), PR_PAID) + util.trigger_callback('request_status', self.wallet, payment_hash.hex(), PR_PAID) util.trigger_callback('ln_payment_completed', payment_hash, chan.channel_id) async def _calc_routing_hints_for_invoice(self, amount_sat: Optional[int]): DIR diff --git a/electrum/wallet.py b/electrum/wallet.py t@@ -1788,7 +1788,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC): addr = self.get_txout_address(txo) if addr in self.receive_requests: status = self.get_request_status(addr) - util.trigger_callback('request_status', addr, status) + util.trigger_callback('request_status', self, addr, status) def make_payment_request(self, address, amount_sat, message, expiration): # TODO maybe merge with wallet.create_invoice()...