new class MoneroRPCClientRaw for non-JSON-RPC methods

This commit is contained in:
The MMGen Project 2021-05-08 11:47:28 +00:00
commit a42a3210c0
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 27 additions and 4 deletions

View file

@ -236,6 +236,7 @@ class CallSigs:
class RPCClient(MMGenObject):
json_rpc = True
auth_type = None
has_auth_cookie = False
network_proto = 'http'
@ -369,7 +370,10 @@ class RPCClient(MMGenObject):
return [r['result'] for r in json.loads(text,parse_float=Decimal,encoding='UTF-8')]
else:
try:
return json.loads(text,parse_float=Decimal,encoding='UTF-8')['result']
if self.json_rpc:
return json.loads(text,parse_float=Decimal,encoding='UTF-8')['result']
else:
return json.loads(text,parse_float=Decimal,encoding='UTF-8')
except:
t = json.loads(text)
try:
@ -679,6 +683,25 @@ class MoneroRPCClient(RPCClient):
rpcmethods = ( 'get_info', )
class MoneroRPCClientRaw(MoneroRPCClient):
json_rpc = False
host_path = '/'
async def call(self,method,*params,**kwargs):
assert params == (), f'{type(self).__name__}.call() accepts keyword arguments only'
return await self.process_http_resp(self.backend.run(
payload = kwargs,
timeout = self.timeout,
wallet = method
))
@staticmethod
def make_host_path(arg):
return arg
rpcmethods = ( 'get_height', 'send_raw_transaction' )
class MoneroWalletRPCClient(MoneroRPCClient):
auth_type = 'digest'

View file

@ -24,7 +24,7 @@ import os,re
from collections import namedtuple
from .common import *
from .addr import KeyAddrList,AddrIdxList
from .rpc import MoneroRPCClient, MoneroWalletRPCClient
from .rpc import MoneroRPCClientRaw, MoneroWalletRPCClient
from .daemon import MoneroWalletDaemon
xmrwallet_uarg_info = (
@ -322,7 +322,7 @@ class MoneroWalletOps:
async def run(self,d,fn):
chain_height = (await self.dc.call('get_info'))['height']
chain_height = (await self.dc.call('get_height'))['height']
msg(f' Chain height: {chain_height}')
import time
@ -373,7 +373,7 @@ class MoneroWalletOps:
def post_init(self):
host,port = uarg.daemon.split(':') if uarg.daemon else ('localhost',self.wd.daemon_port)
self.dc = MoneroRPCClient(host=host, port=int(port), user=None, passwd=None)
self.dc = MoneroRPCClientRaw(host=host, port=int(port), user=None, passwd=None)
self.accts_data = {}
def post_process(self):