1
0

wallet: fix import_requests, and mention quirk re preimages

This commit is contained in:
SomberNight
2023-03-03 16:35:34 +00:00
parent 81bd6f7d1b
commit ec889b8c3f
2 changed files with 6 additions and 3 deletions

View File

@@ -1809,6 +1809,8 @@ class LNWallet(LNWorker):
self.logger.info(f"creating bolt11 invoice with routing_hints: {routing_hints}") self.logger.info(f"creating bolt11 invoice with routing_hints: {routing_hints}")
invoice_features = self.features.for_invoice() invoice_features = self.features.for_invoice()
payment_preimage = self.get_preimage(payment_hash) 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 amount_btc = amount_msat/Decimal(COIN*1000) if amount_msat else None
if expiry == 0: if expiry == 0:
expiry = LN_EXPIRY_NEVER expiry = LN_EXPIRY_NEVER

View File

@@ -1066,13 +1066,14 @@ class Abstract_Wallet(ABC, Logger, EventListener):
data = read_json_file(path) data = read_json_file(path)
for x in data: for x in data:
try: try:
req = Invoice(**x) req = Request(**x)
except: except:
raise FileImportFailed(_("Invalid invoice format")) raise FileImportFailed(_("Invalid invoice format"))
self.add_payment_request(req, write_to_disk=False) self.add_payment_request(req, write_to_disk=False)
self.save_db() self.save_db()
def export_requests(self, path): def export_requests(self, path):
# note: this does not export preimages for LN bolt11 invoices
write_json_file(path, list(self._receive_requests.values())) write_json_file(path, list(self._receive_requests.values()))
def import_invoices(self, path): def import_invoices(self, path):
@@ -1125,7 +1126,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
for txout in invoice.get_outputs(): for txout in invoice.get_outputs():
self._invoices_from_scriptpubkey_map[txout.scriptpubkey].add(invoice_key) 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, """Returns whether on-chain invoice/request is satisfied, num confs required txs have,
and list of relevant TXIDs. and list of relevant TXIDs.
""" """
@@ -1161,7 +1162,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
is_paid = False is_paid = False
return is_paid, conf_needed, list(relevant_txs) 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) is_paid, conf_needed, relevant_txs = self._is_onchain_invoice_paid(invoice)
return is_paid, conf_needed return is_paid, conf_needed