Skip to content

Commit 81fbbd9

Browse files
committed
gossmap: adds __repr__ functions
1 parent d66859b commit 81fbbd9

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

contrib/pyln-client/pyln/client/gossmap.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,6 @@ def __init__(self, buf: bytes):
3131
self.length = (length & GOSSIP_STORE_LEN_MASK)
3232

3333

34-
class GossmapHalfchannel(object):
35-
"""One direction of a GossmapChannel."""
36-
def __init__(self, timestamp: int,
37-
cltv_expiry_delta: int,
38-
htlc_minimum_msat: int, htlc_maximum_msat: int,
39-
fee_base_msat: int, fee_proportional_millionths: int):
40-
self.timestamp: int = timestamp
41-
self.cltv_expiry_delta: int = cltv_expiry_delta
42-
self.htlc_minimum_msat: int = htlc_minimum_msat
43-
self.htlc_maximum_msat: Optional[int] = htlc_maximum_msat
44-
self.fee_base_msat: int = fee_base_msat
45-
self.fee_proportional_millionths: int = fee_proportional_millionths
46-
47-
4834
class GossmapChannel(object):
4935
"""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."""
5036
def __init__(self,
@@ -72,7 +58,8 @@ def update_channel(self,
7258
self.updates_fields[direction] = fields
7359
self.updates_offset = off
7460

75-
half = GossmapHalfchannel(fields['timestamp'],
61+
half = GossmapHalfchannel(self, direction,
62+
fields['timestamp'],
7663
fields['cltv_expiry_delta'],
7764
fields['htlc_minimum_msat'],
7865
fields.get('htlc_maximum_msat', None),
@@ -86,6 +73,28 @@ def get_half_channel(self, direction: int):
8673
raise ValueError("direction can only be 0 or 1")
8774
return self.half_channels[direction]
8875

76+
def __repr__(self):
77+
return "GossmapChannel[{}]".format(str(self.scid))
78+
79+
80+
class GossmapHalfchannel(object):
81+
"""One direction of a GossmapChannel."""
82+
def __init__(self, channel: GossmapChannel, direction: int,
83+
timestamp: int, cltv_expiry_delta: int,
84+
htlc_minimum_msat: int, htlc_maximum_msat: int,
85+
fee_base_msat: int, fee_proportional_millionths: int):
86+
self.channel = channel
87+
self.direction = direction
88+
self.timestamp: int = timestamp
89+
self.cltv_expiry_delta: int = cltv_expiry_delta
90+
self.htlc_minimum_msat: int = htlc_minimum_msat
91+
self.htlc_maximum_msat: Optional[int] = htlc_maximum_msat
92+
self.fee_base_msat: int = fee_base_msat
93+
self.fee_proportional_millionths: int = fee_proportional_millionths
94+
95+
def __repr__(self):
96+
return "GossmapHalfChannel[{}x{}]".format(str(self.channel.scid), self.direction)
97+
8998

9099
class GossmapNodeId(object):
91100
def __init__(self, buf: bytes):
@@ -106,7 +115,7 @@ def __hash__(self):
106115
return self.nodeid.__hash__()
107116

108117
def __repr__(self):
109-
return "GossmapNodeId[0x{}]".format(self.nodeid.hex())
118+
return "GossmapNodeId[{}]".format(self.nodeid.hex())
110119

111120
def from_str(self, s: str):
112121
if s.startswith('0x'):
@@ -127,6 +136,9 @@ def __init__(self, node_id: GossmapNodeId):
127136
self.channels = []
128137
self.node_id = node_id
129138

139+
def __repr__(self):
140+
return "GossmapNode[{}]".format(self.node_id.nodeid.hex())
141+
130142

131143
class Gossmap(object):
132144
"""Class to represent the gossip map of the network"""

contrib/pyln-proto/pyln/proto/primitives.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ def __eq__(self, other: object) -> bool:
8888
def __hash__(self):
8989
return self.to_int().__hash__()
9090

91+
def __repr__(self):
92+
return "ShortChannelId[{}]".format(str(self))
93+
9194

9295
class Secret(object):
9396
def __init__(self, data: bytes) -> None:

0 commit comments

Comments
 (0)