Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions electrum/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
)
from .address_synchronizer import TX_HEIGHT_LOCAL
from .mnemonic import Mnemonic
from .lnutil import (channel_id_from_funding_tx, LnFeatures, SENT, MIN_FINAL_CLTV_DELTA_ACCEPTED,
from .lnutil import (channel_id_from_funding_tx, LnFeatures, SENT, RECEIVED, MIN_FINAL_CLTV_DELTA_ACCEPTED,
PaymentFeeBudget, NBLOCK_CLTV_DELTA_TOO_FAR_INTO_FUTURE)
from .plugin import run_hook, DeviceMgr, Plugins
from .version import ELECTRUM_VERSION
Expand Down Expand Up @@ -1402,7 +1402,7 @@ async def add_hold_invoice(
arg:int:min_final_cltv_expiry_delta:Optional min final cltv expiry delta (default: 294 blocks)
"""
assert len(payment_hash) == 64, f"Invalid payment hash length: {len(payment_hash)} != 64"
assert payment_hash not in wallet.lnworker.payment_info, "Payment hash already used!"
assert not wallet.lnworker.get_payment_info(bfh(payment_hash), direction=RECEIVED), "Payment hash already used!"
assert payment_hash not in wallet.lnworker.dont_expire_htlcs, "Payment hash already used!"
assert wallet.lnworker.get_preimage(bfh(payment_hash)) is None, "Already got a preimage for this payment hash!"
assert MIN_FINAL_CLTV_DELTA_ACCEPTED < min_final_cltv_expiry_delta < 576, "Use a sane min_final_cltv_expiry_delta value"
Expand All @@ -1417,7 +1417,7 @@ async def add_hold_invoice(
min_final_cltv_delta=min_final_cltv_expiry_delta,
exp_delay=expiry,
)
info = wallet.lnworker.get_payment_info(bfh(payment_hash))
info = wallet.lnworker.get_payment_info(bfh(payment_hash), direction=RECEIVED)
lnaddr, invoice = wallet.lnworker.get_bolt11_invoice(
payment_info=info,
message=memo,
Expand All @@ -1443,12 +1443,11 @@ async def settle_hold_invoice(self, preimage: str, wallet: Abstract_Wallet = Non
assert len(preimage) == 64, f"Invalid payment_hash length: {len(preimage)} != 64"
payment_hash: str = crypto.sha256(bfh(preimage)).hex()
assert payment_hash not in wallet.lnworker._preimages, f"Invoice {payment_hash=} already settled"
assert payment_hash in wallet.lnworker.payment_info, \
f"Couldn't find lightning invoice for {payment_hash=}"
info = wallet.lnworker.get_payment_info(bfh(payment_hash), direction=RECEIVED)
assert info, f"Couldn't find lightning invoice for {payment_hash=}"
assert payment_hash in wallet.lnworker.dont_expire_htlcs, f"Invoice {payment_hash=} not a hold invoice?"
assert wallet.lnworker.is_complete_mpp(bfh(payment_hash)), \
f"MPP incomplete, cannot settle hold invoice {payment_hash} yet"
info: Optional['PaymentInfo'] = wallet.lnworker.get_payment_info(bfh(payment_hash))
assert (wallet.lnworker.get_payment_mpp_amount_msat(bfh(payment_hash)) or 0) >= (info.amount_msat or 0)
wallet.lnworker.save_preimage(bfh(payment_hash), bfh(preimage))
util.trigger_callback('wallet_updated', wallet)
Expand All @@ -1464,13 +1463,13 @@ async def cancel_hold_invoice(self, payment_hash: str, wallet: Abstract_Wallet =

arg:str:payment_hash:Payment hash in hex of the hold invoice
"""
assert payment_hash in wallet.lnworker.payment_info, \
assert wallet.lnworker.get_payment_info(bfh(payment_hash), direction=RECEIVED), \
f"Couldn't find lightning invoice for payment hash {payment_hash}"
assert payment_hash not in wallet.lnworker._preimages, "Cannot cancel anymore, preimage already given."
assert payment_hash in wallet.lnworker.dont_expire_htlcs, f"{payment_hash=} not a hold invoice?"
# set to PR_UNPAID so it can get deleted
wallet.lnworker.set_payment_status(bfh(payment_hash), PR_UNPAID)
wallet.lnworker.delete_payment_info(payment_hash)
wallet.lnworker.set_payment_status(bfh(payment_hash), PR_UNPAID, direction=RECEIVED)
wallet.lnworker.delete_payment_info(payment_hash, direction=RECEIVED)
wallet.set_label(payment_hash, None)
del wallet.lnworker.dont_expire_htlcs[payment_hash]
while wallet.lnworker.is_complete_mpp(bfh(payment_hash)):
Expand All @@ -1496,7 +1495,7 @@ async def check_hold_invoice(self, payment_hash: str, wallet: Abstract_Wallet =
arg:str:payment_hash:Payment hash in hex of the hold invoice
"""
assert len(payment_hash) == 64, f"Invalid payment_hash length: {len(payment_hash)} != 64"
info: Optional['PaymentInfo'] = wallet.lnworker.get_payment_info(bfh(payment_hash))
info: Optional['PaymentInfo'] = wallet.lnworker.get_payment_info(bfh(payment_hash), direction=RECEIVED)
is_complete_mpp: bool = wallet.lnworker.is_complete_mpp(bfh(payment_hash))
amount_sat = (wallet.lnworker.get_payment_mpp_amount_msat(bfh(payment_hash)) or 0) // 1000
result = {
Expand All @@ -1518,7 +1517,7 @@ async def check_hold_invoice(self, payment_hash: str, wallet: Abstract_Wallet =
elif wallet.lnworker.get_preimage_hex(payment_hash) is not None:
result["status"] = "settled"
plist = wallet.lnworker.get_payments(status='settled')[bfh(payment_hash)]
_dir, amount_msat, _fee, _ts = wallet.lnworker.get_payment_value(info, plist)
_dir, amount_msat, _fee, _ts = wallet.lnworker.get_payment_value(None, plist)
result["received_amount_sat"] = amount_msat // 1000
result['preimage'] = wallet.lnworker.get_preimage_hex(payment_hash)
if info is not None:
Expand Down
4 changes: 2 additions & 2 deletions electrum/gui/qml/qerequestdetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from electrum.invoices import (
PR_UNPAID, PR_EXPIRED, PR_UNKNOWN, PR_PAID, PR_INFLIGHT, PR_FAILED, PR_ROUTING, PR_UNCONFIRMED, LN_EXPIRY_NEVER
)
from electrum.lnutil import MIN_FUNDING_SAT
from electrum.lnutil import MIN_FUNDING_SAT, RECEIVED
from electrum.lnurl import LNURL3Data, request_lnurl_withdraw_callback, LNURLError
from electrum.payment_identifier import PaymentIdentifier, PaymentIdentifierType
from electrum.i18n import _
Expand Down Expand Up @@ -237,7 +237,7 @@ def lnurlRequestWithdrawal(self, amount_sat: int) -> None:
address=None,
)
req = self._wallet.wallet.get_request(key)
info = self._wallet.wallet.lnworker.get_payment_info(req.payment_hash)
info = self._wallet.wallet.lnworker.get_payment_info(req.payment_hash, direction=RECEIVED)
_lnaddr, b11_invoice = self._wallet.wallet.lnworker.get_bolt11_invoice(
payment_info=info,
message=req.get_message(),
Expand Down
3 changes: 2 additions & 1 deletion electrum/gui/qt/send_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
NotEnoughFunds, NoDynamicFeeEstimates, parse_max_spend, UserCancelled, ChoiceItem,
UserFacingException,
)
from electrum.lnutil import RECEIVED
from electrum.invoices import PR_PAID, Invoice, PR_BROADCASTING, PR_BROADCAST
from electrum.transaction import Transaction, PartialTxInput, PartialTxOutput
from electrum.network import TxBroadcastError, BestEffortRequestFailed
Expand Down Expand Up @@ -979,7 +980,7 @@ def request_lnurl_withdraw_dialog(self, lnurl_data: LNURL3Data):
address=None,
)
req = self.wallet.get_request(key)
info = self.wallet.lnworker.get_payment_info(req.payment_hash)
info = self.wallet.lnworker.get_payment_info(req.payment_hash, direction=RECEIVED)
_lnaddr, b11_invoice = self.wallet.lnworker.get_bolt11_invoice(
payment_info=info,
message=req.get_message(),
Expand Down
4 changes: 2 additions & 2 deletions electrum/lnpeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2221,7 +2221,7 @@ def _check_unfulfilled_htlc(
outer_onion_payment_secret=payment_secret_from_onion,
)

info = self.lnworker.get_payment_info(payment_hash)
info = self.lnworker.get_payment_info(payment_hash, direction=RECEIVED)
if info is None:
_log_fail_reason(f"no payment_info found for RHASH {payment_hash.hex()}")
raise exc_incorrect_or_unknown_pd
Expand Down Expand Up @@ -3115,7 +3115,7 @@ def _check_unfulfilled_htlc_set(
return None, None, fwd_cb

# -- from here on it's assumed this set is a payment for us (not something to forward) --
payment_info = self.lnworker.get_payment_info(payment_hash)
payment_info = self.lnworker.get_payment_info(payment_hash, direction=RECEIVED)
if payment_info is None:
_log_fail_reason(f"payment info has been deleted")
return OnionFailureCode.INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS, None, None
Expand Down
1 change: 1 addition & 0 deletions electrum/lnutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,7 @@ def __neg__(self) -> 'HTLCOwner':
return HTLCOwner(super().__neg__())


# part of lightning_payments db keys
class Direction(IntEnum):
SENT = -1 # in the context of HTLCs: "offered" HTLCs
RECEIVED = 1 # in the context of HTLCs: "received" HTLCs
Expand Down
Loading