mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
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 <rene@rene-pickhardt.de> Co-authored-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
14db874395
commit
6b5db38774
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user