Skip to content

Commit 8eb3c43

Browse files
authored
Merge pull request #10059 from f321x/fix_issue_10057
fix: cli: check_hold_invoice showing settled invoice as unpaid
2 parents a391c36 + b4de29e commit 8eb3c43

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

electrum/commands.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,8 @@ async def settle_hold_invoice(self, preimage: str, wallet: Abstract_Wallet = Non
14271427
assert payment_hash in wallet.lnworker.dont_settle_htlcs, f"Invoice {payment_hash=} not a hold invoice?"
14281428
assert wallet.lnworker.is_accepted_mpp(bfh(payment_hash)), \
14291429
f"MPP incomplete, cannot settle hold invoice {payment_hash} yet"
1430+
info: Optional['PaymentInfo'] = wallet.lnworker.get_payment_info(bfh(payment_hash))
1431+
assert (wallet.lnworker.get_payment_mpp_amount_msat(bfh(payment_hash)) or 0) >= (info.amount_msat or 0)
14301432
del wallet.lnworker.dont_settle_htlcs[payment_hash]
14311433
wallet.lnworker.save_preimage(bfh(payment_hash), bfh(preimage))
14321434
util.trigger_callback('wallet_updated', wallet)
@@ -1474,18 +1476,23 @@ async def check_hold_invoice(self, payment_hash: str, wallet: Abstract_Wallet =
14741476
status = "unknown"
14751477
if info is None:
14761478
pass
1477-
elif not is_accepted_mpp:
1479+
elif not is_accepted_mpp and not wallet.lnworker.get_preimage_hex(payment_hash):
1480+
# is_accepted_mpp is False for settled payments
14781481
status = "unpaid"
14791482
elif is_accepted_mpp and payment_hash in wallet.lnworker.dont_settle_htlcs:
14801483
status = "paid"
1481-
elif (payment_hash in wallet.lnworker._preimages
1482-
and payment_hash not in wallet.lnworker.dont_settle_htlcs
1483-
and is_accepted_mpp):
1484+
elif wallet.lnworker.get_preimage_hex(payment_hash) is not None \
1485+
and payment_hash not in wallet.lnworker.dont_settle_htlcs:
14841486
status = "settled"
1487+
plist = wallet.lnworker.get_payments(status='settled')[bfh(payment_hash)]
1488+
_dir, amount_msat, _fee, _ts = wallet.lnworker.get_payment_value(info, plist)
1489+
amount_sat = amount_msat // 1000
14851490
result = {
14861491
"status": status,
1487-
"amount_sat": amount_sat
1492+
"received_amount_sat": amount_sat,
14881493
}
1494+
if info is not None:
1495+
result["invoice_amount_sat"] = (info.amount_msat or 0) // 1000
14891496
return result
14901497

14911498
@command('w')

tests/test_commands.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ async def test_hold_invoice_commands(self, mock_save_db):
495495
mock.patch.object(wallet.lnworker, 'get_payment_mpp_amount_msat', return_value=10_000 * 1000):
496496
status: dict = await cmds.check_hold_invoice(payment_hash=payment_hash, wallet=wallet)
497497
assert status['status'] == 'paid'
498-
assert status['amount_sat'] == 10000
498+
assert status['received_amount_sat'] == 10000
499499

500500
settle_result = await cmds.settle_hold_invoice(
501501
preimage=preimage.hex(),
@@ -504,6 +504,15 @@ async def test_hold_invoice_commands(self, mock_save_db):
504504
assert settle_result['settled'] == payment_hash
505505
assert wallet.lnworker._preimages[payment_hash] == preimage.hex()
506506
assert payment_hash not in wallet.lnworker.dont_settle_htlcs
507+
with (mock.patch.object(
508+
wallet.lnworker,
509+
'get_payment_value',
510+
return_value=(None, 10000*1000, None, None),
511+
)):
512+
settled_status: dict = await cmds.check_hold_invoice(payment_hash=payment_hash, wallet=wallet)
513+
assert settled_status['status'] == 'settled'
514+
assert settled_status['received_amount_sat'] == 10000
515+
assert settled_status['invoice_amount_sat'] == 10000
507516

508517
with self.assertRaises(AssertionError):
509518
# cancelling a settled invoice should raise

0 commit comments

Comments
 (0)