Skip to content

Commit

Permalink
msggen: generate deprecated fields in rust.py
Browse files Browse the repository at this point in the history
  • Loading branch information
joemphilips authored and cdecker committed Sep 29, 2022
1 parent 22c8cfc commit 52be595
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 337 deletions.
2 changes: 2 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@
"Getinfo.fees_collected_msat": 13,
"Getinfo.id": 1,
"Getinfo.lightning-dir": 9,
"Getinfo.msatoshi_fees_collected": 18,
"Getinfo.network": 12,
"Getinfo.num_active_channels": 6,
"Getinfo.num_inactive_channels": 7,
Expand Down Expand Up @@ -485,6 +486,7 @@
"GetRoute.route[].delay": 5,
"GetRoute.route[].direction": 3,
"GetRoute.route[].id": 1,
"GetRoute.route[].msatoshi": 7,
"GetRoute.route[].style": 6
},
"InvoiceRequest": {
Expand Down
2 changes: 2 additions & 0 deletions cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions contrib/msggen/msggen/gen/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def gen_enum(e):
if e.description != "":
decl += f"/// {e.description}\n"

if e.deprecated:
decl += "#[deprecated]\n"
decl += f"#[derive(Copy, Clone, Debug, Deserialize, Serialize)]\npub enum {e.typename} {{\n"
for v in e.variants:
if v is None:
Expand Down Expand Up @@ -145,10 +147,12 @@ def gen_primitive(p):
typename = typemap.get(p.typename, p.typename)
normalize_varname(p)

if p.deprecated:
defi += " #[deprecated]\n"
if p.required:
defi = f" #[serde(alias = \"{org}\")]\n pub {p.name}: {typename},\n"
defi += f" #[serde(alias = \"{org}\")]\n pub {p.name}: {typename},\n"
else:
defi = f" #[serde(alias = \"{org}\", skip_serializing_if = \"Option::is_none\")]\n pub {p.name}: Option<{typename}>,\n"
defi += f" #[serde(alias = \"{org}\", skip_serializing_if = \"Option::is_none\")]\n pub {p.name}: Option<{typename}>,\n"

return defi, decl

Expand All @@ -173,10 +177,13 @@ def gen_array(a):

itemtype = typemap.get(itemtype, itemtype)
alias = a.name.normalized()
defi = ""
if a.deprecated:
defi += " #[deprecated]\n"
if a.required:
defi = f" #[serde(alias = \"{alias}\")]\n pub {name}: {'Vec<'*a.dims}{itemtype}{'>'*a.dims},\n"
defi += f" #[serde(alias = \"{alias}\")]\n pub {name}: {'Vec<'*a.dims}{itemtype}{'>'*a.dims},\n"
else:
defi = f" #[serde(alias = \"{alias}\", skip_serializing_if = \"crate::is_none_or_empty\")]\n pub {name}: Option<{'Vec<'*a.dims}{itemtype}{'>'*a.dims}>,\n"
defi += f" #[serde(alias = \"{alias}\", skip_serializing_if = \"crate::is_none_or_empty\")]\n pub {name}: Option<{'Vec<'*a.dims}{itemtype}{'>'*a.dims}>,\n"

return (defi, decl)

Expand Down
10 changes: 5 additions & 5 deletions contrib/msggen/msggen/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Field:
def __init__(self, path, description):
self.path = path
self.description = description
self.deprecated = False
self.required = False

@property
Expand Down Expand Up @@ -130,10 +131,6 @@ def from_js(cls, js, path):
desc = ftype["description"] if "description" in ftype else ""
fpath = f"{path}.{fname}"

if ftype.get("deprecated", False):
logger.warning(f"Unmanaged {fpath}, it is deprecated")
continue

if fpath in overrides:
field = copy(overrides[fpath])
field.path = fpath
Expand Down Expand Up @@ -170,6 +167,7 @@ def from_js(cls, js, path):
)

if field is not None:
field.deprecated = ftype.get("deprecated", False)
field.required = fname in required
fields.append(field)
logger.debug(field)
Expand Down Expand Up @@ -320,7 +318,9 @@ def from_js(cls, path, js):

elif child_js["type"] in PrimitiveField.types:
itemtype = PrimitiveField(
child_js["type"], path, child_js.get("description", "")
child_js["type"],
path,
child_js.get("description", ""),
)

logger.debug(f"Array path={path} dims={dims}, type={itemtype}")
Expand Down
2 changes: 2 additions & 0 deletions contrib/pyln-testing/pyln/testing/grpc2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def getinfo2py(m):
"lightning_dir": m.lightning_dir, # PrimitiveField in generate_composite
"blockheight": m.blockheight, # PrimitiveField in generate_composite
"network": m.network, # PrimitiveField in generate_composite
"msatoshi_fees_collected": m.msatoshi_fees_collected, # PrimitiveField in generate_composite
"fees_collected_msat": amount2msat(m.fees_collected_msat), # PrimitiveField in generate_composite
"address": [getinfo_address2py(i) for i in m.address], # ArrayField[composite] in generate_composite
"binding": [getinfo_binding2py(i) for i in m.binding], # ArrayField[composite] in generate_composite
Expand Down Expand Up @@ -787,6 +788,7 @@ def getroute_route2py(m):
"id": hexlify(m.id), # PrimitiveField in generate_composite
"channel": m.channel, # PrimitiveField in generate_composite
"direction": m.direction, # PrimitiveField in generate_composite
"msatoshi": m.msatoshi, # PrimitiveField in generate_composite
"amount_msat": amount2msat(m.amount_msat), # PrimitiveField in generate_composite
"delay": m.delay, # PrimitiveField in generate_composite
"style": str(m.style), # EnumField in generate_composite
Expand Down
656 changes: 328 additions & 328 deletions contrib/pyln-testing/pyln/testing/node_pb2.py

Large diffs are not rendered by default.

0 comments on commit 52be595

Please sign in to comment.