1
1
#! /usr/bin/python3
2
2
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 )
5
7
from pyln .proto import ShortChannelId , PublicKey
6
8
from typing import Any , Dict , List , Optional
7
9
@@ -60,8 +62,7 @@ def __init__(self,
60
62
self .node2_id = node2_id
61
63
self .updates_fields : List [Optional [Dict [str , Any ]]] = [None , None ]
62
64
self .updates_offset : List [Optional [int ]] = [None , None ]
63
-
64
- self .capacity = None # TODO: where do we get this?
65
+ self .satoshis = None
65
66
self .half_channels : List [GossmapHalfchannel ] = [None , None ]
66
67
67
68
def update_channel (self ,
@@ -135,6 +136,7 @@ def __init__(self, store_filename: str = "gossip_store"):
135
136
self .store_buf = bytes ()
136
137
self .nodes : Dict [bytes , GossmapNode ] = {}
137
138
self .channels : Dict [ShortChannelId , GossmapChannel ] = {}
139
+ self ._last_scid : str = None
138
140
version = self .store_file .read (1 )
139
141
if version [0 ] != GOSSIP_STORE_VERSION :
140
142
raise ValueError ("Invalid gossip store version {}" .format (version ))
@@ -156,6 +158,7 @@ def _new_channel(self,
156
158
if node2_id not in self .nodes :
157
159
self .nodes [node2_id ] = GossmapNode (node2_id )
158
160
161
+ self ._last_scid = scid
159
162
self .channels [scid ] = c
160
163
self .nodes [node1_id ].channels .append (c )
161
164
self .nodes [node2_id ].channels .append (c )
@@ -179,6 +182,11 @@ def add_channel(self, rec: bytes, off: int, is_private: bool):
179
182
GossmapNodeId (fields ['node_id_1' ]), GossmapNodeId (fields ['node_id_2' ]),
180
183
is_private )
181
184
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
+
182
190
def get_channel (self , short_channel_id : ShortChannelId ):
183
191
""" Resolves a channel by its short channel id """
184
192
if type (short_channel_id ) == str :
@@ -252,6 +260,8 @@ def refresh(self):
252
260
self .add_channel (rec , off , False )
253
261
elif rectype == WIRE_GOSSIP_STORE_PRIVATE_CHANNEL :
254
262
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 )
255
265
elif rectype == channel_update .number :
256
266
self .update_channel (rec , off )
257
267
elif rectype == WIRE_GOSSIP_STORE_PRIVATE_UPDATE :
0 commit comments