wallet_db: rm dependence on PaymentRequest class in convert_version_25
Change convert_version_25 to delete invoices instead of converting them. convert_version_25 was released ~2 years ago. Wallet files not opened since will have old bip70 invoices deleted upon upgrading. In general it is ~unsafe for convert_version_* to depend on other modules of the code. (using e.g. sha256 is fine as its API will never change, but using e.g. PaymentRequest is dangerous as its API might change over time)
This commit is contained in:
@@ -121,7 +121,7 @@ async def get_payment_request(url: str) -> 'PaymentRequest':
|
||||
|
||||
class PaymentRequest:
|
||||
|
||||
def __init__(self, data, *, error=None):
|
||||
def __init__(self, data: bytes, *, error=None):
|
||||
self.raw = data
|
||||
self.error = error # FIXME overloaded and also used when 'verify' succeeds
|
||||
self.parse(data)
|
||||
@@ -131,7 +131,7 @@ class PaymentRequest:
|
||||
def __str__(self):
|
||||
return str(self.raw)
|
||||
|
||||
def parse(self, r):
|
||||
def parse(self, r: bytes):
|
||||
self.outputs = [] # type: List[PartialTxOutput]
|
||||
if self.error:
|
||||
return
|
||||
|
||||
@@ -42,7 +42,6 @@ from .lnutil import ImportedChannelBackupStorage, OnchainChannelBackupStorage
|
||||
from .lnutil import ChannelConstraints, Outpoint, ShachainElement
|
||||
from .json_db import StoredDict, JsonDB, locked, modifier
|
||||
from .plugin import run_hook, plugin_loaders
|
||||
from .paymentrequest import PaymentRequest
|
||||
from .submarine_swaps import SwapData
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -559,6 +558,7 @@ class WalletDB(JsonDB):
|
||||
self.data['seed_version'] = 24
|
||||
|
||||
def _convert_version_25(self):
|
||||
from .crypto import sha256
|
||||
if not self._is_upgrade_method_needed(24, 24):
|
||||
return
|
||||
# add 'type' field to onchain requests
|
||||
@@ -575,25 +575,15 @@ class WalletDB(JsonDB):
|
||||
'time': r.get('time'),
|
||||
'type': PR_TYPE_ONCHAIN,
|
||||
}
|
||||
# convert bip70 invoices
|
||||
# delete bip70 invoices
|
||||
# note: this upgrade was changed ~2 years after-the-fact to delete instead of converting
|
||||
invoices = self.data.get('invoices', {})
|
||||
for k, r in list(invoices.items()):
|
||||
data = r.get("hex")
|
||||
if data:
|
||||
pr = PaymentRequest(bytes.fromhex(data))
|
||||
if pr.id != k:
|
||||
continue
|
||||
invoices[k] = {
|
||||
'type': PR_TYPE_ONCHAIN,
|
||||
'amount': pr.get_amount(),
|
||||
'bip70': data,
|
||||
'exp': pr.get_expiration_date() - pr.get_time(),
|
||||
'id': pr.id,
|
||||
'message': pr.get_memo(),
|
||||
'outputs': [x.to_legacy_tuple() for x in pr.get_outputs()],
|
||||
'time': pr.get_time(),
|
||||
'requestor': pr.get_requestor(),
|
||||
}
|
||||
pr_id = sha256(bytes.fromhex(data))[0:16].hex()
|
||||
if pr_id != k:
|
||||
continue
|
||||
del invoices[k]
|
||||
self.data['seed_version'] = 25
|
||||
|
||||
def _convert_version_26(self):
|
||||
|
||||
Reference in New Issue
Block a user