1
0

invoices: Use the same base method to export invoices and requests.

This fixes an inconsistency where the 'expiration' field was
relative for invoices, and absolute timestamp for requests.

This in turn fixes QML the timer refreshing the request list.

In order to prevent any API using that field from being silently
broken, the 'expiration' field is renamed as 'expiry'.
This commit is contained in:
ThomasV
2023-03-31 14:25:40 +02:00
parent 2cda5a1a7b
commit 56e685feaa
4 changed files with 33 additions and 42 deletions

View File

@@ -6,7 +6,7 @@ import attr
from .json_db import StoredObject
from .i18n import _
from .util import age, InvoiceError
from .util import age, InvoiceError, format_satoshis
from .lnutil import hex_to_bytes
from .lnaddr import lndecode, LnAddr
from . import constants
@@ -222,6 +222,23 @@ class BaseInvoice(StoredObject):
else: # on-chain
return get_id_from_onchain_outputs(outputs=self.get_outputs(), timestamp=self.time)
def as_dict(self, status):
d = {
'is_lightning': self.is_lightning(),
'amount_BTC': format_satoshis(self.get_amount_sat()),
'message': self.message,
'timestamp': self.get_time(),
'expiry': self.exp,
'status': status,
'status_str': self.get_status_str(status),
'id': self.get_id(),
'amount_sat': int(self.get_amount_sat()),
}
if self.is_lightning():
d['amount_msat'] = self.get_amount_msat()
return d
@attr.s
class Invoice(BaseInvoice):
lightning_invoice = attr.ib(type=str, kw_only=True) # type: Optional[str]