tswaps: create invoice without saving the request - electrum - Electrum Bitcoin wallet (HTM) git clone https://git.parazyd.org/electrum (DIR) Log (DIR) Files (DIR) Refs (DIR) Submodules --- (DIR) commit 4344ca47b3af998fa1e260f66711b8eda62bab67 (DIR) parent 3665f5d3fdaed760134de0032969cbd0ec2607d7 (HTM) Author: ThomasV <thomasv@electrum.org> Date: Fri, 19 Jun 2020 10:23:07 +0200 swaps: create invoice without saving the request Diffstat: M electrum/lnworker.py | 11 +++++++---- M electrum/submarine_swaps.py | 5 +---- 2 files changed, 8 insertions(+), 8 deletions(-) --- (DIR) diff --git a/electrum/lnworker.py b/electrum/lnworker.py t@@ -1090,7 +1090,7 @@ class LNWallet(LNWorker): raise Exception(_("add invoice timed out")) @log_exceptions - async def _add_request_coro(self, amount_sat: Optional[int], message, expiry: int): + async def create_invoice(self, amount_sat: Optional[int], message, expiry: int): timestamp = int(time.time()) routing_hints = await self._calc_routing_hints_for_invoice(amount_sat) if not routing_hints: t@@ -1098,7 +1098,6 @@ class LNWallet(LNWorker): "Other clients will likely not be able to send to us.") payment_preimage = os.urandom(32) payment_hash = sha256(payment_preimage) - info = PaymentInfo(payment_hash, amount_sat, RECEIVED, PR_UNPAID) amount_btc = amount_sat/Decimal(COIN) if amount_sat else None if expiry == 0: t@@ -1113,10 +1112,14 @@ class LNWallet(LNWorker): date=timestamp, payment_secret=derive_payment_secret_from_payment_preimage(payment_preimage)) invoice = lnencode(lnaddr, self.node_keypair.privkey) - key = bh2u(lnaddr.paymenthash) - req = LNInvoice.from_bech32(invoice) self.save_preimage(payment_hash, payment_preimage) self.save_payment_info(info) + return lnaddr, invoice + + async def _add_request_coro(self, amount_sat: Optional[int], message, expiry: int): + lnaddr, invoice = await self.create_invoice(amount_sat, message, expiry) + key = bh2u(lnaddr.paymenthash) + req = LNInvoice.from_bech32(invoice) self.wallet.add_payment_request(req) self.wallet.set_label(key, message) return key (DIR) diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py t@@ -188,10 +188,7 @@ class SwapManager(Logger): """send on-chain BTC, receive on Lightning""" privkey = os.urandom(32) pubkey = ECPrivkey(privkey).get_public_key_bytes(compressed=True) - key = await self.lnworker._add_request_coro(lightning_amount, 'swap', expiry=3600*24) - request = self.wallet.get_request(key) - invoice = request.invoice - lnaddr = self.lnworker._check_invoice(invoice, lightning_amount) + lnaddr, invoice = await self.lnworker.create_invoice(lightning_amount, 'swap', expiry=3600*24) payment_hash = lnaddr.paymenthash preimage = self.lnworker.get_preimage(payment_hash) request_data = {