Skip to content

Commit

Permalink
pylightning: Made rpc a public member of Plugin and sorted imports
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Christian Decker <[email protected]>
  • Loading branch information
renepickhardt and cdecker committed Jan 12, 2019
1 parent 14db874 commit 6b5db38
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions contrib/pylightning/lightning/plugin.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -35,6 +36,7 @@ def __init__(self, stdout=None, stdin=None, autopatch=True):
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):
Expand Down Expand Up @@ -283,6 +285,8 @@ def _getmanifest(self):
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

Expand Down

0 comments on commit 6b5db38

Please sign in to comment.