mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 00:54:20 +01:00
pyln-client/gossmap: make node and node_id comparable with __lt__ and __eq__
This commit is contained in:
committed by
Rusty Russell
parent
47efea92c6
commit
fa8e74a2ad
@@ -65,8 +65,12 @@ class GossmapNodeId(object):
|
|||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if not isinstance(other, GossmapNodeId):
|
if not isinstance(other, GossmapNodeId):
|
||||||
return False
|
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):
|
def __hash__(self):
|
||||||
return self.nodeid.__hash__()
|
return self.nodeid.__hash__()
|
||||||
@@ -143,6 +147,16 @@ class GossmapNode(object):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "GossmapNode[{}]".format(self.node_id.nodeid.hex())
|
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 Gossmap(object):
|
||||||
"""Class to represent the gossip map of the network"""
|
"""Class to represent the gossip map of the network"""
|
||||||
|
|||||||
Reference in New Issue
Block a user