From e2ee79c378191669fd900cc628683523ff59bd29 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 16 Jun 2023 17:08:41 +0000 Subject: [PATCH] lnaddr: add LnAddr.to_debug_json() method --- electrum/invoices.py | 12 +----------- electrum/lnaddr.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/electrum/invoices.py b/electrum/invoices.py index b184388b3..6f7300e36 100644 --- a/electrum/invoices.py +++ b/electrum/invoices.py @@ -290,17 +290,7 @@ class Invoice(BaseInvoice): def to_debug_json(self) -> Dict[str, Any]: d = self.to_json() - d.update({ - 'pubkey': self._lnaddr.pubkey.serialize().hex(), - 'amount_BTC': str(self._lnaddr.amount), - 'rhash': self._lnaddr.paymenthash.hex(), - 'description': self._lnaddr.get_description(), - 'exp': self._lnaddr.get_expiry(), - 'time': self._lnaddr.date, - }) - if ln_routing_info := self._lnaddr.get_routing_info('r'): - # show the last hop of routing hints. (our invoices only have one hop) - d['r_tags'] = [str((a.hex(),b.hex(),c,d,e)) for a,b,c,d,e in ln_routing_info[-1]] + d["lnaddr"] = self._lnaddr.to_debug_json() return d diff --git a/electrum/lnaddr.py b/electrum/lnaddr.py index 8689be0a7..fea9e2ce6 100644 --- a/electrum/lnaddr.py +++ b/electrum/lnaddr.py @@ -6,7 +6,7 @@ import time from hashlib import sha256 from binascii import hexlify from decimal import Decimal -from typing import Optional, TYPE_CHECKING, Type +from typing import Optional, TYPE_CHECKING, Type, Dict, Any import random import bitstring @@ -354,6 +354,25 @@ class LnAddr(object): # we treat it as 0 seconds here (instead of never) return now > self.get_expiry() + self.date + def to_debug_json(self) -> Dict[str, Any]: + d = { + 'pubkey': self.pubkey.serialize().hex(), + 'amount_BTC': str(self.amount), + 'rhash': self.paymenthash.hex(), + 'payment_secret': self.payment_secret.hex() if self.payment_secret else None, + 'description': self.get_description(), + 'exp': self.get_expiry(), + 'time': self.date, + 'min_final_cltv_expiry': self.get_min_final_cltv_expiry(), + 'features': self.get_features().get_names(), + 'tags': self.tags, + 'unknown_tags': self.unknown_tags, + } + if ln_routing_info := self.get_routing_info('r'): + # show the last hop of routing hints. (our invoices only have one hop) + d['r_tags'] = [str((a.hex(),b.hex(),c,d,e)) for a,b,c,d,e in ln_routing_info[-1]] + return d + class SerializableKey: def __init__(self, pubkey):