11#! /usr/bin/python3
22
3- from pyln .spec .bolt7 import (channel_announcement , channel_update ,
4- node_announcement )
3+ from pyln .spec .bolt7 import (channel_announcement ,
4+ channel_update ,
5+ node_announcement ,
6+ gossip_store_channel_amount )
57from pyln .proto import ShortChannelId , PublicKey
68from typing import Any , Dict , List , Optional
79
@@ -60,8 +62,7 @@ def __init__(self,
6062 self .node2_id = node2_id
6163 self .updates_fields : List [Optional [Dict [str , Any ]]] = [None , None ]
6264 self .updates_offset : List [Optional [int ]] = [None , None ]
63-
64- self .capacity = None # TODO: where do we get this?
65+ self .satoshis = None
6566 self .half_channels : List [GossmapHalfchannel ] = [None , None ]
6667
6768 def update_channel (self ,
@@ -135,6 +136,7 @@ def __init__(self, store_filename: str = "gossip_store"):
135136 self .store_buf = bytes ()
136137 self .nodes : Dict [bytes , GossmapNode ] = {}
137138 self .channels : Dict [ShortChannelId , GossmapChannel ] = {}
139+ self ._last_scid : str = None
138140 version = self .store_file .read (1 )
139141 if version [0 ] != GOSSIP_STORE_VERSION :
140142 raise ValueError ("Invalid gossip store version {}" .format (version ))
@@ -156,6 +158,7 @@ def _new_channel(self,
156158 if node2_id not in self .nodes :
157159 self .nodes [node2_id ] = GossmapNode (node2_id )
158160
161+ self ._last_scid = scid
159162 self .channels [scid ] = c
160163 self .nodes [node1_id ].channels .append (c )
161164 self .nodes [node2_id ].channels .append (c )
@@ -179,6 +182,11 @@ def add_channel(self, rec: bytes, off: int, is_private: bool):
179182 GossmapNodeId (fields ['node_id_1' ]), GossmapNodeId (fields ['node_id_2' ]),
180183 is_private )
181184
185+ def _set_channel_amount (self , rec : bytes ):
186+ """ Sets channel capacity of last added channel """
187+ fields = gossip_store_channel_amount .read (io .BytesIO (rec [2 :]), {})
188+ self .channels [self ._last_scid ].satoshis = fields ['satoshis' ]
189+
182190 def get_channel (self , short_channel_id : ShortChannelId ):
183191 """ Resolves a channel by its short channel id """
184192 if type (short_channel_id ) == str :
@@ -252,6 +260,8 @@ def refresh(self):
252260 self .add_channel (rec , off , False )
253261 elif rectype == WIRE_GOSSIP_STORE_PRIVATE_CHANNEL :
254262 self .add_channel (rec [2 + 8 + 2 :], off + 2 + 8 + 2 , True )
263+ elif rectype == gossip_store_channel_amount .number :
264+ self ._set_channel_amount (rec )
255265 elif rectype == channel_update .number :
256266 self .update_channel (rec , off )
257267 elif rectype == WIRE_GOSSIP_STORE_PRIVATE_UPDATE :
0 commit comments