diff --git a/contrib/pyln-client/pyln/client/gossmap.py b/contrib/pyln-client/pyln/client/gossmap.py index 5ad15e248..25d92942d 100755 --- a/contrib/pyln-client/pyln/client/gossmap.py +++ b/contrib/pyln-client/pyln/client/gossmap.py @@ -262,6 +262,17 @@ class Gossmap(object): short_channel_id = ShortChannelId.from_str(short_channel_id) return self.channels.get(short_channel_id) + def get_halfchannel(self, + short_channel_id: Union[ShortChannelId, str], + direction: int): + """ Returns a GossmapHalfchannel identified by a scid and direction. """ + assert short_channel_id is not None + if isinstance(short_channel_id, str): + short_channel_id = ShortChannelId.from_str(short_channel_id) + assert direction in [0, 1], "direction can only be 0 or 1" + channel = self.get_channel(short_channel_id) + return channel.half_channels[direction] + def get_node(self, node_id: Union[GossmapNodeId, str]): """ Resolves a node by its public key node_id """ if isinstance(node_id, str): diff --git a/contrib/pyln-client/tests/test_gossmap.py b/contrib/pyln-client/tests/test_gossmap.py index 5fa38ecc9..0daa1b22a 100644 --- a/contrib/pyln-client/tests/test_gossmap.py +++ b/contrib/pyln-client/tests/test_gossmap.py @@ -70,7 +70,7 @@ def test_gossmap_halfchannel(tmp_path): assert chan.node2 == n2 half0 = chan.get_direction(0) - half1 = chan.get_direction(1) + half1 = g.get_halfchannel("103x1x1", 1) assert half0 assert half1 assert half0.direction == 0