mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
plugin: Make a common directory of plugins in contrib
No need to create a directory each. Signed-off-by: Christian Decker <@cdecker>
This commit is contained in:
parent
e27b2ea69b
commit
879f9b7986
2 changed files with 1 additions and 76 deletions
|
@ -1,75 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
"""Simple plugin to show how to build new plugins for c-lightning
|
|
||||||
|
|
||||||
It demonstrates how a plugin communicates with c-lightning, how it registers
|
|
||||||
command line arguments that should be passed through and how it can register
|
|
||||||
JSON-RPC commands. We communicate with the main daemon through STDIN and STDOUT,
|
|
||||||
reading and writing JSON-RPC requests.
|
|
||||||
|
|
||||||
"""
|
|
||||||
import json
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
greeting = "World"
|
|
||||||
|
|
||||||
|
|
||||||
def json_hello(request):
|
|
||||||
greeting = "Hello {}".format(request['params']['name'])
|
|
||||||
return greeting
|
|
||||||
|
|
||||||
|
|
||||||
def json_init(request):
|
|
||||||
global greeting
|
|
||||||
return {
|
|
||||||
"options": [
|
|
||||||
{"name": "greeting",
|
|
||||||
"type": "string",
|
|
||||||
"default": greeting,
|
|
||||||
"description": "What name should I call you?"},
|
|
||||||
],
|
|
||||||
"rpcmethods": [
|
|
||||||
{
|
|
||||||
"name": "hello",
|
|
||||||
"description": "Returns a personalized greeting for {name}",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def json_configure(request):
|
|
||||||
"""The main daemon is telling us the relevant cli options
|
|
||||||
"""
|
|
||||||
global greeting
|
|
||||||
|
|
||||||
greeting = request['params']['options']['greeting']
|
|
||||||
return "ok"
|
|
||||||
|
|
||||||
|
|
||||||
def json_ping(request):
|
|
||||||
return "pong"
|
|
||||||
|
|
||||||
|
|
||||||
methods = {
|
|
||||||
'hello': json_hello,
|
|
||||||
'init': json_init,
|
|
||||||
'ping': json_ping,
|
|
||||||
'configure': json_configure,
|
|
||||||
}
|
|
||||||
|
|
||||||
partial = ""
|
|
||||||
for l in sys.stdin:
|
|
||||||
partial += l
|
|
||||||
try:
|
|
||||||
request = json.loads(partial)
|
|
||||||
result = {
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"result": methods[request['method']](request),
|
|
||||||
"id": request['id']
|
|
||||||
}
|
|
||||||
json.dump(result, fp=sys.stdout)
|
|
||||||
sys.stdout.write('\n')
|
|
||||||
sys.stdout.flush()
|
|
||||||
partial = ""
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
|
@ -8,7 +8,7 @@ def test_option_passthrough(node_factory):
|
||||||
|
|
||||||
First attempts without the plugin and then with the plugin.
|
First attempts without the plugin and then with the plugin.
|
||||||
"""
|
"""
|
||||||
plugin_path = 'contrib/helloworld-plugin/main.py'
|
plugin_path = 'contrib/plugins/helloworld.py'
|
||||||
|
|
||||||
help_out = subprocess.check_output([
|
help_out = subprocess.check_output([
|
||||||
'lightningd/lightningd',
|
'lightningd/lightningd',
|
||||||
|
|
Loading…
Add table
Reference in a new issue