Skip to content

Commit

Permalink
pygossmap: adds get_halfchannel
Browse files Browse the repository at this point in the history
  • Loading branch information
m-schmoock committed Feb 17, 2023
1 parent 2adeb1c commit 69bfeca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions contrib/pyln-client/pyln/client/gossmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,17 @@ def get_channel(self, short_channel_id: Union[ShortChannelId, str]):
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):
Expand Down
2 changes: 1 addition & 1 deletion contrib/pyln-client/tests/test_gossmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 69bfeca

Please sign in to comment.