mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
message: support option fields.
These are (probably) going away soon, but just tag them for now. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
9992a577b4
commit
e4b5679f5d
@ -109,10 +109,11 @@ domain, such as within a given BOLT"""
|
|||||||
|
|
||||||
class MessageTypeField(object):
|
class MessageTypeField(object):
|
||||||
"""A field within a particular message type or subtype"""
|
"""A field within a particular message type or subtype"""
|
||||||
def __init__(self, ownername, name, fieldtype):
|
def __init__(self, ownername, name, fieldtype, option=None):
|
||||||
self.full_name = "{}.{}".format(ownername, name)
|
self.full_name = "{}.{}".format(ownername, name)
|
||||||
self.name = name
|
self.name = name
|
||||||
self.fieldtype = fieldtype
|
self.fieldtype = fieldtype
|
||||||
|
self.option = option
|
||||||
|
|
||||||
def missing_fields(self, fields):
|
def missing_fields(self, fields):
|
||||||
"""Return this field if it's not in fields"""
|
"""Return this field if it's not in fields"""
|
||||||
@ -171,7 +172,7 @@ inherit from this too.
|
|||||||
.format(parts))
|
.format(parts))
|
||||||
return SubtypeType(parts[0])
|
return SubtypeType(parts[0])
|
||||||
|
|
||||||
def _field_from_csv(self, namespace, parts, ellipsisok=False):
|
def _field_from_csv(self, namespace, parts, ellipsisok=False, option=None):
|
||||||
"""Takes msgdata/subtypedata after first two fields
|
"""Takes msgdata/subtypedata after first two fields
|
||||||
e.g. [...]timestamp_node_id_1,u32,
|
e.g. [...]timestamp_node_id_1,u32,
|
||||||
|
|
||||||
@ -191,19 +192,22 @@ inherit from this too.
|
|||||||
DynamicArrayType(self,
|
DynamicArrayType(self,
|
||||||
parts[0],
|
parts[0],
|
||||||
basetype,
|
basetype,
|
||||||
lenfield))
|
lenfield),
|
||||||
|
option)
|
||||||
lenfield.fieldtype.add_length_for(field)
|
lenfield.fieldtype.add_length_for(field)
|
||||||
elif ellipsisok and parts[2] == '...':
|
elif ellipsisok and parts[2] == '...':
|
||||||
field = MessageTypeField(self.name, parts[0],
|
field = MessageTypeField(self.name, parts[0],
|
||||||
EllipsisArrayType(self,
|
EllipsisArrayType(self,
|
||||||
parts[0], basetype))
|
parts[0], basetype),
|
||||||
|
option)
|
||||||
else:
|
else:
|
||||||
field = MessageTypeField(self.name, parts[0],
|
field = MessageTypeField(self.name, parts[0],
|
||||||
SizedArrayType(self,
|
SizedArrayType(self,
|
||||||
parts[0], basetype,
|
parts[0], basetype,
|
||||||
int(parts[2])))
|
int(parts[2])),
|
||||||
|
option)
|
||||||
else:
|
else:
|
||||||
field = MessageTypeField(self.name, parts[0], basetype)
|
field = MessageTypeField(self.name, parts[0], basetype, option)
|
||||||
|
|
||||||
return field
|
return field
|
||||||
|
|
||||||
@ -299,9 +303,10 @@ class MessageType(SubtypeType):
|
|||||||
'NODE': 0x2000,
|
'NODE': 0x2000,
|
||||||
'UPDATE': 0x1000}
|
'UPDATE': 0x1000}
|
||||||
|
|
||||||
def __init__(self, name, value):
|
def __init__(self, name, value, option=None):
|
||||||
super().__init__(name)
|
super().__init__(name)
|
||||||
self.number = self.parse_value(value)
|
self.number = self.parse_value(value)
|
||||||
|
self.option = option
|
||||||
|
|
||||||
def parse_value(self, value):
|
def parse_value(self, value):
|
||||||
result = 0
|
result = 0
|
||||||
@ -318,23 +323,30 @@ class MessageType(SubtypeType):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def type_from_csv(parts):
|
def type_from_csv(parts):
|
||||||
"""e.g msgtype,open_channel,32"""
|
"""e.g msgtype,open_channel,32,option_foo"""
|
||||||
if len(parts) != 2:
|
option = None
|
||||||
|
if len(parts) == 3:
|
||||||
|
option = parts[2]
|
||||||
|
elif len(parts) < 2 or len(parts) > 3:
|
||||||
raise ValueError("msgtype expected 3 CSV parts, not {}"
|
raise ValueError("msgtype expected 3 CSV parts, not {}"
|
||||||
.format(parts))
|
.format(parts))
|
||||||
return MessageType(parts[0], parts[1])
|
return MessageType(parts[0], parts[1], option)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def field_from_csv(namespace, parts):
|
def field_from_csv(namespace, parts):
|
||||||
"""e.g msgdata,open_channel,temporary_channel_id,byte,32"""
|
"""e.g msgdata,open_channel,temporary_channel_id,byte,32[,opt]"""
|
||||||
if len(parts) != 4:
|
option = None
|
||||||
|
if len(parts) == 5:
|
||||||
|
option = parts[4]
|
||||||
|
elif len(parts) != 4:
|
||||||
raise ValueError("msgdata expected 4 CSV parts, not {}"
|
raise ValueError("msgdata expected 4 CSV parts, not {}"
|
||||||
.format(parts))
|
.format(parts))
|
||||||
messagetype = namespace.get_msgtype(parts[0])
|
messagetype = namespace.get_msgtype(parts[0])
|
||||||
if not messagetype:
|
if not messagetype:
|
||||||
raise ValueError("unknown subtype {}".format(parts[0]))
|
raise ValueError("unknown subtype {}".format(parts[0]))
|
||||||
|
|
||||||
field = messagetype._field_from_csv(namespace, parts[1:])
|
field = messagetype._field_from_csv(namespace, parts[1:4],
|
||||||
|
option=option)
|
||||||
messagetype.add_field(field)
|
messagetype.add_field(field)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user