tallow paying invoice without amount. min feerate 253 sat/kw. - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 8e63471d69640f05c1bbee5f59f912071b2013ec DIR parent ba74844b2e4d44283a78588abfe494cbf29f983f HTML Author: SomberNight <somber.night@protonmail.com> Date: Tue, 17 Jul 2018 21:27:59 +0200 allow paying invoice without amount. min feerate 253 sat/kw. Diffstat: M electrum/gui/qt/main_window.py | 14 ++++++++++---- M electrum/lnbase.py | 3 ++- M electrum/lnworker.py | 12 ++++++++---- M electrum/util.py | 1 + 4 files changed, 21 insertions(+), 9 deletions(-) --- DIR diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py t@@ -61,7 +61,7 @@ from electrum.util import (format_time, format_satoshis, format_fee_satoshis, decimal_point_to_base_unit_name, quantize_feerate, UnknownBaseUnit, DECIMAL_POINT_DEFAULT, UserFacingException, get_new_wallet_name, send_exception_to_crash_reporter, - InvalidBitcoinURI) + InvalidBitcoinURI, InvoiceError) from electrum.transaction import Transaction, TxOutput from electrum.address_synchronizer import AddTransactionException from electrum.wallet import (Multisig_Wallet, CannotBumpFee, Abstract_Wallet, t@@ -1660,8 +1660,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): self.do_send(preview = True) def pay_lightning_invoice(self, invoice): - f = self.wallet.lnworker.pay(invoice) - self.do_clear() + try: + amount = self.amount_e.get_amount() + f = self.wallet.lnworker.pay(invoice, amount_sat=amount) + except InvoiceError as e: + self.show_error(str(e)) + else: + self.do_clear() def do_send(self, preview = False): if self.payto_e.is_lightning: t@@ -1896,7 +1901,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): self.payto_e.setFrozen(True) self.payto_e.setText(pubkey) self.message_e.setText(description) - self.amount_e.setAmount(lnaddr.amount * COIN) + if lnaddr.amount is not None: + self.amount_e.setAmount(lnaddr.amount * COIN) #self.amount_e.textEdited.emit("") self.payto_e.is_lightning = True DIR diff --git a/electrum/lnbase.py b/electrum/lnbase.py t@@ -840,6 +840,7 @@ class Peer(PrintError): assert amount_msat > 0, "amount_msat is not greater zero" height = self.network.get_local_height() route = self.network.path_finder.create_route_from_path(path, self.lnworker.pubkey) + # TODO check that first edge (our channel) has enough balance to support amount_msat hops_data = [] sum_of_deltas = sum(route_edge.channel_policy.cltv_expiry_delta for route_edge in route[1:]) total_fee = 0 t@@ -1028,7 +1029,7 @@ class Peer(PrintError): # TODO should use target_to_fee from master # target_to_fee(10*1000000) # 10 MB feerate_per_kvbyte = self.network.config.depth_to_fee(10) - feerate_per_kw = feerate_per_kvbyte / 4 + feerate_per_kw = max(253, feerate_per_kvbyte // 4) self.print_error("current feerate", chan.remote_state.feerate) self.print_error("new feerate", feerate_per_kw) if feerate_per_kw < chan.remote_state.feerate / 2: DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py t@@ -9,7 +9,7 @@ import random from . import constants from .bitcoin import sha256, COIN -from .util import bh2u, bfh, PrintError +from .util import bh2u, bfh, PrintError, InvoiceError from .constants import set_testnet, set_simnet from .lnbase import Peer, privkey_to_pubkey, aiosafe from .lnaddr import lnencode, LnAddr, lndecode t@@ -18,6 +18,7 @@ from .transaction import Transaction from .lnhtlc import HTLCStateMachine from .lnutil import Outpoint, calc_short_channel_id from .lnwatcher import LNChanCloseHandler +from .i18n import _ # hardcoded nodes node_list = [ t@@ -129,10 +130,10 @@ class LNWorker(PrintError): peer = self.peers[chan.node_id] peer.funding_locked(chan) elif chan.state == "OPEN": + peer = self.peers[chan.node_id] if event == 'fee_histogram': peer.on_bitcoin_fee_update(chan) conf = self.wallet.get_tx_height(chan.funding_outpoint.txid)[1] - peer = self.peers[chan.node_id] peer.on_network_update(chan, conf) asyncio.run_coroutine_threadsafe(network_jobs(), self.network.asyncio_loop).result() t@@ -150,11 +151,14 @@ class LNWorker(PrintError): coro = self._open_channel_coroutine(node_id, local_amt_sat, push_amt_sat, None if pw == "" else pw) return asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop) - def pay(self, invoice): + def pay(self, invoice, amount_sat=None): addr = lndecode(invoice, expected_hrp=constants.net.SEGWIT_HRP) payment_hash = addr.paymenthash invoice_pubkey = addr.pubkey.serialize() - amount_msat = int(addr.amount * COIN * 1000) + amount_sat = (addr.amount * COIN) if addr.amount else amount_sat + if amount_sat is None: + raise InvoiceError(_("Missing amount")) + amount_msat = int(amount_sat * 1000) path = self.network.path_finder.find_path_for_payment(self.pubkey, invoice_pubkey, amount_msat) if path is None: raise Exception("No path found") DIR diff --git a/electrum/util.py b/electrum/util.py t@@ -131,6 +131,7 @@ class BitcoinException(Exception): pass class UserFacingException(Exception): """Exception that contains information intended to be shown to the user.""" +class InvoiceError(Exception): pass # Throw this exception to unwind the stack like when an error occurs. # However unlike other exceptions the user won't be informed.