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
|
#!/usr/bin/env python3
|
||||||
"""Simple plugin to show how to build new plugins for c-lightning
|
"""Simple plugin to show how to build new plugins for c-lightning
|
||||||
|
|
||||||
It demonstrates how a plugin communicates with c-lightning, how it registers
|
It demonstrates how a plugin communicates with c-lightning, how it
|
||||||
command line arguments that should be passed through and how it can register
|
registers command line arguments that should be passed through and how
|
||||||
JSON-RPC commands. We communicate with the main daemon through STDIN and STDOUT,
|
it can register JSON-RPC commands. We communicate with the main daemon
|
||||||
reading and writing JSON-RPC requests.
|
through STDIN and STDOUT, reading and writing JSON-RPC requests.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
@@ -14,8 +14,8 @@ import sys
|
|||||||
greeting = "World"
|
greeting = "World"
|
||||||
|
|
||||||
|
|
||||||
def json_hello(request):
|
def json_hello(request, name):
|
||||||
greeting = "Hello {}".format(request['params']['name'])
|
greeting = "Hello {}".format(name)
|
||||||
return greeting
|
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
|
"""The main daemon is telling us the relevant cli options
|
||||||
"""
|
"""
|
||||||
global greeting
|
global greeting
|
||||||
@@ -52,14 +52,23 @@ methods = {
|
|||||||
'init': json_init,
|
'init': json_init,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
partial = ""
|
partial = ""
|
||||||
for l in sys.stdin:
|
for l in sys.stdin:
|
||||||
partial += l
|
partial += l
|
||||||
try:
|
try:
|
||||||
request = json.loads(partial)
|
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 = {
|
result = {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"result": methods[request['method']](request),
|
"result": result,
|
||||||
"id": request['id']
|
"id": request['id']
|
||||||
}
|
}
|
||||||
json.dump(result, fp=sys.stdout)
|
json.dump(result, fp=sys.stdout)
|
||||||
|
|||||||
Reference in New Issue
Block a user