mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
plugin: Allow both array as well as object params in example plugin
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
a4ded47d34
commit
1e139e412b
@@ -1,10 +1,10 @@
|
||||
#!/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
|
||||
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.
|
||||
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
|
||||
@@ -14,8 +14,8 @@ import sys
|
||||
greeting = "World"
|
||||
|
||||
|
||||
def json_hello(request):
|
||||
greeting = "Hello {}".format(request['params']['name'])
|
||||
def json_hello(request, name):
|
||||
greeting = "Hello {}".format(name)
|
||||
return greeting
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ def json_getmanifest(request):
|
||||
}
|
||||
|
||||
|
||||
def json_init(request):
|
||||
def json_init(request, options):
|
||||
"""The main daemon is telling us the relevant cli options
|
||||
"""
|
||||
global greeting
|
||||
@@ -52,14 +52,23 @@ methods = {
|
||||
'init': json_init,
|
||||
}
|
||||
|
||||
|
||||
partial = ""
|
||||
for l in sys.stdin:
|
||||
partial += l
|
||||
try:
|
||||
request = json.loads(partial)
|
||||
result = None
|
||||
method = methods[request['method']]
|
||||
params = request['params']
|
||||
if isinstance(params, dict):
|
||||
result = method(request, **params)
|
||||
else:
|
||||
result = method(request, *params)
|
||||
|
||||
result = {
|
||||
"jsonrpc": "2.0",
|
||||
"result": methods[request['method']](request),
|
||||
"result": result,
|
||||
"id": request['id']
|
||||
}
|
||||
json.dump(result, fp=sys.stdout)
|
||||
|
||||
Reference in New Issue
Block a user