1
0

LN invoices: support msat precision

fixes #6250
This commit is contained in:
SomberNight
2020-06-22 22:37:58 +02:00
parent 599797c966
commit d5f368c584
19 changed files with 260 additions and 135 deletions

View File

@@ -33,7 +33,7 @@ import binascii
from . import util, bitcoin
from .util import profiler, WalletFileException, multisig_type, TxMinedInfo, bfh
from .invoices import PR_TYPE_ONCHAIN, invoice_from_json
from .invoices import PR_TYPE_ONCHAIN, Invoice
from .keystore import bip44_derivation
from .transaction import Transaction, TxOutpoint, tx_from_any, PartialTransaction, PartialTxOutput
from .logging import Logger
@@ -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 = 29 # electrum >= 2.7 will set this to prevent
FINAL_SEED_VERSION = 30 # electrum >= 2.7 will set this to prevent
# old versions from overwriting new format
@@ -177,6 +177,7 @@ class WalletDB(JsonDB):
self._convert_version_27()
self._convert_version_28()
self._convert_version_29()
self._convert_version_30()
self.put('seed_version', FINAL_SEED_VERSION) # just to be sure
self._after_upgrade_tasks()
@@ -643,6 +644,29 @@ class WalletDB(JsonDB):
d[key] = item
self.data['seed_version'] = 29
def _convert_version_30(self):
if not self._is_upgrade_method_needed(29, 29):
return
from .invoices import PR_TYPE_ONCHAIN, PR_TYPE_LN
requests = self.data.get('payment_requests', {})
invoices = self.data.get('invoices', {})
for d in [invoices, requests]:
for key, item in list(d.items()):
_type = item['type']
if _type == PR_TYPE_ONCHAIN:
item['amount_sat'] = item.pop('amount')
elif _type == PR_TYPE_LN:
amount_sat = item.pop('amount')
item['amount_msat'] = 1000 * amount_sat if amount_sat is not None else None
item.pop('exp')
item.pop('message')
item.pop('rhash')
item.pop('time')
else:
raise Exception(f"unknown invoice type: {_type}")
self.data['seed_version'] = 30
def _convert_imported(self):
if not self._is_upgrade_method_needed(0, 13):
return
@@ -1127,9 +1151,9 @@ class WalletDB(JsonDB):
# note: for performance, "deserialize=False" so that we will deserialize these on-demand
v = dict((k, tx_from_any(x, deserialize=False)) for k, x in v.items())
if key == 'invoices':
v = dict((k, invoice_from_json(x)) for k, x in v.items())
v = dict((k, Invoice.from_json(x)) for k, x in v.items())
if key == 'payment_requests':
v = dict((k, invoice_from_json(x)) for k, x in v.items())
v = dict((k, Invoice.from_json(x)) for k, x in v.items())
elif key == 'adds':
v = dict((k, UpdateAddHtlc.from_tuple(*x)) for k, x in v.items())
elif key == 'fee_updates':