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

@@ -52,7 +52,7 @@ if TYPE_CHECKING:
OLD_SEED_VERSION = 4 # electrum versions < 2.0
NEW_SEED_VERSION = 11 # electrum versions >= 2.0
FINAL_SEED_VERSION = 49 # electrum >= 2.7 will set this to prevent
FINAL_SEED_VERSION = 50 # electrum >= 2.7 will set this to prevent
# old versions from overwriting new format
@@ -198,6 +198,7 @@ class WalletDB(JsonDB):
self._convert_version_47()
self._convert_version_48()
self._convert_version_49()
self._convert_version_50()
self.put('seed_version', FINAL_SEED_VERSION) # just to be sure
self._after_upgrade_tasks()
@@ -904,17 +905,13 @@ class WalletDB(JsonDB):
}
self.data['seed_version'] = 45
def _convert_version_46(self):
from .crypto import sha256d
if not self._is_upgrade_method_needed(45, 45):
return
def _convert_invoices_keys(self, invoices):
# recalc keys of outgoing on-chain invoices
from .crypto import sha256d
def get_id_from_onchain_outputs(raw_outputs, timestamp):
outputs = [PartialTxOutput.from_legacy_tuple(*output) for output in raw_outputs]
outputs_str = "\n".join(f"{txout.scriptpubkey.hex()}, {txout.value}" for txout in outputs)
return sha256d(outputs_str + "%d" % timestamp).hex()[0:10]
invoices = self.data.get('invoices', {})
for key, item in list(invoices.items()):
is_lightning = item['lightning_invoice'] is not None
if is_lightning:
@@ -926,6 +923,12 @@ class WalletDB(JsonDB):
if newkey != key:
invoices[newkey] = item
del invoices[key]
def _convert_version_46(self):
if not self._is_upgrade_method_needed(45, 45):
return
invoices = self.data.get('invoices', {})
self._convert_invoices_keys(invoices)
self.data['seed_version'] = 46
def _convert_version_47(self):
@@ -970,6 +973,13 @@ class WalletDB(JsonDB):
)
self.data['seed_version'] = 49
def _convert_version_50(self):
if not self._is_upgrade_method_needed(49, 49):
return
requests = self.data.get('payment_requests', {})
self._convert_invoices_keys(requests)
self.data['seed_version'] = 50
def _convert_imported(self):
if not self._is_upgrade_method_needed(0, 13):
return