Skip to content

Commit

Permalink
pyln-client/gossmap: make node and node_id comparable with __lt__ and…
Browse files Browse the repository at this point in the history
… __eq__
  • Loading branch information
m-schmoock authored and rustyrussell committed Sep 2, 2021
1 parent 6f13022 commit 9564166
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion contrib/pyln-client/pyln/client/gossmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ def to_pubkey(self) -> PublicKey:
def __eq__(self, other):
if not isinstance(other, GossmapNodeId):
return False
return self.nodeid.__eq__(other.nodeid)

return self.nodeid == other.nodeid
def __lt__(self, other):
if not isinstance(other, GossmapNodeId):
raise ValueError(f"Cannot compare GossmapNodeId with {type(other)}")
return self.nodeid.__lt__(other.nodeid) # yes, that works

def __hash__(self):
return self.nodeid.__hash__()
Expand Down Expand Up @@ -144,6 +148,16 @@ def __init__(self, node_id: GossmapNodeId):
def __repr__(self):
return "GossmapNode[{}]".format(self.node_id.nodeid.hex())

def __eq__(self, other):
if not isinstance(other, GossmapNode):
return False
return self.node_id.__eq__(other.node_id)

def __lt__(self, other):
if not isinstance(other, GossmapNode):
raise ValueError(f"Cannot compare GossmapNode with {type(other)}")
return self.node_id.__lt__(other.node_id)


class Gossmap(object):
"""Class to represent the gossip map of the network"""
Expand Down

0 comments on commit 9564166

Please sign in to comment.