pyln.proto: fix handling of subtypes in TLVs.

This was revealed by using lnprototest on channel_types.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-06-24 15:00:52 +09:30
parent eaa2ff23f1
commit ca3680246e

View File

@ -305,8 +305,8 @@ other types. Since 'msgtype' is almost identical, it inherits from this too.
raise ValueError("Missing field {} {}".format(f.name, otherfields)) raise ValueError("Missing field {} {}".format(f.name, otherfields))
val = None val = None
if self.name in otherfields: if type(f.fieldtype) is SubtypeType:
otherfields = otherfields[self.name] otherfields = otherfields[f.name]
f.fieldtype.write(io_out, val, otherfields) f.fieldtype.write(io_out, val, otherfields)
def read(self, io_in: BufferedIOBase, otherfields: Dict[str, Any]) -> Optional[Dict[str, Any]]: def read(self, io_in: BufferedIOBase, otherfields: Dict[str, Any]) -> Optional[Dict[str, Any]]:
@ -554,7 +554,7 @@ tlvdata,reply_channel_range_tlvs,timestamps_tlv,encoding_type,u8,
for typenum, writefunc, val in ordered: for typenum, writefunc, val in ordered:
buf = BytesIO() buf = BytesIO()
writefunc(cast(BufferedIOBase, buf), val, otherfields) writefunc(cast(BufferedIOBase, buf), val, val)
BigSizeType.write(io_out, typenum) BigSizeType.write(io_out, typenum)
BigSizeType.write(io_out, len(buf.getvalue())) BigSizeType.write(io_out, len(buf.getvalue()))
io_out.write(buf.getvalue()) io_out.write(buf.getvalue())