pyln.proto.message: fix handling of missing optional fields.

If they don't exist, that's OK. These will eventually be going away
from the spec, but there are still some in gossip messages for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2020-06-12 13:24:56 +09:30 committed by Christian Decker
parent fd3ea91b44
commit aaefbe2e9e

View File

@ -591,6 +591,8 @@ Returns None on EOF
fields[f.name] = f.fieldtype.read(io_in, fields)
if fields[f.name] is None:
# optional fields are OK to be missing at end!
if f.option is not None:
break
raise ValueError('{}: truncated at field {}'
.format(mtype, f.name))
@ -641,6 +643,9 @@ Must not have missing fields.
if f.name in self.fields:
val = self.fields[f.name]
else:
# If this isn't present, and it's marked optional, don't write.
if f.option is not None:
return
val = None
f.fieldtype.write(io_out, val, self.fields)