diff --git a/electrum/lnworker.py b/electrum/lnworker.py index eae2ac43a..9b69156a6 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -1809,6 +1809,8 @@ class LNWallet(LNWorker): self.logger.info(f"creating bolt11 invoice with routing_hints: {routing_hints}") invoice_features = self.features.for_invoice() payment_preimage = self.get_preimage(payment_hash) + if payment_preimage is None: # e.g. when export/importing requests between wallets + raise Exception("missing preimage for payment_hash") amount_btc = amount_msat/Decimal(COIN*1000) if amount_msat else None if expiry == 0: expiry = LN_EXPIRY_NEVER diff --git a/electrum/wallet.py b/electrum/wallet.py index 3ef44d9ba..cd88432e5 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -1066,13 +1066,14 @@ class Abstract_Wallet(ABC, Logger, EventListener): data = read_json_file(path) for x in data: try: - req = Invoice(**x) + req = Request(**x) except: raise FileImportFailed(_("Invalid invoice format")) self.add_payment_request(req, write_to_disk=False) self.save_db() def export_requests(self, path): + # note: this does not export preimages for LN bolt11 invoices write_json_file(path, list(self._receive_requests.values())) def import_invoices(self, path): @@ -1125,7 +1126,7 @@ class Abstract_Wallet(ABC, Logger, EventListener): for txout in invoice.get_outputs(): self._invoices_from_scriptpubkey_map[txout.scriptpubkey].add(invoice_key) - def _is_onchain_invoice_paid(self, invoice: Invoice) -> Tuple[bool, Optional[int], Sequence[str]]: + def _is_onchain_invoice_paid(self, invoice: BaseInvoice) -> Tuple[bool, Optional[int], Sequence[str]]: """Returns whether on-chain invoice/request is satisfied, num confs required txs have, and list of relevant TXIDs. """ @@ -1161,7 +1162,7 @@ class Abstract_Wallet(ABC, Logger, EventListener): is_paid = False return is_paid, conf_needed, list(relevant_txs) - def is_onchain_invoice_paid(self, invoice: Invoice) -> Tuple[bool, Optional[int]]: + def is_onchain_invoice_paid(self, invoice: BaseInvoice) -> Tuple[bool, Optional[int]]: is_paid, conf_needed, relevant_txs = self._is_onchain_invoice_paid(invoice) return is_paid, conf_needed