Browse Source

wallet_db upgrade: fix possible corruption of invoice amounts

see https://github.com/spesmilo/electrum/pull/7774
patch-4
SomberNight 3 years ago
parent
commit
ed65f335bd
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/wallet.py
  2. 13
      electrum/wallet_db.py

2
electrum/wallet.py

@ -943,6 +943,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
amount_msat = '!'
break
else:
assert isinstance(x.value, int), f"{x.value!r}"
amount_msat += x.value * 1000
timestamp = None
exp = None
@ -2439,6 +2440,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
def create_request(self, amount_sat: int, message: str, exp_delay: int, address: str):
# for receiving
amount_sat = amount_sat or 0
assert isinstance(amount_sat, int), f"{amount_sat!r}"
exp_delay = exp_delay or 0
timestamp = int(time.time())
fallback_address = address if self.config.get('bolt11_fallback', True) else None

13
electrum/wallet_db.py

@ -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 = 47 # electrum >= 2.7 will set this to prevent
FINAL_SEED_VERSION = 48 # electrum >= 2.7 will set this to prevent
# old versions from overwriting new format
@ -196,6 +196,7 @@ class WalletDB(JsonDB):
self._convert_version_45()
self._convert_version_46()
self._convert_version_47()
self._convert_version_48()
self.put('seed_version', FINAL_SEED_VERSION) # just to be sure
self._after_upgrade_tasks()
@ -942,6 +943,16 @@ class WalletDB(JsonDB):
del requests[key]
self.data['seed_version'] = 47
def _convert_version_48(self):
# fix possible corruption of invoice amounts, see #7774
if not self._is_upgrade_method_needed(47, 47):
return
invoices = self.data.get('invoices', {})
for key, item in list(invoices.items()):
if item['amount_msat'] == 1000 * "!":
item['amount_msat'] = "!"
self.data['seed_version'] = 48
def _convert_imported(self):
if not self._is_upgrade_method_needed(0, 13):
return

Loading…
Cancel
Save