Merge #11277: Fix uninitialized URI in batch RPC requests
4526d21
Add test for multiwallet batch RPC calls (Russell Yanofsky)74182f2
Add missing batch rpc calls to python coverage logs (Russell Yanofsky)505530c
Add missing multiwallet rpc calls to python coverage logs (Russell Yanofsky)9f67646
Make AuthServiceProxy._batch method usable (Russell Yanofsky)e02007a
Limit AuthServiceProxyWrapper.__getattr__ wrapping (Russell Yanofsky)edafc71
Fix uninitialized URI in batch RPC requests (Russell Yanofsky) Pull request description: This fixes "Wallet file not specified" errors when making batch wallet RPC calls with more than one wallet loaded. This issue was reported by @NicolasDorier in https://github.com/bitcoin/bitcoin/issues/11257 Request URI is not used for anything except multiwallet request dispatching, so this change has no other effect. Tree-SHA512: b3907af48a6323f864bb045ee2fa56b604188b835025ef82ba3d81673244c04228d796323cec208a676e7cd578a95ec7c7ba1e84d0158b93844d5dda8f6589b9
This commit is contained in:
commit
f74459dba6
6 changed files with 33 additions and 23 deletions
|
@ -192,7 +192,7 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
|
||||||
|
|
||||||
// array of requests
|
// array of requests
|
||||||
} else if (valRequest.isArray())
|
} else if (valRequest.isArray())
|
||||||
strReply = JSONRPCExecBatch(valRequest.get_array());
|
strReply = JSONRPCExecBatch(jreq, valRequest.get_array());
|
||||||
else
|
else
|
||||||
throw JSONRPCError(RPC_PARSE_ERROR, "Top-level object parse error");
|
throw JSONRPCError(RPC_PARSE_ERROR, "Top-level object parse error");
|
||||||
|
|
||||||
|
|
|
@ -389,11 +389,10 @@ bool IsDeprecatedRPCEnabled(const std::string& method)
|
||||||
return find(enabled_methods.begin(), enabled_methods.end(), method) != enabled_methods.end();
|
return find(enabled_methods.begin(), enabled_methods.end(), method) != enabled_methods.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue JSONRPCExecOne(const UniValue& req)
|
static UniValue JSONRPCExecOne(JSONRPCRequest jreq, const UniValue& req)
|
||||||
{
|
{
|
||||||
UniValue rpc_result(UniValue::VOBJ);
|
UniValue rpc_result(UniValue::VOBJ);
|
||||||
|
|
||||||
JSONRPCRequest jreq;
|
|
||||||
try {
|
try {
|
||||||
jreq.parse(req);
|
jreq.parse(req);
|
||||||
|
|
||||||
|
@ -413,11 +412,11 @@ static UniValue JSONRPCExecOne(const UniValue& req)
|
||||||
return rpc_result;
|
return rpc_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string JSONRPCExecBatch(const UniValue& vReq)
|
std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq)
|
||||||
{
|
{
|
||||||
UniValue ret(UniValue::VARR);
|
UniValue ret(UniValue::VARR);
|
||||||
for (unsigned int reqIdx = 0; reqIdx < vReq.size(); reqIdx++)
|
for (unsigned int reqIdx = 0; reqIdx < vReq.size(); reqIdx++)
|
||||||
ret.push_back(JSONRPCExecOne(vReq[reqIdx]));
|
ret.push_back(JSONRPCExecOne(jreq, vReq[reqIdx]));
|
||||||
|
|
||||||
return ret.write() + "\n";
|
return ret.write() + "\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,7 +191,7 @@ extern std::string HelpExampleRpc(const std::string& methodname, const std::stri
|
||||||
bool StartRPC();
|
bool StartRPC();
|
||||||
void InterruptRPC();
|
void InterruptRPC();
|
||||||
void StopRPC();
|
void StopRPC();
|
||||||
std::string JSONRPCExecBatch(const UniValue& vReq);
|
std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq);
|
||||||
|
|
||||||
// Retrieves any serialization flags requested in command line argument
|
// Retrieves any serialization flags requested in command line argument
|
||||||
int RPCSerializationFlags();
|
int RPCSerializationFlags();
|
||||||
|
|
|
@ -76,5 +76,9 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||||
assert_equal(w2.getbalance(), 1)
|
assert_equal(w2.getbalance(), 1)
|
||||||
assert_equal(w3.getbalance(), 2)
|
assert_equal(w3.getbalance(), 2)
|
||||||
|
|
||||||
|
batch = w1.batch([w1.getblockchaininfo.get_request(), w1.getwalletinfo.get_request()])
|
||||||
|
assert_equal(batch[0]["result"]["chain"], "regtest")
|
||||||
|
assert_equal(batch[1]["result"]["walletname"], "w1")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
MultiWalletTest().main()
|
MultiWalletTest().main()
|
||||||
|
|
|
@ -138,17 +138,20 @@ class AuthServiceProxy(object):
|
||||||
self.__conn.request(method, path, postdata, headers)
|
self.__conn.request(method, path, postdata, headers)
|
||||||
return self._get_response()
|
return self._get_response()
|
||||||
|
|
||||||
def __call__(self, *args, **argsn):
|
def get_request(self, *args, **argsn):
|
||||||
AuthServiceProxy.__id_count += 1
|
AuthServiceProxy.__id_count += 1
|
||||||
|
|
||||||
log.debug("-%s-> %s %s"%(AuthServiceProxy.__id_count, self._service_name,
|
log.debug("-%s-> %s %s"%(AuthServiceProxy.__id_count, self._service_name,
|
||||||
json.dumps(args, default=EncodeDecimal, ensure_ascii=self.ensure_ascii)))
|
json.dumps(args, default=EncodeDecimal, ensure_ascii=self.ensure_ascii)))
|
||||||
if args and argsn:
|
if args and argsn:
|
||||||
raise ValueError('Cannot handle both named and positional arguments')
|
raise ValueError('Cannot handle both named and positional arguments')
|
||||||
postdata = json.dumps({'version': '1.1',
|
return {'version': '1.1',
|
||||||
'method': self._service_name,
|
'method': self._service_name,
|
||||||
'params': args or argsn,
|
'params': args or argsn,
|
||||||
'id': AuthServiceProxy.__id_count}, default=EncodeDecimal, ensure_ascii=self.ensure_ascii)
|
'id': AuthServiceProxy.__id_count}
|
||||||
|
|
||||||
|
def __call__(self, *args, **argsn):
|
||||||
|
postdata = json.dumps(self.get_request(*args, **argsn), default=EncodeDecimal, ensure_ascii=self.ensure_ascii)
|
||||||
response = self._request('POST', self.__url.path, postdata.encode('utf-8'))
|
response = self._request('POST', self.__url.path, postdata.encode('utf-8'))
|
||||||
if response['error'] is not None:
|
if response['error'] is not None:
|
||||||
raise JSONRPCException(response['error'])
|
raise JSONRPCException(response['error'])
|
||||||
|
@ -158,7 +161,7 @@ class AuthServiceProxy(object):
|
||||||
else:
|
else:
|
||||||
return response['result']
|
return response['result']
|
||||||
|
|
||||||
def _batch(self, rpc_call_list):
|
def batch(self, rpc_call_list):
|
||||||
postdata = json.dumps(list(rpc_call_list), default=EncodeDecimal, ensure_ascii=self.ensure_ascii)
|
postdata = json.dumps(list(rpc_call_list), default=EncodeDecimal, ensure_ascii=self.ensure_ascii)
|
||||||
log.debug("--> "+postdata)
|
log.debug("--> "+postdata)
|
||||||
return self._request('POST', self.__url.path, postdata.encode('utf-8'))
|
return self._request('POST', self.__url.path, postdata.encode('utf-8'))
|
||||||
|
|
|
@ -31,10 +31,11 @@ class AuthServiceProxyWrapper(object):
|
||||||
self.auth_service_proxy_instance = auth_service_proxy_instance
|
self.auth_service_proxy_instance = auth_service_proxy_instance
|
||||||
self.coverage_logfile = coverage_logfile
|
self.coverage_logfile = coverage_logfile
|
||||||
|
|
||||||
def __getattr__(self, *args, **kwargs):
|
def __getattr__(self, name):
|
||||||
return_val = self.auth_service_proxy_instance.__getattr__(
|
return_val = getattr(self.auth_service_proxy_instance, name)
|
||||||
*args, **kwargs)
|
if not isinstance(return_val, type(self.auth_service_proxy_instance)):
|
||||||
|
# If proxy getattr returned an unwrapped value, do the same here.
|
||||||
|
return return_val
|
||||||
return AuthServiceProxyWrapper(return_val, self.coverage_logfile)
|
return AuthServiceProxyWrapper(return_val, self.coverage_logfile)
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
|
@ -44,20 +45,23 @@ class AuthServiceProxyWrapper(object):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
|
return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
|
||||||
|
self._log_call()
|
||||||
|
return return_val
|
||||||
|
|
||||||
|
def _log_call(self):
|
||||||
rpc_method = self.auth_service_proxy_instance._service_name
|
rpc_method = self.auth_service_proxy_instance._service_name
|
||||||
|
|
||||||
if self.coverage_logfile:
|
if self.coverage_logfile:
|
||||||
with open(self.coverage_logfile, 'a+', encoding='utf8') as f:
|
with open(self.coverage_logfile, 'a+', encoding='utf8') as f:
|
||||||
f.write("%s\n" % rpc_method)
|
f.write("%s\n" % rpc_method)
|
||||||
|
|
||||||
return return_val
|
|
||||||
|
|
||||||
@property
|
|
||||||
def url(self):
|
|
||||||
return self.auth_service_proxy_instance.url
|
|
||||||
|
|
||||||
def __truediv__(self, relative_uri):
|
def __truediv__(self, relative_uri):
|
||||||
return AuthServiceProxyWrapper(self.auth_service_proxy_instance / relative_uri)
|
return AuthServiceProxyWrapper(self.auth_service_proxy_instance / relative_uri,
|
||||||
|
self.coverage_logfile)
|
||||||
|
|
||||||
|
def get_request(self, *args, **kwargs):
|
||||||
|
self._log_call()
|
||||||
|
return self.auth_service_proxy_instance.get_request(*args, **kwargs)
|
||||||
|
|
||||||
def get_filename(dirname, n_node):
|
def get_filename(dirname, n_node):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue