lnworker: save outgoing invoice when initiating payment
This commit is contained in:
@@ -33,6 +33,7 @@ from electrum.i18n import _
|
||||
from electrum.util import format_time, pr_tooltips, PR_UNPAID
|
||||
from electrum.lnutil import lndecode
|
||||
from electrum.bitcoin import COIN
|
||||
from electrum import constants
|
||||
|
||||
from .util import (MyTreeView, read_QIcon, MONOSPACE_FONT, PR_UNPAID,
|
||||
pr_tooltips, import_meta_gui, export_meta_gui, pr_icons)
|
||||
|
||||
@@ -1948,8 +1948,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
||||
#self.amount_e.textEdited.emit("")
|
||||
self.payto_e.is_lightning = True
|
||||
self.show_send_tab_onchain_fees(False)
|
||||
# save
|
||||
self.wallet.lnworker.save_invoice(None, invoice, SENT)
|
||||
|
||||
def show_send_tab_onchain_fees(self, b: bool):
|
||||
self.feecontrol_fields.setVisible(b)
|
||||
|
||||
@@ -465,14 +465,15 @@ class LNWorker(PrintError):
|
||||
peer = self.peers[route[0].node_id]
|
||||
if not self.get_channel_by_short_id(route[0].short_channel_id):
|
||||
assert False, 'Found route with short channel ID we don\'t have: ' + repr(route[0].short_channel_id)
|
||||
return addr, peer, self._pay_to_route(route, addr)
|
||||
return addr, peer, self._pay_to_route(route, addr, invoice)
|
||||
|
||||
async def _pay_to_route(self, route, addr):
|
||||
async def _pay_to_route(self, route, addr, pay_req):
|
||||
short_channel_id = route[0].short_channel_id
|
||||
chan = self.get_channel_by_short_id(short_channel_id)
|
||||
if not chan:
|
||||
raise Exception("PathFinder returned path with short_channel_id {} that is not in channel list".format(bh2u(short_channel_id)))
|
||||
peer = self.peers[route[0].node_id]
|
||||
self.save_invoice(None, pay_req, SENT)
|
||||
htlc = await peer.pay(route, chan, int(addr.amount * COIN * 1000), addr.paymenthash, addr.get_min_final_cltv_expiry())
|
||||
self.network.trigger_callback('htlc_added', htlc, addr, SENT)
|
||||
|
||||
|
||||
@@ -109,6 +109,9 @@ class MockLNWorker:
|
||||
def on_channels_updated(self):
|
||||
pass
|
||||
|
||||
def save_invoice(*args):
|
||||
pass
|
||||
|
||||
get_invoice = LNWorker.get_invoice
|
||||
_create_route_from_invoice = LNWorker._create_route_from_invoice
|
||||
_check_invoice = staticmethod(LNWorker._check_invoice)
|
||||
@@ -243,7 +246,7 @@ class TestPeer(unittest.TestCase):
|
||||
# AssertionError is ok since we shouldn't use old routes, and the
|
||||
# route finding should fail when channel is closed
|
||||
with self.assertRaises(AssertionError):
|
||||
run(asyncio.gather(w1._pay_to_route(route, addr), p1._main_loop(), p2._main_loop()))
|
||||
run(asyncio.gather(w1._pay_to_route(route, addr, pay_req), p1._main_loop(), p2._main_loop()))
|
||||
|
||||
def run(coro):
|
||||
asyncio.get_event_loop().run_until_complete(coro)
|
||||
|
||||
Reference in New Issue
Block a user