Browse Source

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>
nifty/pset-pre
Rusty Russell 5 years ago
committed by Christian Decker
parent
commit
aaefbe2e9e
  1. 5
      contrib/pyln-proto/pyln/proto/message/message.py

5
contrib/pyln-proto/pyln/proto/message/message.py

@ -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)

Loading…
Cancel
Save