Skip to content

Commit

Permalink
pyln-client/gossmap: adds __repr__ functions
Browse files Browse the repository at this point in the history
  • Loading branch information
m-schmoock authored and rustyrussell committed Aug 26, 2021
1 parent 1916e65 commit 9e82d6c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 16 additions & 4 deletions contrib/pyln-client/pyln/client/gossmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,22 @@ def __init__(self, buf: bytes):

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
self.htlc_maximum_msat: Optional[int] = htlc_maximum_msat
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."""
Expand Down Expand Up @@ -72,7 +77,8 @@ def update_channel(self,
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),
Expand All @@ -86,6 +92,9 @@ def get_half_channel(self, direction: int):
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):
Expand All @@ -106,7 +115,7 @@ def __hash__(self):
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'):
Expand All @@ -127,6 +136,9 @@ def __init__(self, node_id: GossmapNodeId):
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"""
Expand Down
3 changes: 3 additions & 0 deletions contrib/pyln-proto/pyln/proto/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def __eq__(self, other: object) -> bool:
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:
Expand Down

0 comments on commit 9e82d6c

Please sign in to comment.