diff --git a/contrib/pylightning/lightning/plugin.py b/contrib/pylightning/lightning/plugin.py index 4440f3185..402f3cccf 100644 --- a/contrib/pylightning/lightning/plugin.py +++ b/contrib/pylightning/lightning/plugin.py @@ -30,10 +30,11 @@ class Method(object): - RPC exposed by RPC passthrough - HOOK registered to be called synchronously by lightningd """ - def __init__(self, name, func, mtype=MethodType.RPCMETHOD): + def __init__(self, name, func, mtype=MethodType.RPCMETHOD, category=None): self.name = name self.func = func self.mtype = mtype + self.category = category self.background = False @@ -118,7 +119,7 @@ class Plugin(object): self.write_lock = RLock() - def add_method(self, name, func, background=False): + def add_method(self, name, func, background=False, category=None): """Add a plugin method to the dispatch table. The function will be expected at call time (see `_dispatch`) @@ -145,6 +146,9 @@ class Plugin(object): `request.set_result` or `result.set_exception` to return a result or raise an exception for the call. + The `category` argument can be used to specify the category of the + newly created rpc command. + """ if name in self.methods: raise ValueError( @@ -152,7 +156,7 @@ class Plugin(object): ) # Register the function with the name - method = Method(name, func, MethodType.RPCMETHOD) + method = Method(name, func, MethodType.RPCMETHOD, category) method.background = background self.methods[name] = method @@ -211,23 +215,23 @@ class Plugin(object): else: return self.options[name]['default'] - def async_method(self, method_name): + def async_method(self, method_name, category=None): """Decorator to add an async plugin method to the dispatch table. Internally uses add_method. """ def decorator(f): - self.add_method(method_name, f, background=True) + self.add_method(method_name, f, background=True, category=category) return f return decorator - def method(self, method_name): + def method(self, method_name, category=None): """Decorator to add a plugin method to the dispatch table. Internally uses add_method. """ def decorator(f): - self.add_method(method_name, f, background=False) + self.add_method(method_name, f, background=False, category=category) return f return decorator @@ -473,6 +477,7 @@ class Plugin(object): methods.append({ 'name': method.name, + 'category': method.category if method.category else "plugin", 'usage': " ".join(args), 'description': doc })