Skip to content

Commit

Permalink
fix: ln-info delivers wrong identity_uri #202
Browse files Browse the repository at this point in the history
  • Loading branch information
fusion44 committed May 20, 2023
1 parent 93a62ad commit 9255a51
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions app/lightning/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from typing import List, Optional, Union

from deepdiff import DeepDiff
from fastapi import HTTPException
from fastapi.param_functions import Query
from loguru import logger
from pydantic import BaseModel, validator
from pydantic.types import conint

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

identity_pubkey: str = Query("The identity pubkey of the current node.")
identity_pubkey: str = Query(
..., description="The identity pubkey of the current node."
)

identity_uri: str = Query(
"The complete URI (pubkey@physicaladdress:port) the current node."
...,
description="The complete URI (pubkey@physicaladdress:port) the current node.",
)

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

_uris = []
for b in i["binding"]:
_uris.append(f"{b['address']}:{b['port']}")
pubkey = i["id"]
if "binding" in i:
for b in i["binding"]:
_uris.append(f"{pubkey}@{b['address']}:{b['port']}")

if "address" in i:
for b in i["address"]:
_uris.append(f"{pubkey}@{b['address']}:{b['port']}")

uri = ""
if len(_uris) > 0:
uri = _uris[0]

return LnInfo(
implementation=implementation,
version=i["version"],
commit_hash=i["version"].split("-")[-1],
identity_pubkey=i["id"],
identity_pubkey=pubkey,
identity_uri=uri,
alias=i["alias"],
color=i["color"],
num_pending_channels=i["num_pending_channels"],
Expand Down Expand Up @@ -1514,6 +1530,7 @@ class LightningInfoLite(BaseModel):
)

@classmethod
@logger.catch(exclude=(HTTPException,))
def from_lninfo(cls, info: LnInfo):
return cls(
implementation=info.implementation,
Expand Down

0 comments on commit 9255a51

Please sign in to comment.