msggen: Add RoutehintList as a primitive

This commit is contained in:
Christian Decker
2022-04-01 14:43:34 +10:30
committed by Rusty Russell
parent ec5cd92580
commit ef145c7900
6 changed files with 65 additions and 4 deletions

View File

@@ -377,7 +377,7 @@ class GrpcUnconverterGenerator(GrpcConverterGenerator):
if isinstance(f, ArrayField):
typ = f.itemtype.typename
mapping = {
'hex': f'hex::decode(s).unwrap()',
'hex': f'hex::encode(s)',
'u32': f's.clone()',
}.get(typ, f's.into()')
self.write(f"{name}: c.{name}.iter().map(|s| {mapping}).collect(),\n", numindent=3)
@@ -410,6 +410,7 @@ class GrpcUnconverterGenerator(GrpcConverterGenerator):
'msat|any?': f'c.{name}.as_ref().map(|a| a.into())',
'feerate': f'c.{name}.as_ref().unwrap().into()',
'feerate?': f'c.{name}.as_ref().map(|a| a.into())',
'RoutehintList?': f'c.{name}.clone().map(|rl| rl.into())',
}.get(
typ,
f'c.{name}.clone()' # default to just assignment

View File

@@ -340,6 +340,7 @@ InvoiceLabelField = PrimitiveField("string", None, None)
DatastoreKeyField = ArrayField(itemtype=PrimitiveField("string", None, None), dims=1, path=None, description=None)
InvoiceExposeprivatechannelsField = PrimitiveField("boolean", None, None)
PayExclude = ArrayField(itemtype=PrimitiveField("string", None, None), dims=1, path=None, description=None)
RoutehintListField = PrimitiveField("RoutehintList", None, None)
# Override fields with manually managed types, fieldpath -> field mapping
overrides = {
'Invoice.label': InvoiceLabelField,
@@ -350,6 +351,7 @@ overrides = {
'ListDatastore.key': DatastoreKeyField,
'Invoice.exposeprivatechannels': InvoiceExposeprivatechannelsField,
'Pay.exclude': PayExclude,
'KeySend.routehints': RoutehintListField,
}

View File

@@ -165,7 +165,7 @@ def gen_array(a):
return ("", "") # Override said not to include
itemtype = typemap.get(itemtype, itemtype)
alias = a.name.normalized()[:-2] # Strip the `[]` suffix for arrays.
alias = a.name.normalized()
defi = f" #[serde(alias = \"{alias}\")]\n pub {name}: {'Vec<'*a.dims}{itemtype}{'>'*a.dims},\n"
return (defi, decl)