From 2fa61899a341d667084d3d021ad0d5c68a7a2d50 Mon Sep 17 00:00:00 2001 From: Rene Pickhardt Date: Thu, 3 Jan 2019 20:23:02 +0100 Subject: [PATCH] pylightning: Made rpc a public member of Plugin and sorted imports After this code change people can use `plugin.rpc` from anywhere in their plugin code this is much nicer than going this way: ``` @plugin.method("init") def init(options, configuration, plugin): global rpc basedir = plugin.lightning_dir rpc_filename = plugin.rpc_filename path = os.path.join(basedir, rpc_filename) rpc = LightningRpc(path) ``` or similarly that way: ``` @plugin.method("init") def init(options, configuration, plugin): global rpc basedir = configuration['lightning-dir'] rpc_filename = configuration['rpc-file'] path = os.path.join(basedir, rpc_filename) rpc = LightningRpc(path) ``` Also the imports have been sorted alphabetically Co-authored-by: Rene Pickhardt Co-authored-by: Christian Decker --- contrib/pylightning/lightning/plugin.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/contrib/pylightning/lightning/plugin.py b/contrib/pylightning/lightning/plugin.py index 447bce508..44ec78840 100644 --- a/contrib/pylightning/lightning/plugin.py +++ b/contrib/pylightning/lightning/plugin.py @@ -1,10 +1,11 @@ from collections import OrderedDict +from lightning import LightningRpc -import sys -import os -import json import inspect +import json +import os import re +import sys import traceback @@ -35,6 +36,7 @@ class Plugin(object): self.add_method("getmanifest", self._getmanifest) self.rpc_filename = None self.lightning_dir = None + self.rpc = None self.init = None def add_method(self, name, func): @@ -283,6 +285,8 @@ class Plugin(object): def _init(self, options, configuration, request): self.rpc_filename = configuration['rpc-file'] self.lightning_dir = configuration['lightning-dir'] + path = os.path.join(self.lightning_dir, self.rpc_filename) + self.rpc = LightningRpc(path) for name, value in options.items(): self.options[name]['value'] = value