Browse Source

bolt-gen: add truncated uint support for TLV fields

TLV's have truncated values, add support for them. plus
some 'compilation' tests.
pull/2938/head
lisa neigut 6 years ago
committed by Rusty Russell
parent
commit
cedebfd2d9
  1. 12
      tools/generate-bolts.py
  2. 4
      tools/test/test_cases

12
tools/generate-bolts.py

@ -153,10 +153,12 @@ class Type(FieldSet):
'u16', 'u16',
'u32', 'u32',
'u64', 'u64',
'tu16',
'tu32',
'tu64',
'bool', 'bool',
'amount_sat', 'amount_sat',
'amount_msat', 'amount_msat',
# FIXME: omits var_int
] ]
typedefs = [ typedefs = [
@ -168,6 +170,12 @@ class Type(FieldSet):
'secp256k1_ecdsa_signature', 'secp256k1_ecdsa_signature',
] ]
truncated_typedefs = [
'tu16',
'tu32',
'tu64',
]
# Externally defined variable size types (require a context) # Externally defined variable size types (require a context)
varsize_types = [ varsize_types = [
'peer_features', 'peer_features',
@ -238,6 +246,8 @@ class Type(FieldSet):
def type_name(self): def type_name(self):
if self.name in self.typedefs: if self.name in self.typedefs:
return self.name return self.name
if self.name in self.truncated_typedefs:
return self.name[1:]
if self.is_enum: if self.is_enum:
prefix = 'enum ' prefix = 'enum '
else: else:

4
tools/test/test_cases

@ -96,6 +96,8 @@ subtypedata,test_features,globalfeatures,u8,len_gf
# TLV's! # TLV's!
tlvtype,n1,tlv1,1 tlvtype,n1,tlv1,1
# a truncated u64
tlvdata,n1,tlv1,amount_msat,tu64,
tlvtype,n1,tlv2,2 tlvtype,n1,tlv2,2
# neseted subtype # neseted subtype
tlvdata,n1,tlv2,scid,test_short_id, tlvdata,n1,tlv2,scid,test_short_id,
@ -106,7 +108,9 @@ tlvdata,n1,tlv3,amount_msat_2,u64,
tlvtype,n1,tlv4,254 tlvtype,n1,tlv4,254
tlvdata,n1,tlv4,cltv_delta,u16, tlvdata,n1,tlv4,cltv_delta,u16,
tlvtype,n2,tlv1,0 tlvtype,n2,tlv1,0
tlvdata,n2,tlv1,amount_msat,tu64,
tlvtype,n2,tlv2,11 tlvtype,n2,tlv2,11
tlvdata,n2,tlv2,cltv_expiry,tu32,
# TLV with all varsized and array structs # TLV with all varsized and array structs
tlvtype,n3,tlv3,1 tlvtype,n3,tlv3,1
tlvdata,n3,tlv3,subtype,test_short_id, tlvdata,n3,tlv3,subtype,test_short_id,

Loading…
Cancel
Save