diff --git a/contrib/pyln-client/pyln/client/gossmap.py b/contrib/pyln-client/pyln/client/gossmap.py index f10f490f0..79d5d2b21 100755 --- a/contrib/pyln-client/pyln/client/gossmap.py +++ b/contrib/pyln-client/pyln/client/gossmap.py @@ -32,10 +32,12 @@ class GossipStoreHeader(object): class GossmapHalfchannel(object): """One direction of a GossmapChannel.""" - def __init__(self, timestamp: int, - cltv_expiry_delta: int, + def __init__(self, channel: GossmapChannel, direction: int, + timestamp: int, cltv_expiry_delta: int, htlc_minimum_msat: int, htlc_maximum_msat: int, fee_base_msat: int, fee_proportional_millionths: int): + self.channel = channel + self.direction = direction self.timestamp: int = timestamp self.cltv_expiry_delta: int = cltv_expiry_delta self.htlc_minimum_msat: int = htlc_minimum_msat @@ -43,6 +45,9 @@ class GossmapHalfchannel(object): self.fee_base_msat: int = fee_base_msat self.fee_proportional_millionths: int = fee_proportional_millionths + def __repr__(self): + return "GossmapHalfchannel[{}x{}]".format(str(self.channel.scid), self.direction) + class GossmapChannel(object): """A channel: fields of channel_announcement are in .fields, optional updates are in .updates_fields, which can be None if there has been no channel update.""" @@ -71,7 +76,8 @@ class GossmapChannel(object): self.updates_fields[direction] = fields self.updates_offset = off - half = GossmapHalfchannel(fields['timestamp'], + half = GossmapHalfchannel(self, direction, + fields['timestamp'], fields['cltv_expiry_delta'], fields['htlc_minimum_msat'], fields.get('htlc_maximum_msat', None), @@ -85,6 +91,9 @@ class GossmapChannel(object): raise ValueError("direction can only be 0 or 1") return self.half_channels[direction] + def __repr__(self): + return "GossmapChannel[{}]".format(str(self.scid)) + class GossmapNodeId(object): def __init__(self, buf: bytes): @@ -105,7 +114,7 @@ class GossmapNodeId(object): return self.nodeid.__hash__() def __repr__(self): - return "GossmapNodeId[0x{}]".format(self.nodeid.hex()) + return "GossmapNodeId[{}]".format(self.nodeid.hex()) def from_str(self, s: str): if s.startswith('0x'): @@ -126,6 +135,9 @@ class GossmapNode(object): self.channels = [] self.node_id = node_id + def __repr__(self): + return "GossmapNode[{}]".format(self.node_id.nodeid.hex()) + class Gossmap(object): """Class to represent the gossip map of the network""" diff --git a/contrib/pyln-proto/pyln/proto/primitives.py b/contrib/pyln-proto/pyln/proto/primitives.py index 151424b86..d9deb6a9c 100644 --- a/contrib/pyln-proto/pyln/proto/primitives.py +++ b/contrib/pyln-proto/pyln/proto/primitives.py @@ -88,6 +88,9 @@ class ShortChannelId(object): def __hash__(self): return self.to_int().__hash__() + def __repr__(self): + return "ShortChannelId[{}]".format(str(self)) + class Secret(object): def __init__(self, data: bytes) -> None: