pyln-client/gossmap: init GossmapNode and Id also with hexstring

also improves test coverage
Changelog-Added: pyln-client: routines for direct access to the gossip store as Gossmap
This commit is contained in:
Michael Schmoock
2021-09-08 06:26:06 +09:30
committed by Rusty Russell
parent fa8e74a2ad
commit 125752118a
2 changed files with 30 additions and 1 deletions

View File

@@ -55,6 +55,8 @@ class GossmapHalfchannel(object):
class GossmapNodeId(object):
def __init__(self, buf: bytes):
if isinstance(buf, str):
buf = bytes.fromhex(buf)
if len(buf) != 33 or (buf[0] != 2 and buf[0] != 3):
raise ValueError("{} is not a valid node_id".format(buf.hex()))
self.nodeid = buf
@@ -139,6 +141,8 @@ class GossmapNode(object):
.channels is a list of the GossmapChannels attached to this node.
"""
def __init__(self, node_id: GossmapNodeId):
if isinstance(node_id, bytes) or isinstance(node_id, str):
node_id = GossmapNodeId(node_id)
self.announce_fields: Optional[Dict[str, Any]] = None
self.announce_offset: Optional[int] = None
self.channels: List[GossmapChannel] = []