From 887fb38e06da6d0fcb2bafcbf0fd06912f3c7044 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 7 Sep 2021 13:39:15 +0930 Subject: [PATCH] pyln-client/gossmap: use ShortChannelId class from pyln.proto, if available. Signed-off-by: Rusty Russell --- contrib/pyln-client/pyln/client/gossmap.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/contrib/pyln-client/pyln/client/gossmap.py b/contrib/pyln-client/pyln/client/gossmap.py index f374e1914..c0ff524c1 100755 --- a/contrib/pyln-client/pyln/client/gossmap.py +++ b/contrib/pyln-client/pyln/client/gossmap.py @@ -2,6 +2,7 @@ from pyln.spec.bolt7 import (channel_announcement, channel_update, node_announcement) +from pyln.proto import ShortChannelId from typing import Any, Dict, List, Optional import io @@ -28,11 +29,6 @@ class GossipStoreHeader(object): self.length = (length & GOSSIP_STORE_LEN_MASK) -# FIXME! -class short_channel_id(int): - pass - - class point(bytes): pass @@ -75,7 +71,7 @@ class Gossmap(object): self.store_file = open(store_filename, "rb") self.store_buf = bytes() self.nodes: Dict[point, GossmapNode] = {} - self.channels: Dict[short_channel_id, GossmapChannel] = {} + self.channels: Dict[ShortChannelId, GossmapChannel] = {} version = self.store_file.read(1) if version[0] != GOSSIP_STORE_VERSION: raise ValueError("Invalid gossip store version {}".format(version)) @@ -85,7 +81,7 @@ class Gossmap(object): def _new_channel(self, fields: Dict[str, Any], announce_offset: int, - scid: short_channel_id, + scid: ShortChannelId, node1_id: point, node2_id: point, is_private: bool): @@ -101,7 +97,7 @@ class Gossmap(object): self.nodes[node1_id].channels.append(c) self.nodes[node2_id].channels.append(c) - def _del_channel(self, scid: short_channel_id): + def _del_channel(self, scid: ShortChannelId): c = self.channels[scid] n1 = self.nodes[c.node1_id] n2 = self.nodes[c.node2_id] @@ -115,14 +111,15 @@ class Gossmap(object): def add_channel(self, rec: bytes, off: int, is_private: bool): fields = channel_announcement.read(io.BytesIO(rec[2:]), {}) - self._new_channel(fields, off, fields['short_channel_id'], + self._new_channel(fields, off, + ShortChannelId.from_int(fields['short_channel_id']), fields['node_id_1'], fields['node_id_2'], is_private) def update_channel(self, rec: bytes, off: int): fields = channel_update.read(io.BytesIO(rec[2:]), {}) direction = fields['channel_flags'] & 1 - c = self.channels[fields['short_channel_id']] + c = self.channels[ShortChannelId.from_int(fields['short_channel_id'])] c.updates_fields[direction] = fields c.updates_offset = off