54
54
from .bip32 import BIP32Node , convert_bip32_intpath_to_strpath , convert_bip32_strpath_to_intpath
55
55
from .crypto import sha256
56
56
from . import util
57
+ from .lntransport import extract_nodeid
57
58
from .util import (NotEnoughFunds , UserCancelled , profiler , OldTaskGroup , ignore_exceptions ,
58
59
format_satoshis , format_fee_satoshis , NoDynamicFeeEstimates ,
59
60
WalletFileException , BitcoinException ,
60
61
InvalidPassword , format_time , timestamp_to_datetime , Satoshis ,
61
62
Fiat , bfh , TxMinedInfo , quantize_feerate , OrderedDictWithIndex )
63
+ from .lnutil import MIN_FUNDING_SAT
62
64
from .simple_config import SimpleConfig , FEE_RATIO_HIGH_WARNING , FEERATE_WARNING_HIGH_FEE
63
65
from .bitcoin import COIN , TYPE_ADDRESS
64
66
from .bitcoin import is_address , address_to_script , is_minikey , relayfee , dust_threshold
@@ -350,13 +352,17 @@ class ReceiveRequestHelp(NamedTuple):
350
352
351
353
ln_swap_suggestion : Optional [Any ] = None
352
354
ln_rebalance_suggestion : Optional [Any ] = None
355
+ ln_zeroconf_suggestion : bool = False
353
356
354
357
def can_swap (self ) -> bool :
355
358
return bool (self .ln_swap_suggestion )
356
359
357
360
def can_rebalance (self ) -> bool :
358
361
return bool (self .ln_rebalance_suggestion )
359
362
363
+ def can_zeroconf (self ) -> bool :
364
+ return self .ln_zeroconf_suggestion
365
+
360
366
361
367
class TxWalletDelta (NamedTuple ):
362
368
is_relevant : bool # "related to wallet?"
@@ -3278,12 +3284,19 @@ def get_help_texts_for_receive_request(self, req: Request) -> ReceiveRequestHelp
3278
3284
ln_is_error = False
3279
3285
ln_swap_suggestion = None
3280
3286
ln_rebalance_suggestion = None
3287
+ ln_zeroconf_suggestion = False
3281
3288
URI = self .get_request_URI (req ) or ''
3282
3289
lightning_has_channels = (
3283
3290
self .lnworker and len ([chan for chan in self .lnworker .channels .values () if chan .is_open ()]) > 0
3284
3291
)
3285
3292
lightning_online = self .lnworker and self .lnworker .num_peers () > 0
3286
3293
can_receive_lightning = self .lnworker and amount_sat <= self .lnworker .num_sats_can_receive ()
3294
+ try :
3295
+ zeroconf_nodeid = extract_nodeid (self .config .ZEROCONF_TRUSTED_NODE )[0 ]
3296
+ except Exception :
3297
+ zeroconf_nodeid = None
3298
+ can_get_zeroconf_channel = (self .lnworker and self .config .ACCEPT_ZEROCONF_CHANNELS
3299
+ and zeroconf_nodeid in self .lnworker .peers )
3287
3300
status = self .get_invoice_status (req )
3288
3301
3289
3302
if status == PR_EXPIRED :
@@ -3309,21 +3322,33 @@ def get_help_texts_for_receive_request(self, req: Request) -> ReceiveRequestHelp
3309
3322
address_help = URI_help = (_ ("This address has already been used. "
3310
3323
"For better privacy, do not reuse it for new payments." ))
3311
3324
if req .is_lightning ():
3312
- if not lightning_has_channels :
3325
+ if not lightning_has_channels and not can_get_zeroconf_channel :
3313
3326
ln_is_error = True
3314
3327
ln_help = _ ("You must have an open Lightning channel to receive payments." )
3315
3328
elif not lightning_online :
3316
3329
ln_is_error = True
3317
3330
ln_help = _ ('You must be online to receive Lightning payments.' )
3318
- elif not can_receive_lightning :
3319
- ln_is_error = True
3331
+ elif not can_receive_lightning or (amount_sat <= 0 and not lightning_has_channels ):
3320
3332
ln_rebalance_suggestion = self .lnworker .suggest_rebalance_to_receive (amount_sat )
3321
3333
ln_swap_suggestion = self .lnworker .suggest_swap_to_receive (amount_sat )
3322
- ln_help = _ ('You do not have the capacity to receive this amount with Lightning.' )
3323
- if bool (ln_rebalance_suggestion ):
3324
- ln_help += '\n \n ' + _ ('You may have that capacity if you rebalance your channels.' )
3325
- elif bool (ln_swap_suggestion ):
3326
- ln_help += '\n \n ' + _ ('You may have that capacity if you swap some of your funds.' )
3334
+ # prefer to use swaps over JIT channels if possible
3335
+ if can_get_zeroconf_channel and not bool (ln_rebalance_suggestion ) and not bool (ln_swap_suggestion ):
3336
+ if amount_sat < MIN_FUNDING_SAT :
3337
+ ln_is_error = True
3338
+ ln_help = (_ ('Cannot receive this payment. Request at least {} sat '
3339
+ 'to purchase a Lightning channel from your service provider.' )
3340
+ .format (MIN_FUNDING_SAT ))
3341
+ else :
3342
+ ln_zeroconf_suggestion = True
3343
+ ln_help = _ (f'Receiving this payment will purchase a payment channel from your '
3344
+ f'service provider. Service fees are deducted from the incoming payment.' )
3345
+ else :
3346
+ ln_is_error = True
3347
+ ln_help = _ ('You do not have the capacity to receive this amount with Lightning.' )
3348
+ if bool (ln_rebalance_suggestion ):
3349
+ ln_help += '\n \n ' + _ ('You may have that capacity if you rebalance your channels.' )
3350
+ elif bool (ln_swap_suggestion ):
3351
+ ln_help += '\n \n ' + _ ('You may have that capacity if you swap some of your funds.' )
3327
3352
# for URI that has LN part but no onchain part, copy error:
3328
3353
if not addr and ln_is_error :
3329
3354
URI_is_error = ln_is_error
@@ -3337,6 +3362,7 @@ def get_help_texts_for_receive_request(self, req: Request) -> ReceiveRequestHelp
3337
3362
ln_is_error = ln_is_error ,
3338
3363
ln_rebalance_suggestion = ln_rebalance_suggestion ,
3339
3364
ln_swap_suggestion = ln_swap_suggestion ,
3365
+ ln_zeroconf_suggestion = ln_zeroconf_suggestion
3340
3366
)
3341
3367
3342
3368
0 commit comments