mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-03 20:35:13 +00:00
allow paying invoice without amount. min feerate 253 sat/kw.
This commit is contained in:
parent
f3bd710bbf
commit
037290a9a8
4 changed files with 23 additions and 9 deletions
|
@ -55,7 +55,7 @@ from electrum.util import (format_time, format_satoshis, format_fee_satoshis,
|
|||
export_meta, import_meta, bh2u, bfh, InvalidPassword,
|
||||
base_units, base_units_list, base_unit_name_to_decimal_point,
|
||||
decimal_point_to_base_unit_name, quantize_feerate,
|
||||
UnknownBaseUnit, DECIMAL_POINT_DEFAULT)
|
||||
UnknownBaseUnit, DECIMAL_POINT_DEFAULT, InvoiceError)
|
||||
from electrum.transaction import Transaction, TxOutput
|
||||
from electrum.address_synchronizer import AddTransactionException
|
||||
from electrum.wallet import (Multisig_Wallet, CannotBumpFee, Abstract_Wallet,
|
||||
|
@ -1563,8 +1563,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||
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:
|
||||
|
@ -1788,7 +1793,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
|||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
@ -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 = [
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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")
|
||||
|
|
|
@ -119,6 +119,9 @@ class WalletFileException(Exception): pass
|
|||
class BitcoinException(Exception): pass
|
||||
|
||||
|
||||
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.
|
||||
class UserCancelled(Exception):
|
||||
|
|
Loading…
Add table
Reference in a new issue