1
0

invoices: also run amount-validator on setter

- @amount_msat.validator prevents the creation of invoices with e.g. too large amounts
- however the qml gui is mutating invoices by directly setting the `amount_msat` field,
  and it looks like attrs validators only run during init.
  We can use `on_setattr` (introduced in attrs==20.1.0).
- a wallet db upgrade is added to rm existing insane invoices
- btw the qml gui was already doing its own input validation on the textedit
  (see qeconfig.btcAmountRegex). however that only limits the input to not have more
  chars than what is needed to represent 21M BTC (e.g. you can still enter 99M BTC,
  which the invoice logic does not tolerate later on - but is normally caught).

fixes https://github.com/spesmilo/electrum/issues/8582
This commit is contained in:
SomberNight
2023-08-22 18:10:21 +00:00
parent 7245762922
commit 4e6e6f76ca
4 changed files with 68 additions and 8 deletions

View File

@@ -54,7 +54,7 @@ from .version import ELECTRUM_VERSION
OLD_SEED_VERSION = 4 # electrum versions < 2.0
NEW_SEED_VERSION = 11 # electrum versions >= 2.0
FINAL_SEED_VERSION = 53 # electrum >= 2.7 will set this to prevent
FINAL_SEED_VERSION = 54 # electrum >= 2.7 will set this to prevent
# old versions from overwriting new format
@@ -239,6 +239,7 @@ class WalletDB(JsonDB):
self._convert_version_51()
self._convert_version_52()
self._convert_version_53()
self._convert_version_54()
self.put('seed_version', FINAL_SEED_VERSION) # just to be sure
self._after_upgrade_tasks()
@@ -1076,6 +1077,23 @@ class WalletDB(JsonDB):
cb['local_payment_pubkey'] = None
self.data['seed_version'] = 53
def _convert_version_54(self):
# note: similar to convert_version_38
if not self._is_upgrade_method_needed(53, 53):
return
from .bitcoin import TOTAL_COIN_SUPPLY_LIMIT_IN_BTC, COIN
max_sats = TOTAL_COIN_SUPPLY_LIMIT_IN_BTC * COIN
requests = self.data.get('payment_requests', {})
invoices = self.data.get('invoices', {})
for d in [invoices, requests]:
for key, item in list(d.items()):
amount_msat = item['amount_msat']
if amount_msat == '!':
continue
if not (isinstance(amount_msat, int) and 0 <= amount_msat <= max_sats * 1000):
del d[key]
self.data['seed_version'] = 54
def _convert_imported(self):
if not self._is_upgrade_method_needed(0, 13):
return