tools/gen: Enable Subtypes to have TLVStreams
This change will allow subtypes in wiregen files to have tlvstreams. Shifting tlv structs above subtypes in header_template is done to prevent forward declaration. Since generate-wire prepends 'tlv_' in tlvname, we have to modify fromwire_subtype_field and towire_subtype_field in impl_template to accommodate this. Changelog-Added: This PR would turn our peers into watchtower and enable SCB to create penalty txn.
This commit is contained in:
committed by
Alex Myers
parent
5b83eff5d9
commit
39f63eb27f
@@ -37,28 +37,6 @@ const char *${enum_set['name']}_name(int e);
|
||||
bool ${enum_set['name']}_is_defined(u16 type);
|
||||
% endfor
|
||||
|
||||
## Structs for subtypes + tlv messages
|
||||
% for struct in structs:
|
||||
struct ${struct.struct_name()} {
|
||||
% for f in struct.fields.values():
|
||||
% for c in f.field_comments:
|
||||
/* ${c} */
|
||||
% endfor
|
||||
% if bool(f.len_field_of):
|
||||
<% continue %>
|
||||
% endif
|
||||
% if f.is_varlen() and f.type_obj.is_varsize():
|
||||
${f.type_obj.type_name()} **${f.name};
|
||||
% elif f.is_varlen() or f.type_obj.is_varsize():
|
||||
${f.type_obj.type_name()} *${f.name};
|
||||
% elif f.is_array():
|
||||
${f.type_obj.type_name()} ${f.name}[${f.count}];
|
||||
% else:
|
||||
${f.type_obj.type_name()} ${f.name};
|
||||
% endif
|
||||
% endfor
|
||||
};
|
||||
% endfor
|
||||
## Structs for TLVs
|
||||
% for tlv in tlvs.values():
|
||||
struct ${tlv.struct_name()} {
|
||||
@@ -82,6 +60,29 @@ struct ${tlv.struct_name()} {
|
||||
};
|
||||
% endfor
|
||||
|
||||
## Structs for subtypes + tlv messages
|
||||
% for struct in structs:
|
||||
struct ${struct.struct_name()} {
|
||||
% for f in struct.fields.values():
|
||||
% for c in f.field_comments:
|
||||
/* ${c} */
|
||||
% endfor
|
||||
% if bool(f.len_field_of):
|
||||
<% continue %>
|
||||
% endif
|
||||
% if f.is_varlen() and f.type_obj.is_varsize():
|
||||
${f.type_obj.type_name()} **${f.name};
|
||||
% elif f.is_varlen() or f.type_obj.is_varsize():
|
||||
${f.type_obj.type_name()} *${f.name};
|
||||
% elif f.is_array():
|
||||
${f.type_obj.type_name()} ${f.name}[${f.count}];
|
||||
% else:
|
||||
${f.type_obj.type_name()} ${f.name};
|
||||
% endif
|
||||
% endfor
|
||||
};
|
||||
% endfor
|
||||
|
||||
% for tlv in tlvs.values():
|
||||
struct ${tlv.struct_name()} *${tlv.struct_name()}_new(const tal_t *ctx);
|
||||
|
||||
|
||||
@@ -66,6 +66,8 @@ towire_${type_obj.name}_array(${ptr}, ${fieldname}, ${f.size('tal_count(' + fiel
|
||||
towire_${type_obj.name}(${ptr}, ${f.name});
|
||||
% elif is_single_ptr:
|
||||
towire_${type_obj.name}(${ptr}, ${'*' if type_obj.is_assignable() else ''}${fieldname});
|
||||
%elif f.type_obj.is_tlv():
|
||||
towire_tlv_${type_obj.name}(${ptr}, ${'' if type_obj.is_assignable() or type_obj.is_varsize() else '&'}${fieldname});
|
||||
% else:
|
||||
towire_${type_obj.name}(${ptr}, ${'' if type_obj.is_assignable() or type_obj.is_varsize() else '&'}${fieldname});
|
||||
% endif
|
||||
@@ -74,6 +76,8 @@ towire_${type_obj.name}(${ptr}, ${'' if type_obj.is_assignable() or type_obj.is_
|
||||
<%def name="fromwire_subtype_field(fieldname, f, ctx, is_ptr)">\
|
||||
<%
|
||||
type_ = f.type_obj.name
|
||||
if f.type_obj.is_tlv():
|
||||
type_ = 'tlv_' + type_
|
||||
typename = f.type_obj.type_name()
|
||||
if f.type_obj.is_varsize():
|
||||
typename += ' *'
|
||||
|
||||
@@ -590,6 +590,9 @@ def main(options, args=None, output=sys.stdout, lines=None):
|
||||
else:
|
||||
count = tokens[4]
|
||||
|
||||
if tokens[3] in master.tlvs:
|
||||
type_obj.tlv = master.tlvs[tokens[3]]
|
||||
|
||||
subtype.add_data_field(tokens[2], type_obj, count, comments=list(comment_set),
|
||||
optional=optional)
|
||||
comment_set = []
|
||||
|
||||
Reference in New Issue
Block a user