From 241cd8d0124960d015ea89425d3f5e01faa5318c Mon Sep 17 00:00:00 2001 From: Jesse de Wit Date: Sat, 24 Dec 2022 11:32:58 +0100 Subject: [PATCH] generate composite fields in grpc --- cln-grpc/proto/node.proto | Bin 31305 -> 31712 bytes cln-grpc/src/convert.rs | Bin 67847 -> 73231 bytes cln-rpc/src/model.rs | Bin 131519 -> 132560 bytes contrib/msggen/msggen/gen/grpc.py | 37 ++++++++++++++++-- contrib/msggen/msggen/gen/rust.py | 11 +++++- contrib/pyln-testing/pyln/testing/node_pb2.py | Bin 125062 -> 125997 bytes 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/cln-grpc/proto/node.proto b/cln-grpc/proto/node.proto index 43ce50ba7fcc124843e9188b639a615fea3a1af9..0020e4ca3b91fd84685654b5de68bdace1383736 100644 GIT binary patch delta 310 zcmX^4h4I06#tm$IdiezUH;A*rO3J}X%7KnBMp80)dX_w6{^W&OqRb$>T{BpO0GYXKwEzGB delta 72 zcmV-O0Js0(_W{ZD0k8%RlfX$8vrGr<=JN`XsX~MUa*l!U!N-TwIs#j)2!eEN7RE2{8tx#<6-n2L#<=6E zzCu-bE4_(hgc-;mc@qAPB;9W!KSU4Fz%lZ?oD1r?s$>YOE35np=4MkNo1KO$*#+R& z67G+&7oxEuA*N&#po4sGQ-*=(_QBP`!M1uvNE*a^wZ>w50?Z~4cu=VYl@Qv8SEYZSD zQl&Nwj4TWpj#VK_+nK4balQZ-e~wOwW&D@r+fLIe5xi&^+cT_RIm&`gbn)`yleSx? zOo(Vm>gIo10L*4i>^9|)v8)bq8{#lzaHciqyt$$ESgZlI$ z@LzDLW(o{%N@#eC#dCk_f3pYX{!AxAH|Q!u*SY=dC|F#^^2IKf?Z(sRd*MtpIn>1n zkqcw)hvQ{_qM#@^1A!qpL9rcW+sAPL#$rAM|3sES;Et{LaqzkD6nuGW7#{Q-gx_x+ z24n6an43?!z4MPo)?bQ_G^6Hu|30Lq?sX#6@65R`FTArnx`e$|+8jT>AuSJ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sm9V}mvT80M}j delta 70 zcmV-M0J;CriwM7i2(aBulOGzbmuocv53}S=>t~lAe*r+VlD7OKvk}{-2D3Wi@CdV~ c>&H5mq%{E`x6vj6 for pb::{field.typename} {{ + impl From<{prefix}::{field.typename}> for pb::{pbname} {{ fn from(c: {prefix}::{field.typename}) -> Self {{ Self {{ """) @@ -321,6 +329,13 @@ class GrpcConverterGenerator(IGenerator): self.write(f"{name}: {rhs}, // Rule #2 for type {typ}\n", numindent=3) + elif isinstance(f, CompositeField): + rhs = "" + if f.required: + rhs = f'Some(c.{name}.into())' + else: + rhs = f'c.{name}.map(|v| v.into())' + self.write(f"{name}: {rhs},\n", numindent=3) self.write(f"""\ }} }} @@ -328,6 +343,12 @@ class GrpcConverterGenerator(IGenerator): """) + def to_camel_case(self, snake_str): + components = snake_str.split('_') + # We capitalize the first letter of each component except the first one + # with the 'title' method and join them together. + return components[0] + ''.join(x.title() for x in components[1:]) + def generate_requests(self, service): for meth in service.methods: req = meth.request @@ -380,12 +401,15 @@ class GrpcUnconverterGenerator(GrpcConverterGenerator): for f in field.fields: if isinstance(f, ArrayField): self.generate_array(prefix, f) + elif isinstance(f, CompositeField): + self.generate_composite(prefix, f) + pbname = self.to_camel_case(field.typename) # And now we can convert the current field: self.write(f"""\ #[allow(unused_variables)] - impl From for {prefix}::{field.typename} {{ - fn from(c: pb::{field.typename}) -> Self {{ + impl From for {prefix}::{field.typename} {{ + fn from(c: pb::{pbname}) -> Self {{ Self {{ """) @@ -446,6 +470,13 @@ class GrpcUnconverterGenerator(GrpcConverterGenerator): f'c.{name}' # default to just assignment ) self.write(f"{name}: {rhs}, // Rule #1 for type {typ}\n", numindent=3) + elif isinstance(f, CompositeField): + rhs = "" + if f.required: + rhs = f'c.{name}.unwrap().into()' + else: + rhs = f'c.{name}.map(|v| v.into())' + self.write(f"{name}: {rhs},\n", numindent=3) self.write(f"""\ }} diff --git a/contrib/msggen/msggen/gen/rust.py b/contrib/msggen/msggen/gen/rust.py index 017aad1c0..69d3f539d 100644 --- a/contrib/msggen/msggen/gen/rust.py +++ b/contrib/msggen/msggen/gen/rust.py @@ -201,7 +201,16 @@ def gen_composite(c) -> Tuple[str, str]: r += "".join([f[0] for f in fields]) r += "}\n\n" - return ("", r) + + defi = "" + if c.deprecated: + defi += " #[deprecated]\n" + if c.required: + defi += f" #[serde(alias = \"{c.name.name}\")]\n pub {c.name}: {c.typename},\n" + else: + defi += f" #[serde(alias = \"{c.name.name}\", skip_serializing_if = \"Option::is_none\")]\n pub {c.name}: Option<{c.typename}>,\n" + + return defi, r class RustGenerator(IGenerator): diff --git a/contrib/pyln-testing/pyln/testing/node_pb2.py b/contrib/pyln-testing/pyln/testing/node_pb2.py index 5579d16aaacf00f9d7e99e25584f6f335f6f0406..c529b9ebb19dfb083d70071a34298cae6a2737dc 100644 GIT binary patch delta 5568 zcmZu!d2m(L8K0AT-+K|Vy}Xw_ftQs4G2CgdxDAXuvn2v{@KDoi_$ zE23xgw2Gi(JDma{!Jr5MLIe~S6h#4X3AhyNs7&olJMC2L?>qOs$aMNgUVh(qzq5S% zckX>B)_W}0|6)$gVte4FoHZd>1jr!Ggka+r-X` zvH!A;v$wxsz={5ROx_|l-NQXPox76Pu~IQy^rsxl7c&|f#q^e3RwtfKREhcZG4cNI z%f-BVV`6E%LbS~<6nh?wh?O_Q#M6G67>wuRu%uYICn8S9Q{v8RlVbJtW5oF4I?+~G zAXYve71tEEh$}Bmip!smiM7SG;vdCT;#l!G5nV;HF%eIUV=Kg#mV`)|5phXky!cxp zA?`}tuJsrT1n;U6`N?WAkc^9|$vfCGCD~UH6$g_|E$JT1S0?n*J+6Cu_oAD-Z-Pob z{;U-A=gs(804X!A6q2n?EEc~Q%&v5g4>5z&pE#YID)yHoL}7VMw3oP|u(Vj=HNa`$ zViM3s~cnO#J;#zTwR%l3pbaRiPtMF zRxi#}&R`8LWtCmUXV^8fY0GWj``QqYoIVSWdnXI>YVg#5D%2x@~ni3vBWA%ptvp zn+>Ayz8Y~~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