swaps: create invoice without saving the request
This commit is contained in:
@@ -1090,7 +1090,7 @@ class LNWallet(LNWorker):
|
|||||||
raise Exception(_("add invoice timed out"))
|
raise Exception(_("add invoice timed out"))
|
||||||
|
|
||||||
@log_exceptions
|
@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())
|
timestamp = int(time.time())
|
||||||
routing_hints = await self._calc_routing_hints_for_invoice(amount_sat)
|
routing_hints = await self._calc_routing_hints_for_invoice(amount_sat)
|
||||||
if not routing_hints:
|
if not routing_hints:
|
||||||
@@ -1098,7 +1098,6 @@ class LNWallet(LNWorker):
|
|||||||
"Other clients will likely not be able to send to us.")
|
"Other clients will likely not be able to send to us.")
|
||||||
payment_preimage = os.urandom(32)
|
payment_preimage = os.urandom(32)
|
||||||
payment_hash = sha256(payment_preimage)
|
payment_hash = sha256(payment_preimage)
|
||||||
|
|
||||||
info = PaymentInfo(payment_hash, amount_sat, RECEIVED, PR_UNPAID)
|
info = PaymentInfo(payment_hash, amount_sat, RECEIVED, PR_UNPAID)
|
||||||
amount_btc = amount_sat/Decimal(COIN) if amount_sat else None
|
amount_btc = amount_sat/Decimal(COIN) if amount_sat else None
|
||||||
if expiry == 0:
|
if expiry == 0:
|
||||||
@@ -1113,10 +1112,14 @@ class LNWallet(LNWorker):
|
|||||||
date=timestamp,
|
date=timestamp,
|
||||||
payment_secret=derive_payment_secret_from_payment_preimage(payment_preimage))
|
payment_secret=derive_payment_secret_from_payment_preimage(payment_preimage))
|
||||||
invoice = lnencode(lnaddr, self.node_keypair.privkey)
|
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_preimage(payment_hash, payment_preimage)
|
||||||
self.save_payment_info(info)
|
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.add_payment_request(req)
|
||||||
self.wallet.set_label(key, message)
|
self.wallet.set_label(key, message)
|
||||||
return key
|
return key
|
||||||
|
|||||||
@@ -188,10 +188,7 @@ class SwapManager(Logger):
|
|||||||
"""send on-chain BTC, receive on Lightning"""
|
"""send on-chain BTC, receive on Lightning"""
|
||||||
privkey = os.urandom(32)
|
privkey = os.urandom(32)
|
||||||
pubkey = ECPrivkey(privkey).get_public_key_bytes(compressed=True)
|
pubkey = ECPrivkey(privkey).get_public_key_bytes(compressed=True)
|
||||||
key = await self.lnworker._add_request_coro(lightning_amount, 'swap', expiry=3600*24)
|
lnaddr, invoice = await self.lnworker.create_invoice(lightning_amount, 'swap', expiry=3600*24)
|
||||||
request = self.wallet.get_request(key)
|
|
||||||
invoice = request.invoice
|
|
||||||
lnaddr = self.lnworker._check_invoice(invoice, lightning_amount)
|
|
||||||
payment_hash = lnaddr.paymenthash
|
payment_hash = lnaddr.paymenthash
|
||||||
preimage = self.lnworker.get_preimage(payment_hash)
|
preimage = self.lnworker.get_preimage(payment_hash)
|
||||||
request_data = {
|
request_data = {
|
||||||
|
|||||||
Reference in New Issue
Block a user