Browse Source

wallet.get_request_URI: rm code duplication

patch-4
SomberNight 2 years ago
parent
commit
659d6890d9
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 3
      electrum/gui/qt/receive_tab.py
  2. 2
      electrum/gui/text.py
  3. 10
      electrum/invoices.py
  4. 19
      electrum/wallet.py

3
electrum/gui/qt/receive_tab.py

@ -221,8 +221,7 @@ class ReceiveTab(QWidget, MessageBoxMixin, Logger):
address_help = '' if addr else _('Amount too small to be received onchain')
URI_help = ''
lnaddr = req.lightning_invoice
bip21_lightning = lnaddr if self.config.get('bip21_lightning', False) else None
URI = req.get_bip21_URI(lightning=bip21_lightning)
URI = self.wallet.get_request_URI(req) or ''
lightning_online = self.wallet.lnworker and self.wallet.lnworker.num_peers() > 0
can_receive_lightning = self.wallet.lnworker and amount_sat <= self.wallet.lnworker.num_sats_can_receive()
has_expired = self.wallet.get_request_status(key) == PR_EXPIRED

2
electrum/gui/text.py

@ -853,7 +853,7 @@ class ElectrumGui(BaseElectrumGui, EventListener):
def show_request(self, key):
req = self.wallet.get_request(key)
addr = req.get_address() or ''
URI = req.get_bip21_URI()
URI = self.wallet.get_request_URI(req) or ''
lnaddr = req.lightning_invoice or ''
w = curses.newwin(self.maxy - 2, self.maxx - 2, 1, 1)
pos = 4

10
electrum/invoices.py

@ -155,7 +155,7 @@ class Invoice(StoredObject):
return amount_msat
return int(amount_msat // 1000)
def get_bip21_URI(self, lightning=None):
def get_bip21_URI(self, *, include_lightning: bool = False) -> Optional[str]:
from electrum.util import create_bip21_uri
addr = self.get_address()
amount = self.get_amount_sat()
@ -164,13 +164,15 @@ class Invoice(StoredObject):
message = self.message
extra = {}
if self.time and self.exp:
extra['time'] = str(self.time)
extra['exp'] = str(self.exp)
# only if we can receive
extra['time'] = str(int(self.time))
extra['exp'] = str(int(self.exp))
lightning = self.lightning_invoice if include_lightning else None
if lightning:
extra['lightning'] = lightning
if not addr and lightning:
return "bitcoin:?lightning="+lightning
if not addr and not lightning:
return None
uri = create_bip21_uri(addr, amount, message, extra_query_params=extra)
return str(uri)

19
electrum/wallet.py

@ -2290,22 +2290,9 @@ class Abstract_Wallet(ABC, Logger, EventListener):
def delete_address(self, address: str) -> None:
raise Exception("this wallet cannot delete addresses")
def get_request_URI(self, req: Invoice) -> str:
# todo: should be a method of invoice?
addr = req.get_address()
message = self.get_label_for_address(addr)
amount = req.get_amount_sat()
extra_query_params = {}
if req.time and req.exp:
extra_query_params['time'] = str(int(req.time))
extra_query_params['exp'] = str(int(req.exp))
#if req.get('name') and req.get('sig'):
# sig = bfh(req.get('sig'))
# sig = bitcoin.base_encode(sig, base=58)
# extra_query_params['name'] = req['name']
# extra_query_params['sig'] = sig
uri = create_bip21_uri(addr, amount, message, extra_query_params=extra_query_params)
return str(uri)
def get_request_URI(self, req: Invoice) -> Optional[str]:
include_lightning = bool(self.config.get('bip21_lightning', False))
return req.get_bip21_URI(include_lightning=include_lightning)
def check_expired_status(self, r: Invoice, status):
#if r.is_lightning() and r.exp == 0:

Loading…
Cancel
Save