mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-04 04:45:16 +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,
|
export_meta, import_meta, bh2u, bfh, InvalidPassword,
|
||||||
base_units, base_units_list, base_unit_name_to_decimal_point,
|
base_units, base_units_list, base_unit_name_to_decimal_point,
|
||||||
decimal_point_to_base_unit_name, quantize_feerate,
|
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.transaction import Transaction, TxOutput
|
||||||
from electrum.address_synchronizer import AddTransactionException
|
from electrum.address_synchronizer import AddTransactionException
|
||||||
from electrum.wallet import (Multisig_Wallet, CannotBumpFee, Abstract_Wallet,
|
from electrum.wallet import (Multisig_Wallet, CannotBumpFee, Abstract_Wallet,
|
||||||
|
@ -1563,7 +1563,12 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
self.do_send(preview = True)
|
self.do_send(preview = True)
|
||||||
|
|
||||||
def pay_lightning_invoice(self, invoice):
|
def pay_lightning_invoice(self, invoice):
|
||||||
f = self.wallet.lnworker.pay(invoice)
|
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()
|
self.do_clear()
|
||||||
|
|
||||||
def do_send(self, preview = False):
|
def do_send(self, preview = False):
|
||||||
|
@ -1788,6 +1793,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
self.payto_e.setFrozen(True)
|
self.payto_e.setFrozen(True)
|
||||||
self.payto_e.setText(pubkey)
|
self.payto_e.setText(pubkey)
|
||||||
self.message_e.setText(description)
|
self.message_e.setText(description)
|
||||||
|
if lnaddr.amount is not None:
|
||||||
self.amount_e.setAmount(lnaddr.amount * COIN)
|
self.amount_e.setAmount(lnaddr.amount * COIN)
|
||||||
#self.amount_e.textEdited.emit("")
|
#self.amount_e.textEdited.emit("")
|
||||||
self.payto_e.is_lightning = True
|
self.payto_e.is_lightning = True
|
||||||
|
|
|
@ -840,6 +840,7 @@ class Peer(PrintError):
|
||||||
assert amount_msat > 0, "amount_msat is not greater zero"
|
assert amount_msat > 0, "amount_msat is not greater zero"
|
||||||
height = self.network.get_local_height()
|
height = self.network.get_local_height()
|
||||||
route = self.network.path_finder.create_route_from_path(path, self.lnworker.pubkey)
|
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 = []
|
hops_data = []
|
||||||
sum_of_deltas = sum(route_edge.channel_policy.cltv_expiry_delta for route_edge in route[1:])
|
sum_of_deltas = sum(route_edge.channel_policy.cltv_expiry_delta for route_edge in route[1:])
|
||||||
total_fee = 0
|
total_fee = 0
|
||||||
|
@ -1028,7 +1029,7 @@ class Peer(PrintError):
|
||||||
# TODO should use target_to_fee from master
|
# TODO should use target_to_fee from master
|
||||||
# target_to_fee(10*1000000) # 10 MB
|
# target_to_fee(10*1000000) # 10 MB
|
||||||
feerate_per_kvbyte = self.network.config.depth_to_fee(10)
|
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("current feerate", chan.remote_state.feerate)
|
||||||
self.print_error("new feerate", feerate_per_kw)
|
self.print_error("new feerate", feerate_per_kw)
|
||||||
if feerate_per_kw < chan.remote_state.feerate / 2:
|
if feerate_per_kw < chan.remote_state.feerate / 2:
|
||||||
|
|
|
@ -9,7 +9,7 @@ import random
|
||||||
|
|
||||||
from . import constants
|
from . import constants
|
||||||
from .bitcoin import sha256, COIN
|
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 .constants import set_testnet, set_simnet
|
||||||
from .lnbase import Peer, privkey_to_pubkey, aiosafe
|
from .lnbase import Peer, privkey_to_pubkey, aiosafe
|
||||||
from .lnaddr import lnencode, LnAddr, lndecode
|
from .lnaddr import lnencode, LnAddr, lndecode
|
||||||
|
@ -18,6 +18,7 @@ from .transaction import Transaction
|
||||||
from .lnhtlc import HTLCStateMachine
|
from .lnhtlc import HTLCStateMachine
|
||||||
from .lnutil import Outpoint, calc_short_channel_id
|
from .lnutil import Outpoint, calc_short_channel_id
|
||||||
from .lnwatcher import LNChanCloseHandler
|
from .lnwatcher import LNChanCloseHandler
|
||||||
|
from .i18n import _
|
||||||
|
|
||||||
# hardcoded nodes
|
# hardcoded nodes
|
||||||
node_list = [
|
node_list = [
|
||||||
|
@ -129,10 +130,10 @@ class LNWorker(PrintError):
|
||||||
peer = self.peers[chan.node_id]
|
peer = self.peers[chan.node_id]
|
||||||
peer.funding_locked(chan)
|
peer.funding_locked(chan)
|
||||||
elif chan.state == "OPEN":
|
elif chan.state == "OPEN":
|
||||||
|
peer = self.peers[chan.node_id]
|
||||||
if event == 'fee_histogram':
|
if event == 'fee_histogram':
|
||||||
peer.on_bitcoin_fee_update(chan)
|
peer.on_bitcoin_fee_update(chan)
|
||||||
conf = self.wallet.get_tx_height(chan.funding_outpoint.txid)[1]
|
conf = self.wallet.get_tx_height(chan.funding_outpoint.txid)[1]
|
||||||
peer = self.peers[chan.node_id]
|
|
||||||
peer.on_network_update(chan, conf)
|
peer.on_network_update(chan, conf)
|
||||||
asyncio.run_coroutine_threadsafe(network_jobs(), self.network.asyncio_loop).result()
|
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)
|
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)
|
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)
|
addr = lndecode(invoice, expected_hrp=constants.net.SEGWIT_HRP)
|
||||||
payment_hash = addr.paymenthash
|
payment_hash = addr.paymenthash
|
||||||
invoice_pubkey = addr.pubkey.serialize()
|
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)
|
path = self.network.path_finder.find_path_for_payment(self.pubkey, invoice_pubkey, amount_msat)
|
||||||
if path is None:
|
if path is None:
|
||||||
raise Exception("No path found")
|
raise Exception("No path found")
|
||||||
|
|
|
@ -119,6 +119,9 @@ class WalletFileException(Exception): pass
|
||||||
class BitcoinException(Exception): pass
|
class BitcoinException(Exception): pass
|
||||||
|
|
||||||
|
|
||||||
|
class InvoiceError(Exception): pass
|
||||||
|
|
||||||
|
|
||||||
# Throw this exception to unwind the stack like when an error occurs.
|
# Throw this exception to unwind the stack like when an error occurs.
|
||||||
# However unlike other exceptions the user won't be informed.
|
# However unlike other exceptions the user won't be informed.
|
||||||
class UserCancelled(Exception):
|
class UserCancelled(Exception):
|
||||||
|
|
Loading…
Add table
Reference in a new issue