From fa8e74a2ad4915d3b9c17dcbb660ba345e8b3eb8 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Wed, 8 Sep 2021 06:26:06 +0930 Subject: [PATCH] pyln-client/gossmap: make node and node_id comparable with __lt__ and __eq__ --- contrib/pyln-client/pyln/client/gossmap.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/contrib/pyln-client/pyln/client/gossmap.py b/contrib/pyln-client/pyln/client/gossmap.py index 9e807c679..4f39a6851 100755 --- a/contrib/pyln-client/pyln/client/gossmap.py +++ b/contrib/pyln-client/pyln/client/gossmap.py @@ -65,8 +65,12 @@ class GossmapNodeId(object): 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__() @@ -143,6 +147,16 @@ class GossmapNode(object): 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"""