Browse Source

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>
patch-4
MrNaif2018 4 years ago
committed by GitHub
parent
commit
6bd1a04aee
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      electrum/daemon.py
  2. 4
      electrum/gui/kivy/main_window.py
  3. 8
      electrum/gui/qt/main_window.py
  4. 12
      electrum/lnworker.py
  5. 2
      electrum/wallet.py

2
electrum/daemon.py

@ -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()

4
electrum/gui/kivy/main_window.py

@ -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')
@ -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

8
electrum/gui/qt/main_window.py

@ -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

12
electrum/lnworker.py

@ -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))
@ -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:
@ -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)
@ -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]):

2
electrum/wallet.py

@ -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()...

Loading…
Cancel
Save