Browse Source

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>
pr-2218
Rene Pickhardt 6 years ago
committed by Christian Decker
parent
commit
2fa61899a3
No known key found for this signature in database GPG Key ID: 1416D83DC4F0E86D
  1. 10
      contrib/pylightning/lightning/plugin.py

10
contrib/pylightning/lightning/plugin.py

@ -1,10 +1,11 @@
from collections import OrderedDict from collections import OrderedDict
from lightning import LightningRpc
import sys
import os
import json
import inspect import inspect
import json
import os
import re import re
import sys
import traceback import traceback
@ -35,6 +36,7 @@ class Plugin(object):
self.add_method("getmanifest", self._getmanifest) self.add_method("getmanifest", self._getmanifest)
self.rpc_filename = None self.rpc_filename = None
self.lightning_dir = None self.lightning_dir = None
self.rpc = None
self.init = None self.init = None
def add_method(self, name, func): def add_method(self, name, func):
@ -283,6 +285,8 @@ class Plugin(object):
def _init(self, options, configuration, request): def _init(self, options, configuration, request):
self.rpc_filename = configuration['rpc-file'] self.rpc_filename = configuration['rpc-file']
self.lightning_dir = configuration['lightning-dir'] 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(): for name, value in options.items():
self.options[name]['value'] = value self.options[name]['value'] = value

Loading…
Cancel
Save