From 0878fe08f77ce15d47a3b597a50a2b7e7e8f897f Mon Sep 17 00:00:00 2001 From: ThomasV Date: Mon, 1 Jun 2020 22:18:08 +0200 Subject: [PATCH] do not display 'Expires in 100 years' for LN invoices --- electrum/invoices.py | 8 +++++++- electrum/lnworker.py | 8 ++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/electrum/invoices.py b/electrum/invoices.py index c003685ce..52733ec5b 100644 --- a/electrum/invoices.py +++ b/electrum/invoices.py @@ -56,6 +56,12 @@ assert PR_DEFAULT_EXPIRATION_WHEN_CREATING in pr_expiration_values outputs_decoder = lambda _list: [PartialTxOutput.from_legacy_tuple(*x) for x in _list] +# hack: BOLT-11 is not really clear on what an expiry of 0 means. +# It probably interprets it as 0 seconds, so already expired... +# Our higher level invoices code however uses 0 for "never". +# Hence set some high expiration here +LN_EXPIRY_NEVER = 100 * 365 * 24 * 60 * 60 # 100 years + @attr.s class Invoice(StoredObject): type = attr.ib(type=int) @@ -70,7 +76,7 @@ class Invoice(StoredObject): def get_status_str(self, status): status_str = pr_tooltips[status] if status == PR_UNPAID: - if self.exp > 0: + if self.exp > 0 and self.exp != LN_EXPIRY_NEVER: expiration = self.exp + self.time status_str = _('Expires') + ' ' + age(expiration, include_seconds=True) else: diff --git a/electrum/lnworker.py b/electrum/lnworker.py index 443234061..a5cc3f2a7 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -24,7 +24,7 @@ from aiorpcx import run_in_thread from . import constants, util from . import keystore from .util import profiler -from .invoices import PR_TYPE_LN, PR_UNPAID, PR_EXPIRED, PR_PAID, PR_INFLIGHT, PR_FAILED, PR_ROUTING, LNInvoice +from .invoices import PR_TYPE_LN, PR_UNPAID, PR_EXPIRED, PR_PAID, PR_INFLIGHT, PR_FAILED, PR_ROUTING, LNInvoice, LN_EXPIRY_NEVER from .util import NetworkRetryManager from .lnutil import LN_MAX_FUNDING_SAT from .keystore import BIP32_KeyStore @@ -1086,11 +1086,7 @@ class LNWallet(LNWorker): info = PaymentInfo(payment_hash, amount_sat, RECEIVED, PR_UNPAID) amount_btc = amount_sat/Decimal(COIN) if amount_sat else None if expiry == 0: - # hack: BOLT-11 is not really clear on what an expiry of 0 means. - # It probably interprets it as 0 seconds, so already expired... - # Our higher level invoices code however uses 0 for "never". - # Hence set some high expiration here - expiry = 100 * 365 * 24 * 60 * 60 # 100 years + expiry = LN_EXPIRY_NEVER lnaddr = LnAddr(paymenthash=payment_hash, amount=amount_btc, tags=[('d', message),