Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions cln-grpc/src/convert.rs

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

4 changes: 4 additions & 0 deletions contrib/msggen/msggen/gen/grpc/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def generate_composite(self, prefix, field: CompositeField, override=None):
"u16?": f"c.{name}.map(|v| v.into())",
"msat": f"Some(c.{name}.into())",
"msat?": f"c.{name}.map(|f| f.into())",
"sat": f"Some(c.{name}.into())",
"sat?": f"c.{name}.map(|f| f.into())",
"pubkey": f"c.{name}.serialize().to_vec()",
"pubkey?": f"c.{name}.map(|v| v.serialize().to_vec())",
"hex": f"hex::decode(&c.{name}).unwrap()",
Expand All @@ -115,6 +117,8 @@ def generate_composite(self, prefix, field: CompositeField, override=None):
"msat_or_any": f"Some(c.{name}.into())",
"msat_or_all": f"Some(c.{name}.into())",
"msat_or_all?": f"c.{name}.map(|o|o.into())",
"sat_or_all": f"Some(c.{name}.into())",
"sat_or_all?": f"c.{name}.map(|o|o.into())",
"feerate?": f"c.{name}.map(|o|o.into())",
"feerate": f"Some(c.{name}.into())",
"outpoint?": f"c.{name}.map(|o|o.into())",
Expand Down
4 changes: 4 additions & 0 deletions contrib/msggen/msggen/gen/grpc/unconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def generate_composite(self, prefix, field: CompositeField, override=None) -> No
"msat_or_all?": f"c.{name}.map(|a| a.into())",
"msat_or_any": f"c.{name}.unwrap().into()",
"msat_or_any?": f"c.{name}.map(|a| a.into())",
"sat": f"c.{name}.unwrap().into()",
"sat?": f"c.{name}.map(|a| a.into())",
"sat_or_all": f"c.{name}.unwrap().into()",
"sat_or_all?": f"c.{name}.map(|a| a.into())",
"feerate": f"c.{name}.unwrap().into()",
"feerate?": f"c.{name}.map(|a| a.into())",
"outpoint?": f"c.{name}.map(|a| a.into())",
Expand Down
2 changes: 2 additions & 0 deletions contrib/msggen/msggen/gen/grpc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"msat": "Amount",
"msat_or_all": "AmountOrAll",
"msat_or_any": "AmountOrAny",
"sat": "Amount",
"sat_or_all": "AmountOrAll",
"currency": "string",
"number": "double",
"pubkey": "bytes",
Expand Down
5 changes: 5 additions & 0 deletions contrib/msggen/msggen/gen/grpc2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(self, dest: TextIO):
"boolean": "m.{name}",
"short_channel_id": "m.{name}",
"msat": "amount2msat(m.{name})",
"sat": "amount2sat(m.{name})",
"currency": "m.{name}",
"number": "m.{name}",
}
Expand Down Expand Up @@ -87,6 +88,10 @@ def amount2msat(a):
return a.msat


def amount2sat(a):
return a.msat / 1000

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return a.msat / 1000
return a.msat // 1000

Do we want integer division here? Any remainder after division should indicate a problem, but if we're only using it to directly convert types it shouldn't theoretically be an issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed an Amount already is a correctly parsed value and this should be fine, otherwise we should raise an error here, no?



def remove_default(d):
# grpc is really not good at empty values, they get replaced with the type's default value...
return {k: v for k, v in d.items() if v is not None and v != ""}
Expand Down
2 changes: 2 additions & 0 deletions contrib/msggen/msggen/gen/rpc/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"msat": "Amount",
"msat_or_all": "AmountOrAll",
"msat_or_any": "AmountOrAny",
"sat": "Amount",
"sat_or_all": "AmountOrAll",
"currency": "String",
"number": "f64",
"pubkey": "PublicKey",
Expand Down
2 changes: 2 additions & 0 deletions contrib/msggen/msggen/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ class PrimitiveField(Field):
"msat",
"msat_or_any",
"msat_or_all",
"sat",
"sat_or_all",
"currency",
"hex",
"short_channel_id",
Expand Down
Loading