Skip to content

Commit 9255a51

Browse files
committed
fix: ln-info delivers wrong identity_uri #202
1 parent 93a62ad commit 9255a51

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

app/lightning/models.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from typing import List, Optional, Union
44

55
from deepdiff import DeepDiff
6+
from fastapi import HTTPException
67
from fastapi.param_functions import Query
8+
from loguru import logger
79
from pydantic import BaseModel, validator
810
from pydantic.types import conint
911

@@ -1318,10 +1320,13 @@ class LnInfo(BaseModel):
13181320
..., description="The SHA1 commit hash that the daemon is compiled with."
13191321
)
13201322

1321-
identity_pubkey: str = Query("The identity pubkey of the current node.")
1323+
identity_pubkey: str = Query(
1324+
..., description="The identity pubkey of the current node."
1325+
)
13221326

13231327
identity_uri: str = Query(
1324-
"The complete URI (pubkey@physicaladdress:port) the current node."
1328+
...,
1329+
description="The complete URI (pubkey@physicaladdress:port) the current node.",
13251330
)
13261331

13271332
alias: str = Query(..., description="The alias of the node.")
@@ -1431,14 +1436,25 @@ def from_cln_jrpc(cls, implementation, i) -> "LnInfo":
14311436
# _features.append(FeaturesEntry.from_cln_json(i["our_features"][k], k))
14321437

14331438
_uris = []
1434-
for b in i["binding"]:
1435-
_uris.append(f"{b['address']}:{b['port']}")
1439+
pubkey = i["id"]
1440+
if "binding" in i:
1441+
for b in i["binding"]:
1442+
_uris.append(f"{pubkey}@{b['address']}:{b['port']}")
1443+
1444+
if "address" in i:
1445+
for b in i["address"]:
1446+
_uris.append(f"{pubkey}@{b['address']}:{b['port']}")
1447+
1448+
uri = ""
1449+
if len(_uris) > 0:
1450+
uri = _uris[0]
14361451

14371452
return LnInfo(
14381453
implementation=implementation,
14391454
version=i["version"],
14401455
commit_hash=i["version"].split("-")[-1],
1441-
identity_pubkey=i["id"],
1456+
identity_pubkey=pubkey,
1457+
identity_uri=uri,
14421458
alias=i["alias"],
14431459
color=i["color"],
14441460
num_pending_channels=i["num_pending_channels"],
@@ -1514,6 +1530,7 @@ class LightningInfoLite(BaseModel):
15141530
)
15151531

15161532
@classmethod
1533+
@logger.catch(exclude=(HTTPException,))
15171534
def from_lninfo(cls, info: LnInfo):
15181535
return cls(
15191536
implementation=info.implementation,

0 commit comments

Comments
 (0)