Skip to content

Commit

Permalink
gossmap: adds __repr__ functions
Browse files Browse the repository at this point in the history
  • Loading branch information
m-schmoock committed Aug 24, 2021
1 parent 6ddb573 commit a5b83fb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
42 changes: 27 additions & 15 deletions contrib/pyln-client/pyln/client/gossmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ def __init__(self, buf: bytes):
self.length = (length & GOSSIP_STORE_LEN_MASK)


class GossmapHalfchannel(object):
"""One direction of a GossmapChannel."""
def __init__(self, timestamp: int,
cltv_expiry_delta: int,
htlc_minimum_msat: int, htlc_maximum_msat: int,
fee_base_msat: int, fee_proportional_millionths: int):
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


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."""
def __init__(self,
Expand Down Expand Up @@ -72,7 +58,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 +73,28 @@ 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 GossmapHalfchannel(object):
"""One direction of a GossmapChannel."""
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 GossmapNodeId(object):
def __init__(self, buf: bytes):
Expand Down Expand Up @@ -120,6 +129,9 @@ def __init__(self, node_id: GossmapNodeId):
self.channels = []
self.node_id = node_id

def __repr__(self):
return "GossmapNode[0x{}]".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 a5b83fb

Please sign in to comment.