|
|
@ -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: |
|
|
@ -53,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 = 45 # electrum >= 2.7 will set this to prevent |
|
|
|
FINAL_SEED_VERSION = 46 # electrum >= 2.7 will set this to prevent |
|
|
|
# old versions from overwriting new format |
|
|
|
|
|
|
|
|
|
|
@ -194,6 +193,7 @@ class WalletDB(JsonDB): |
|
|
|
self._convert_version_43() |
|
|
|
self._convert_version_44() |
|
|
|
self._convert_version_45() |
|
|
|
self._convert_version_46() |
|
|
|
self.put('seed_version', FINAL_SEED_VERSION) # just to be sure |
|
|
|
|
|
|
|
self._after_upgrade_tasks() |
|
|
@ -558,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 |
|
|
@ -574,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): |
|
|
@ -908,6 +899,30 @@ 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 |
|
|
|
# recalc keys of outgoing on-chain invoices |
|
|
|
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: |
|
|
|
continue |
|
|
|
outputs_raw = item['outputs'] |
|
|
|
assert outputs_raw, outputs_raw |
|
|
|
timestamp = item['time'] |
|
|
|
newkey = get_id_from_onchain_outputs(outputs_raw, timestamp) |
|
|
|
if newkey != key: |
|
|
|
invoices[newkey] = item |
|
|
|
del invoices[key] |
|
|
|
self.data['seed_version'] = 46 |
|
|
|
|
|
|
|
def _convert_imported(self): |
|
|
|
if not self._is_upgrade_method_needed(0, 13): |
|
|
|
return |
|
|
|