Browse Source

wallet: use height to determine request status (similar to outgoing invoices)

patch-4
ThomasV 4 years ago
parent
commit
43614af2c4
  1. 20
      electrum/wallet.py

20
electrum/wallet.py

@ -1737,13 +1737,19 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
def delete_address(self, address: str) -> None: def delete_address(self, address: str) -> None:
raise Exception("this wallet cannot delete addresses") raise Exception("this wallet cannot delete addresses")
def get_payment_status(self, address, amount): def get_onchain_request_status(self, r):
address = r.get_address()
amount = r.get_amount_sat()
received, sent = self.get_addr_io(address) received, sent = self.get_addr_io(address)
l = [] l = []
for txo, x in received.items(): for txo, x in received.items():
h, v, is_cb = x h, v, is_cb = x
txid, n = txo.split(':') txid, n = txo.split(':')
conf = self.get_tx_height(txid).conf tx_height = self.get_tx_height(txid)
height = tx_height.height
if height > 0 and height <= r.height:
continue
conf = tx_height.conf
l.append((conf, v)) l.append((conf, v))
vsum = 0 vsum = 0
for conf, v in reversed(sorted(l)): for conf, v in reversed(sorted(l)):
@ -1792,7 +1798,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
status = self.lnworker.get_payment_status(bfh(r.rhash)) if self.lnworker else PR_UNKNOWN status = self.lnworker.get_payment_status(bfh(r.rhash)) if self.lnworker else PR_UNKNOWN
else: else:
assert isinstance(r, OnchainInvoice) assert isinstance(r, OnchainInvoice)
paid, conf = self.get_payment_status(r.get_address(), r.get_amount_sat()) paid, conf = self.get_onchain_request_status(r)
status = PR_PAID if paid else PR_UNPAID status = PR_PAID if paid else PR_UNPAID
return self.check_expired_status(r, status) return self.check_expired_status(r, status)
@ -1832,11 +1838,9 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
d['can_receive'] = self.lnworker.can_receive_invoice(x) d['can_receive'] = self.lnworker.can_receive_invoice(x)
else: else:
assert isinstance(x, OnchainInvoice) assert isinstance(x, OnchainInvoice)
amount_sat = x.get_amount_sat() paid, conf = self.get_onchain_request_status(x)
addr = x.get_address() d['amount_sat'] = x.get_amount_sat()
paid, conf = self.get_payment_status(addr, amount_sat) d['address'] = x.get_address()
d['amount_sat'] = amount_sat
d['address'] = addr
d['URI'] = self.get_request_URI(x) d['URI'] = self.get_request_URI(x)
if conf is not None: if conf is not None:
d['confirmations'] = conf d['confirmations'] = conf

Loading…
Cancel
Save