Started serializedAPI plugin
This commit is contained in:
parent
c880b6fa7a
commit
264eeaa988
1
static-data/default-plugins/rpc/.env
Normal file
1
static-data/default-plugins/rpc/.env
Normal file
@ -0,0 +1 @@
|
||||
PYTHONPATH=./venv/bin/python310:../../src/:./
|
4
static-data/default-plugins/rpc/info.json
Normal file
4
static-data/default-plugins/rpc/info.json
Normal file
@ -0,0 +1,4 @@
|
||||
{ "name": "rpc",
|
||||
"version": "0.0.0",
|
||||
"author": "onionr"
|
||||
}
|
69
static-data/default-plugins/rpc/main.py
Normal file
69
static-data/default-plugins/rpc/main.py
Normal file
@ -0,0 +1,69 @@
|
||||
"""Onionr - Private P2P Communication.
|
||||
|
||||
Default example plugin for devs or to test blocks
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
import locale
|
||||
from threading import Thread
|
||||
|
||||
import cherrypy
|
||||
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||
# import after path insert
|
||||
|
||||
from utils import identifyhome
|
||||
from onionrthreads import add_onionr_thread
|
||||
|
||||
"""
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
|
||||
plugin_name = 'rpc'
|
||||
PLUGIN_VERSION = '0.0.0'
|
||||
socket_file_path = identifyhome.identify_home() + 'rpc.sock'
|
||||
|
||||
from jsonrpc import JSONRPCResponseManager, dispatcher
|
||||
|
||||
|
||||
@dispatcher.add_method
|
||||
def foobar(**kwargs):
|
||||
return kwargs["foo"] + kwargs["bar"]
|
||||
|
||||
class OnionrRPC(object):
|
||||
@cherrypy.expose
|
||||
@cherrypy.tools.json_out()
|
||||
def rpc(self):
|
||||
# Dispatcher is dictionary {<method_name>: callable}
|
||||
data = cherrypy.request.body.read().decode('utf-8')
|
||||
|
||||
dispatcher["echo"] = lambda s: s
|
||||
dispatcher["add"] = lambda a, b: a + b
|
||||
|
||||
response = JSONRPCResponseManager.handle(data, dispatcher)
|
||||
return response.json
|
||||
|
||||
|
||||
def on_init(api, data=None):
|
||||
config = {
|
||||
'server.socket_file': socket_file_path,
|
||||
'engine.autoreload.on': False
|
||||
}
|
||||
cherrypy.config.update(config)
|
||||
|
||||
add_onionr_thread(
|
||||
cherrypy.quickstart, 5, 'OnionrRPCServer',
|
||||
OnionrRPC(), initial_sleep=0)
|
Loading…
Reference in New Issue
Block a user