1
0

Index request by ID instead of receiving address.

Replace get_key_for_outgoing_invoice, get_key_for_incoming_request
with Invoice.get_id()

When a new request is created, reuse addresses of expired requests (fixes #7927)

The API is changed for the following commands:
 get_request, get_invoice,
 list_requests, list_invoices,
 delete_request, delete_invoice
This commit is contained in:
ThomasV
2022-08-15 14:14:25 +02:00
parent 7d317761da
commit 14e96f4d53
11 changed files with 114 additions and 101 deletions

View File

@@ -880,21 +880,27 @@ class Commands:
return decrypted.decode('utf-8')
@command('w')
async def getrequest(self, key, wallet: Abstract_Wallet = None):
"""Return a payment request"""
r = wallet.get_request(key)
async def get_request(self, request_id, wallet: Abstract_Wallet = None):
"""Returns a payment request"""
r = wallet.get_request(request_id)
if not r:
raise Exception("Request not found")
return wallet.export_request(r)
@command('w')
async def get_invoice(self, invoice_id, wallet: Abstract_Wallet = None):
"""Returns an invoice (request for outgoing payment)"""
r = wallet.get_invoice(invoice_id)
if not r:
raise Exception("Request not found")
return wallet.export_invoice(r)
#@command('w')
#async def ackrequest(self, serialized):
# """<Not implemented>"""
# pass
@command('w')
async def list_requests(self, pending=False, expired=False, paid=False, wallet: Abstract_Wallet = None):
"""List the payment requests you made."""
def _filter_invoices(self, _list, wallet, pending, expired, paid):
if pending:
f = PR_UNPAID
elif expired:
@@ -903,11 +909,23 @@ class Commands:
f = PR_PAID
else:
f = None
out = wallet.get_sorted_requests()
if f is not None:
out = [req for req in out
if f == wallet.get_invoice_status(req)]
return [wallet.export_request(x) for x in out]
_list = [x for x in _list if f == wallet.get_invoice_status(x)]
return _list
@command('w')
async def list_requests(self, pending=False, expired=False, paid=False, wallet: Abstract_Wallet = None):
"""Returns the list of incoming payment requests saved in the wallet."""
l = wallet.get_sorted_requests()
l = self._filter_invoices(l, wallet, pending, expired, paid)
return [wallet.export_request(x) for x in l]
@command('w')
async def list_invoices(self, pending=False, expired=False, paid=False, wallet: Abstract_Wallet = None):
"""Returns the list of invoices (requests for outgoing payments) saved in the wallet."""
l = wallet.get_invoices()
l = self._filter_invoices(l, wallet, pending, expired, paid)
return [wallet.export_invoice(x) for x in l]
@command('w')
async def createnewaddress(self, wallet: Abstract_Wallet = None):
@@ -971,9 +989,14 @@ class Commands:
return tx.txid()
@command('w')
async def delete_request(self, address, wallet: Abstract_Wallet = None):
"""Remove a payment request"""
return wallet.delete_request(address)
async def delete_request(self, request_id, wallet: Abstract_Wallet = None):
"""Remove an incoming payment request"""
return wallet.delete_request(request_id)
@command('w')
async def delete_invoice(self, invoice_id, wallet: Abstract_Wallet = None):
"""Remove an outgoing payment invoice"""
return wallet.delete_invoice(invoice_id)
@command('w')
async def clear_requests(self, wallet: Abstract_Wallet = None):
@@ -1175,11 +1198,6 @@ class Commands:
if self.network.path_finder:
self.network.path_finder.liquidity_hints.reset_liquidity_hints()
@command('w')
async def list_invoices(self, wallet: Abstract_Wallet = None):
l = wallet.get_invoices()
return [wallet.export_invoice(x) for x in l]
@command('wnl')
async def close_channel(self, channel_point, force=False, wallet: Abstract_Wallet = None):
txid, index = channel_point.split(':')