1
0

invoices: deal with expiration of "0" mess

Internally, we've been using an expiration of 0 to mean "never expires".
For LN invoices, BOLT-11 does not specify what an expiration of 0 means.
Other clients seem to treat it as "0 seconds" (i.e. already expired).
This means there is no way to create a BOLT-11 invoice that "never" expires.

For LN invoices,
- we now treat an expiration of 0, , as "0 seconds",
- when creating an invoice, if the user selected never, we will put 100 years as expiration
This commit is contained in:
SomberNight
2020-03-04 14:24:07 +01:00
parent 4c177c4c92
commit 7962e17df6
5 changed files with 33 additions and 17 deletions

View File

@@ -199,6 +199,8 @@ def lnencode(addr, privkey):
# Get minimal length by trimming leading 5 bits at a time.
expirybits = bitstring.pack('intbe:64', v)[4:64]
while expirybits.startswith('0b00000'):
if len(expirybits) == 5:
break # v == 0
expirybits = expirybits[5:]
data += tagged('x', expirybits)
elif k == 'h':
@@ -259,21 +261,24 @@ class LnAddr(object):
return self._min_final_cltv_expiry
def get_tag(self, tag):
description = ''
for k,v in self.tags:
for k, v in self.tags:
if k == tag:
description = v
break
return description
return v
return None
def get_description(self):
return self.get_tag('d')
def get_description(self) -> str:
return self.get_tag('d') or ''
def get_expiry(self):
return int(self.get_tag('x') or '3600')
def get_expiry(self) -> int:
exp = self.get_tag('x')
if exp is None:
exp = 3600
return int(exp)
def is_expired(self):
def is_expired(self) -> bool:
now = time.time()
# BOLT-11 does not specify what expiration of '0' means.
# we treat it as 0 seconds here (instead of never)
return now > self.get_expiry() + self.date