Browse Source

pyln.proto.message: allow fields with options to be missing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
nifty/pset-pre
Rusty Russell 5 years ago
committed by Christian Decker
parent
commit
acfeaebb62
  1. 6
      contrib/pyln-proto/pyln/proto/message/message.py

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

@ -142,7 +142,7 @@ class MessageTypeField(object):
def missing_fields(self, fields):
"""Return this field if it's not in fields"""
if self.name not in fields and not self.fieldtype.is_optional():
if self.name not in fields and not self.option and not self.fieldtype.is_optional():
return [self]
return []
@ -294,7 +294,9 @@ inherit from this too.
for field in self.fields:
val = field.fieldtype.read(io_in, otherfields)
if val is None:
raise ValueError("{}.{}: short read".format(self, field))
# Might only exist with certain options available
if field.fieldtype.option is None:
raise ValueError("{}.{}: short read".format(self, field))
vals[field.name] = val
return vals

Loading…
Cancel
Save