7070)
7171from .address_synchronizer import TX_HEIGHT_LOCAL
7272from .mnemonic import Mnemonic
73- from .lnutil import (channel_id_from_funding_tx , LnFeatures , SENT , MIN_FINAL_CLTV_DELTA_ACCEPTED ,
73+ from .lnutil import (channel_id_from_funding_tx , LnFeatures , SENT , RECEIVED , MIN_FINAL_CLTV_DELTA_ACCEPTED ,
7474 PaymentFeeBudget , NBLOCK_CLTV_DELTA_TOO_FAR_INTO_FUTURE )
7575from .plugin import run_hook , DeviceMgr , Plugins
7676from .version import ELECTRUM_VERSION
@@ -1398,7 +1398,7 @@ async def add_hold_invoice(
13981398 arg:int:min_final_cltv_expiry_delta:Optional min final cltv expiry delta (default: 294 blocks)
13991399 """
14001400 assert len (payment_hash ) == 64 , f"Invalid payment hash length: { len (payment_hash )} != 64"
1401- assert payment_hash not in wallet .lnworker .payment_info , "Payment hash already used!"
1401+ assert not wallet .lnworker .get_payment_info ( bfh ( payment_hash ), direction = RECEIVED ) , "Payment hash already used!"
14021402 assert payment_hash not in wallet .lnworker .dont_expire_htlcs , "Payment hash already used!"
14031403 assert wallet .lnworker .get_preimage (bfh (payment_hash )) is None , "Already got a preimage for this payment hash!"
14041404 assert MIN_FINAL_CLTV_DELTA_ACCEPTED < min_final_cltv_expiry_delta < 576 , "Use a sane min_final_cltv_expiry_delta value"
@@ -1413,7 +1413,7 @@ async def add_hold_invoice(
14131413 min_final_cltv_delta = min_final_cltv_expiry_delta ,
14141414 exp_delay = expiry ,
14151415 )
1416- info = wallet .lnworker .get_payment_info (bfh (payment_hash ))
1416+ info = wallet .lnworker .get_payment_info (bfh (payment_hash ), direction = RECEIVED )
14171417 lnaddr , invoice = wallet .lnworker .get_bolt11_invoice (
14181418 payment_info = info ,
14191419 message = memo ,
@@ -1439,12 +1439,11 @@ async def settle_hold_invoice(self, preimage: str, wallet: Abstract_Wallet = Non
14391439 assert len (preimage ) == 64 , f"Invalid payment_hash length: { len (preimage )} != 64"
14401440 payment_hash : str = crypto .sha256 (bfh (preimage )).hex ()
14411441 assert payment_hash not in wallet .lnworker ._preimages , f"Invoice { payment_hash = } already settled"
1442- assert payment_hash in wallet .lnworker .payment_info , \
1443- f"Couldn't find lightning invoice for { payment_hash = } "
1442+ info = wallet .lnworker .get_payment_info ( bfh ( payment_hash ), direction = RECEIVED )
1443+ assert info , f"Couldn't find lightning invoice for { payment_hash = } "
14441444 assert payment_hash in wallet .lnworker .dont_expire_htlcs , f"Invoice { payment_hash = } not a hold invoice?"
14451445 assert wallet .lnworker .is_complete_mpp (bfh (payment_hash )), \
14461446 f"MPP incomplete, cannot settle hold invoice { payment_hash } yet"
1447- info : Optional ['PaymentInfo' ] = wallet .lnworker .get_payment_info (bfh (payment_hash ))
14481447 assert (wallet .lnworker .get_payment_mpp_amount_msat (bfh (payment_hash )) or 0 ) >= (info .amount_msat or 0 )
14491448 wallet .lnworker .save_preimage (bfh (payment_hash ), bfh (preimage ))
14501449 util .trigger_callback ('wallet_updated' , wallet )
@@ -1460,13 +1459,13 @@ async def cancel_hold_invoice(self, payment_hash: str, wallet: Abstract_Wallet =
14601459
14611460 arg:str:payment_hash:Payment hash in hex of the hold invoice
14621461 """
1463- assert payment_hash in wallet .lnworker .payment_info , \
1462+ assert wallet .lnworker .get_payment_info ( bfh ( payment_hash ), direction = RECEIVED ) , \
14641463 f"Couldn't find lightning invoice for payment hash { payment_hash } "
14651464 assert payment_hash not in wallet .lnworker ._preimages , "Cannot cancel anymore, preimage already given."
14661465 assert payment_hash in wallet .lnworker .dont_expire_htlcs , f"{ payment_hash = } not a hold invoice?"
14671466 # set to PR_UNPAID so it can get deleted
1468- wallet .lnworker .set_payment_status (bfh (payment_hash ), PR_UNPAID )
1469- wallet .lnworker .delete_payment_info (payment_hash )
1467+ wallet .lnworker .set_payment_status (bfh (payment_hash ), PR_UNPAID , direction = RECEIVED )
1468+ wallet .lnworker .delete_payment_info (payment_hash , direction = RECEIVED )
14701469 wallet .set_label (payment_hash , None )
14711470 del wallet .lnworker .dont_expire_htlcs [payment_hash ]
14721471 while wallet .lnworker .is_complete_mpp (bfh (payment_hash )):
@@ -1492,7 +1491,7 @@ async def check_hold_invoice(self, payment_hash: str, wallet: Abstract_Wallet =
14921491 arg:str:payment_hash:Payment hash in hex of the hold invoice
14931492 """
14941493 assert len (payment_hash ) == 64 , f"Invalid payment_hash length: { len (payment_hash )} != 64"
1495- info : Optional ['PaymentInfo' ] = wallet .lnworker .get_payment_info (bfh (payment_hash ))
1494+ info : Optional ['PaymentInfo' ] = wallet .lnworker .get_payment_info (bfh (payment_hash ), direction = RECEIVED )
14961495 is_complete_mpp : bool = wallet .lnworker .is_complete_mpp (bfh (payment_hash ))
14971496 amount_sat = (wallet .lnworker .get_payment_mpp_amount_msat (bfh (payment_hash )) or 0 ) // 1000
14981497 result = {
@@ -1514,7 +1513,7 @@ async def check_hold_invoice(self, payment_hash: str, wallet: Abstract_Wallet =
15141513 elif wallet .lnworker .get_preimage_hex (payment_hash ) is not None :
15151514 result ["status" ] = "settled"
15161515 plist = wallet .lnworker .get_payments (status = 'settled' )[bfh (payment_hash )]
1517- _dir , amount_msat , _fee , _ts = wallet .lnworker .get_payment_value (info , plist )
1516+ _dir , amount_msat , _fee , _ts = wallet .lnworker .get_payment_value (None , plist )
15181517 result ["received_amount_sat" ] = amount_msat // 1000
15191518 result ['preimage' ] = wallet .lnworker .get_preimage_hex (payment_hash )
15201519 if info is not None :
0 commit comments