lnmsg: pass filename as parameter instead of boolean
This commit is contained in:
+4
-7
@@ -323,7 +323,7 @@ def _parse_msgtype_intvalue_for_onion_wire(value: str) -> int:
|
|||||||
|
|
||||||
class LNSerializer:
|
class LNSerializer:
|
||||||
|
|
||||||
def __init__(self, *, for_onion_wire: bool = False):
|
def __init__(self, *, name: str = 'peer_wire'):
|
||||||
# TODO msg_type could be 'int' everywhere...
|
# TODO msg_type could be 'int' everywhere...
|
||||||
self.msg_scheme_from_type = {} # type: Dict[bytes, List[Sequence[str]]]
|
self.msg_scheme_from_type = {} # type: Dict[bytes, List[Sequence[str]]]
|
||||||
self.msg_type_from_name = {} # type: Dict[str, bytes]
|
self.msg_type_from_name = {} # type: Dict[str, bytes]
|
||||||
@@ -334,10 +334,7 @@ class LNSerializer:
|
|||||||
|
|
||||||
self.subtypes = {} # type: Dict[str, Dict[str, Sequence[str]]]
|
self.subtypes = {} # type: Dict[str, Dict[str, Sequence[str]]]
|
||||||
|
|
||||||
if for_onion_wire:
|
path = os.path.join(os.path.dirname(__file__), "lnwire", name + ".csv")
|
||||||
path = os.path.join(os.path.dirname(__file__), "lnwire", "onion_wire.csv")
|
|
||||||
else:
|
|
||||||
path = os.path.join(os.path.dirname(__file__), "lnwire", "peer_wire.csv")
|
|
||||||
with open(path, newline='') as f:
|
with open(path, newline='') as f:
|
||||||
csvreader = csv.reader(f)
|
csvreader = csv.reader(f)
|
||||||
for row in csvreader:
|
for row in csvreader:
|
||||||
@@ -345,7 +342,7 @@ class LNSerializer:
|
|||||||
if row[0] == "msgtype":
|
if row[0] == "msgtype":
|
||||||
# msgtype,<msgname>,<value>[,<option>]
|
# msgtype,<msgname>,<value>[,<option>]
|
||||||
msg_type_name = row[1]
|
msg_type_name = row[1]
|
||||||
if for_onion_wire:
|
if name == 'onion_wire':
|
||||||
msg_type_int = _parse_msgtype_intvalue_for_onion_wire(str(row[2]))
|
msg_type_int = _parse_msgtype_intvalue_for_onion_wire(str(row[2]))
|
||||||
else:
|
else:
|
||||||
msg_type_int = int(row[2])
|
msg_type_int = int(row[2])
|
||||||
@@ -668,4 +665,4 @@ encode_msg = _inst.encode_msg
|
|||||||
decode_msg = _inst.decode_msg
|
decode_msg = _inst.decode_msg
|
||||||
|
|
||||||
|
|
||||||
OnionWireSerializer = LNSerializer(for_onion_wire=True)
|
OnionWireSerializer = LNSerializer(name='onion_wire')
|
||||||
|
|||||||
Reference in New Issue
Block a user