Browse Source

new class MoneroRPCClientRaw for non-JSON-RPC methods

The MMGen Project 3 years ago
parent
commit
a42a3210c0
2 changed files with 27 additions and 4 deletions
  1. 24 1
      mmgen/rpc.py
  2. 3 3
      mmgen/xmrwallet.py

+ 24 - 1
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'

+ 3 - 3
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):