From a42a3210c00f3d32b626a983a5b6dd075899abae Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 8 May 2021 11:47:28 +0000 Subject: [PATCH] new class MoneroRPCClientRaw for non-JSON-RPC methods --- mmgen/rpc.py | 25 ++++++++++++++++++++++++- mmgen/xmrwallet.py | 6 +++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/mmgen/rpc.py b/mmgen/rpc.py index 3262fc44..fe5254a9 100755 --- a/mmgen/rpc.py +++ b/mmgen/rpc.py @@ -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' diff --git a/mmgen/xmrwallet.py b/mmgen/xmrwallet.py index 07c537b4..700c4451 100755 --- a/mmgen/xmrwallet.py +++ b/mmgen/xmrwallet.py @@ -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):