mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2024-09-20 15:37:30 +00:00
8b225fde43
* Fix stdouterr issue when shutdown storage node * Fix random failure for submission test * add more info for failed rpc * use single file instead of subprocess pipe to launch CLI * Opt test_all for windows * wait for log entry before file sync by admin
32 lines
982 B
Python
32 lines
982 B
Python
from jsonrpcclient import request, parse, Ok
|
|
import requests
|
|
|
|
|
|
class SimpleRpcProxy:
|
|
def __init__(self, url, timeout=60):
|
|
self.url = url
|
|
self.timeout = timeout
|
|
|
|
def __getattr__(self, name):
|
|
return RpcCaller(self.url, name, self.timeout)
|
|
|
|
|
|
class RpcCaller:
|
|
def __init__(self, url, method, timeout):
|
|
self.url = url
|
|
self.method = method
|
|
self.timeout = timeout
|
|
|
|
def __call__(self, *args, **argsn):
|
|
r = request(self.method, *args)
|
|
try:
|
|
response = requests.post(self.url, json=r, timeout=self.timeout)
|
|
parsed = parse(response.json())
|
|
if isinstance(parsed, Ok):
|
|
return parsed.result
|
|
else:
|
|
print("Failed to call RPC, method = %s(%s), error = %s" % (self.method, *args, parsed))
|
|
except Exception as ex:
|
|
print("Failed to call RPC, method = %s(%s), exception = %s" % (self.method, *args, ex))
|
|
return None
|