Compare commits
8 Commits
btcpaymast
...
plugin-2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c349654ff6 | ||
|
|
a6a699b4c5 | ||
|
|
a8026ff599 | ||
|
|
3d36f4e63d | ||
|
|
8d020933d9 | ||
|
|
50b6e21ce2 | ||
|
|
2282a306f4 | ||
|
|
6e3ced1531 |
@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
- JSON API: `getinfo` now returns `num_peers` `num_pending_channels`,
|
||||
`num_active_channels` and `num_inactive_channels` fields.
|
||||
- JSON API: use `\n\n` to terminate responses, for simplified parsing (pylightning now relies on this)
|
||||
- Plugins: Added plugins to `lightningd` and implemented the option passthrough.
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
4
Makefile
4
Makefile
@ -38,7 +38,9 @@ ifeq ($(COMPAT),1)
|
||||
COMPAT_CFLAGS=-DCOMPAT_V052=1 -DCOMPAT_V060=1 -DCOMPAT_V061=1
|
||||
endif
|
||||
|
||||
PYTEST_OPTS := -v
|
||||
# Timeout shortly before the 600 second travis silence timeout
|
||||
# (method=thread to support xdist)
|
||||
PYTEST_OPTS := -v --timeout=550 --timeout_method=thread
|
||||
|
||||
# This is where we add new features as bitcoin adds them.
|
||||
FEATURES :=
|
||||
|
||||
@ -51,4 +51,19 @@ RUN cd /tmp/ && \
|
||||
rm -rf bitcoin.tar.gz /tmp/bitcoin-$BITCOIN_VERSION
|
||||
|
||||
RUN pip3 install --upgrade pip && \
|
||||
python3 -m pip install python-bitcoinlib==0.7.0 pytest==3.0.5 setuptools==36.6.0 pytest-test-groups==1.0.3 flake8==3.5.0 pytest-rerunfailures==3.1 ephemeral-port-reserve==1.1.0 pytest-xdist==1.22.2 flaky==3.4.0 CherryPy==17.3.0 Flask==1.0.2
|
||||
python3 -m pip install \
|
||||
CherryPy==17.3.0 \
|
||||
Flask==1.0.2 \
|
||||
cheroot==6.5.2 \
|
||||
ephemeral-port-reserve==1.1.0 \
|
||||
flaky==3.4.0 \
|
||||
pytest-benchmark==3.1.1 \
|
||||
pytest-forked==0.2 \
|
||||
pytest-timeout==1.3.3 \
|
||||
pytest-xdist==1.22.2 \
|
||||
pytest==3.8.1 \
|
||||
python-bitcoinlib==0.7.0 \
|
||||
tqdm==4.26.0 \
|
||||
pytest-test-groups==1.0.3 \
|
||||
flake8==3.5.0 \
|
||||
pytest-rerunfailures==3.1
|
||||
@ -51,4 +51,19 @@ RUN cd /tmp/ && \
|
||||
rm -rf bitcoin.tar.gz /tmp/bitcoin-$BITCOIN_VERSION
|
||||
|
||||
RUN pip3 install --upgrade pip && \
|
||||
python3 -m pip install python-bitcoinlib==0.7.0 pytest==3.0.5 setuptools==36.6.0 pytest-test-groups==1.0.3 flake8==3.5.0 pytest-rerunfailures==3.1 ephemeral-port-reserve==1.1.0 pytest-xdist==1.22.2 flaky==3.4.0 CherryPy==17.3.0 Flask==1.0.2
|
||||
python3 -m pip install \
|
||||
CherryPy==17.3.0 \
|
||||
Flask==1.0.2 \
|
||||
cheroot==6.5.2 \
|
||||
ephemeral-port-reserve==1.1.0 \
|
||||
flaky==3.4.0 \
|
||||
pytest-benchmark==3.1.1 \
|
||||
pytest-forked==0.2 \
|
||||
pytest-timeout==1.3.3 \
|
||||
pytest-xdist==1.22.2 \
|
||||
pytest==3.8.1 \
|
||||
python-bitcoinlib==0.7.0 \
|
||||
tqdm==4.26.0 \
|
||||
pytest-test-groups==1.0.3 \
|
||||
flake8==3.5.0 \
|
||||
pytest-rerunfailures==3.1
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
"""Simple plugin to show how to build new plugins for c-lightning
|
||||
|
||||
It demonstrates how a plugin communicates with c-lightning, how it registers
|
||||
@ -19,7 +19,7 @@ def json_hello(request):
|
||||
return greeting
|
||||
|
||||
|
||||
def json_init(request):
|
||||
def json_getmanifest(request):
|
||||
global greeting
|
||||
return {
|
||||
"options": [
|
||||
@ -37,7 +37,7 @@ def json_init(request):
|
||||
}
|
||||
|
||||
|
||||
def json_configure(request):
|
||||
def json_init(request):
|
||||
"""The main daemon is telling us the relevant cli options
|
||||
"""
|
||||
global greeting
|
||||
@ -46,15 +46,10 @@ def json_configure(request):
|
||||
return "ok"
|
||||
|
||||
|
||||
def json_ping(request):
|
||||
return "pong"
|
||||
|
||||
|
||||
methods = {
|
||||
'hello': json_hello,
|
||||
'getmanifest': json_getmanifest,
|
||||
'init': json_init,
|
||||
'ping': json_ping,
|
||||
'configure': json_configure,
|
||||
}
|
||||
|
||||
partial = ""
|
||||
@ -68,7 +68,7 @@ this example:
|
||||
{
|
||||
"name": "gettime",
|
||||
"description": "Returns the current time in {timezone}",
|
||||
"params": ["timezone"]
|
||||
"long_description": "Returns the current time in the timezone that is given as the only parameter.\nThis description may be quite long and is allowed to span multiple lines."
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include <ccan/opt/opt.h>
|
||||
#include <ccan/pipecmd/pipecmd.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <errno.h>
|
||||
#include <lightningd/json.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -408,6 +409,10 @@ void plugins_init(struct plugins *plugins)
|
||||
cmd[1] = NULL;
|
||||
p->pid = pipecmdarr(&stdout, &stdin, NULL, cmd);
|
||||
|
||||
if (p->pid == -1)
|
||||
fatal("error starting plugin '%s': %s", p->cmd,
|
||||
strerror(errno));
|
||||
|
||||
list_head_init(&p->output);
|
||||
p->buffer = tal_arr(p, char, 64);
|
||||
p->used = 0;
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
pytest==3.8.1
|
||||
CherryPy==17.3.0
|
||||
Flask==1.0.2
|
||||
cheroot==6.5.2
|
||||
@ -8,3 +9,4 @@ pytest-forked==0.2
|
||||
pytest-xdist==1.22.2
|
||||
python-bitcoinlib==0.7.0
|
||||
tqdm==4.26.0
|
||||
pytest-timeout==1.3.3
|
||||
|
||||
29
tests/test_plugin.py
Normal file
29
tests/test_plugin.py
Normal file
@ -0,0 +1,29 @@
|
||||
from fixtures import * # noqa: F401,F403
|
||||
|
||||
import subprocess
|
||||
|
||||
|
||||
def test_option_passthrough(node_factory):
|
||||
""" Ensure that registering options works.
|
||||
|
||||
First attempts without the plugin and then with the plugin.
|
||||
"""
|
||||
plugin_path = 'contrib/plugins/helloworld.py'
|
||||
|
||||
help_out = subprocess.check_output([
|
||||
'lightningd/lightningd',
|
||||
'--help'
|
||||
]).decode('utf-8')
|
||||
assert('--greeting' not in help_out)
|
||||
|
||||
help_out = subprocess.check_output([
|
||||
'lightningd/lightningd',
|
||||
'--plugin={}'.format(plugin_path),
|
||||
'--help'
|
||||
]).decode('utf-8')
|
||||
assert('--greeting' in help_out)
|
||||
|
||||
# Now try to see if it gets accepted, would fail to start if the
|
||||
# option didn't exist
|
||||
n = node_factory.get_node(options={'plugin': plugin_path, 'greeting': 'Mars'})
|
||||
n.stop()
|
||||
@ -772,7 +772,7 @@ class NodeFactory(object):
|
||||
'valgrind',
|
||||
'-q',
|
||||
'--trace-children=yes',
|
||||
'--trace-children-skip=*bitcoin-cli*',
|
||||
'--trace-children-skip=*plugins*,*python*,*bitcoin-cli*',
|
||||
'--error-exitcode=7',
|
||||
'--log-file={}/valgrind-errors.%p'.format(node.daemon.lightning_dir)
|
||||
]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user