Skip to content

Commit

Permalink
msggen: add missing-grpc command
Browse files Browse the repository at this point in the history
  • Loading branch information
jackstar12 committed Apr 11, 2024
1 parent 7d8c723 commit 3b64d42
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 90 deletions.
7 changes: 7 additions & 0 deletions contrib/msggen/msggen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import logging
from msggen.patch import VersionAnnotationPatch, OptionalPatch, OverridePatch
from msggen.checks import VersioningCheck
from msggen.utils.utils import check_missing


logging.basicConfig(
Expand Down Expand Up @@ -96,6 +97,7 @@ def main():
bundle.add_argument('schema_dir', action='store')

subcmds.add_parser("generate", help="generate all files")
subcmds.add_parser("missing-grpc", help="print all rpc commands missing from grpc")
args = parser.parse_args()

if args.command == 'generate':
Expand All @@ -107,6 +109,11 @@ def main():
print(f"Combining schemas from {src.resolve()} into {dest.resolve()}")
schema = combine_schemas(src, dest)
print(f"Created {dest} from {len(schema)} files")
elif args.command == 'missing-grpc':
print("Missing RPC commands in grpc:")
missing = check_missing()
for name in missing:
print(name)


if __name__ == "__main__":
Expand Down
191 changes: 101 additions & 90 deletions contrib/msggen/msggen/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,96 @@
import functools
from collections import OrderedDict

grpc_method_names = [
"Getinfo",
"ListPeers",
"ListFunds",
"SendPay",
"ListChannels",
"AddGossip",
"AutoCleanInvoice",
"CheckMessage",
"Close",
"Connect",
"CreateInvoice",
"Datastore",
"DatastoreUsage",
"CreateOnion",
"DelDatastore",
"DelInvoice",
"Invoice",
"ListDatastore",
"ListInvoices",
"SendOnion",
"ListSendPays",
"ListTransactions",
"Pay",
"ListNodes",
"WaitAnyInvoice",
"WaitInvoice",
"WaitSendPay",
"NewAddr",
"Withdraw",
"KeySend",
"FundPsbt",
"SendPsbt",
"SignPsbt",
"UtxoPsbt",
"TxDiscard",
"TxPrepare",
"TxSend",
"ListPeerChannels",
"ListClosedChannels",
"DecodePay",
"Decode",
# "delpay",
# "disableoffer",
"Disconnect",
"Feerates",
"FetchInvoice",
# "fundchannel_cancel",
# "fundchannel_complete",
"FundChannel",
# "fundchannel_start",
# "funderupdate",
# "getlog",
"GetRoute",
"ListForwards",
"ListOffers",
"ListPays",
"ListHtlcs",
# "multifundchannel",
# "multiwithdraw",
"Offer",
# "openchannel_abort",
# "openchannel_bump",
# "openchannel_init",
# "openchannel_signed",
# "openchannel_update",
# "parsefeerate",
"Ping",
# "plugin",
# "reserveinputs",
"SendCustomMsg",
# "sendinvoice",
# "sendonionmessage",
"SetChannel",
"SignInvoice",
"SignMessage",
# "unreserveinputs",
"WaitBlockHeight",
"Wait",
# "ListConfigs",
# "check", # No point in mapping this one
"Stop",
# "notifications", # No point in mapping this
# "help",
"PreApproveKeysend",
"PreApproveInvoice",
"StaticBackup",
"Bkpr-ListIncome",
]


def combine_schemas(schema_dir: Path, dest: Path):
"""Enumerate all schema files, and combine it into a single JSON file."""
Expand Down Expand Up @@ -35,6 +125,16 @@ def get_schema_bundle():
p = resources.open_text("msggen", "schema.json")
return json.load(p)

def check_missing():
"""Check for missing gRPC commands in the schema.
"""
schema = get_schema_bundle()
command_names = set(
full_name.replace("lightning-", "").replace(".json", "") for full_name in schema.keys()
)
lower_method_names = set(name.lower() for name in grpc_method_names)
return command_names - lower_method_names


def load_jsonrpc_method(name):
"""Load a method based on the file naming conventions for the JSON-RPC.
Expand All @@ -57,96 +157,7 @@ def load_jsonrpc_method(name):


def load_jsonrpc_service():
method_names = [
"Getinfo",
"ListPeers",
"ListFunds",
"SendPay",
"ListChannels",
"AddGossip",
"AutoCleanInvoice",
"CheckMessage",
"Close",
"Connect",
"CreateInvoice",
"Datastore",
"DatastoreUsage",
"CreateOnion",
"DelDatastore",
"DelInvoice",
"Invoice",
"ListDatastore",
"ListInvoices",
"SendOnion",
"ListSendPays",
"ListTransactions",
"Pay",
"ListNodes",
"WaitAnyInvoice",
"WaitInvoice",
"WaitSendPay",
"NewAddr",
"Withdraw",
"KeySend",
"FundPsbt",
"SendPsbt",
"SignPsbt",
"UtxoPsbt",
"TxDiscard",
"TxPrepare",
"TxSend",
"ListPeerChannels",
"ListClosedChannels",
"DecodePay",
"Decode",
# "delpay",
# "disableoffer",
"Disconnect",
"Feerates",
"FetchInvoice",
# "fundchannel_cancel",
# "fundchannel_complete",
"FundChannel",
# "fundchannel_start",
# "funderupdate",
# "getlog",
"GetRoute",
"ListForwards",
"ListOffers",
"ListPays",
"ListHtlcs",
# "multifundchannel",
# "multiwithdraw",
"Offer",
# "openchannel_abort",
# "openchannel_bump",
# "openchannel_init",
# "openchannel_signed",
# "openchannel_update",
# "parsefeerate",
"Ping",
# "plugin",
# "reserveinputs",
"SendCustomMsg",
# "sendinvoice",
# "sendonionmessage",
"SetChannel",
"SignInvoice",
"SignMessage",
# "unreserveinputs",
"WaitBlockHeight",
"Wait",
# "ListConfigs",
# "check", # No point in mapping this one
"Stop",
# "notifications", # No point in mapping this
# "help",
"PreApproveKeysend",
"PreApproveInvoice",
"StaticBackup",
"Bkpr-ListIncome",
]
methods = [load_jsonrpc_method(name) for name in method_names]
methods = [load_jsonrpc_method(name) for name in grpc_method_names]
service = Service(name="Node", methods=methods)
service.includes = ['primitives.proto'] # Make sure we have the primitives included.
return service

0 comments on commit 3b64d42

Please sign in to comment.