mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
Merge bitcoin/bitcoin#30238: json-rpc 2.0 followups: docs, tests, cli
1f6ab1215bminor: remove unnecessary semicolons from RPC content type examples (Matthew Zipkin)b225295298test: use json-rpc 2.0 in all functional tests by default (Matthew Zipkin)391843b029bitcoin-cli: use json-rpc 2.0 (Matthew Zipkin)d39bdf3397test: remove unused variable in interface_rpc.py (Matthew Zipkin)0ead71df8cdoc: update and link for JSON-RPC 2.0 (Matthew Zipkin) Pull request description: This is a follow-up to #27101. - Addresses [post-merge comments ](https://github.com/bitcoin/bitcoin/pull/27101#discussion_r1606723428) - bitcoin-cli uses JSON-RPC 2.0 - functional tests use JSON-RPC 2.0 by default (exceptions are in the regression tests added by #27101) ACKs for top commit: tdb3: ACK1f6ab1215bcbergqvist: ACK1f6ab1215bTree-SHA512: 49bf14c70464081280216ece538a2f5ec810bac80a86a83ad3284f0f1b017edf755a1a74a45be279effe00218170cafde7c2de58aed07097a95c2c6b837a6b6c
This commit is contained in:
@@ -26,7 +26,7 @@ ServiceProxy class:
|
||||
|
||||
- HTTP connections persist for the life of the AuthServiceProxy object
|
||||
(if server supports HTTP/1.1)
|
||||
- sends protocol 'version', per JSON-RPC 1.1
|
||||
- sends "jsonrpc":"2.0", per JSON-RPC 2.0
|
||||
- sends proper, incrementing 'id'
|
||||
- sends Basic HTTP authentication headers
|
||||
- parses all JSON numbers that look like floats as Decimal
|
||||
@@ -117,7 +117,7 @@ class AuthServiceProxy():
|
||||
params = dict(args=args, **argsn)
|
||||
else:
|
||||
params = args or argsn
|
||||
return {'version': '1.1',
|
||||
return {'jsonrpc': '2.0',
|
||||
'method': self._service_name,
|
||||
'params': params,
|
||||
'id': AuthServiceProxy.__id_count}
|
||||
@@ -125,15 +125,28 @@ class AuthServiceProxy():
|
||||
def __call__(self, *args, **argsn):
|
||||
postdata = json.dumps(self.get_request(*args, **argsn), default=serialization_fallback, ensure_ascii=self.ensure_ascii)
|
||||
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
|
||||
if response['error'] is not None:
|
||||
raise JSONRPCException(response['error'], status)
|
||||
elif 'result' not in response:
|
||||
raise JSONRPCException({
|
||||
'code': -343, 'message': 'missing JSON-RPC result'}, status)
|
||||
elif status != HTTPStatus.OK:
|
||||
raise JSONRPCException({
|
||||
'code': -342, 'message': 'non-200 HTTP status code but no JSON-RPC error'}, status)
|
||||
# For backwards compatibility tests, accept JSON RPC 1.1 responses
|
||||
if 'jsonrpc' not in response:
|
||||
if response['error'] is not None:
|
||||
raise JSONRPCException(response['error'], status)
|
||||
elif 'result' not in response:
|
||||
raise JSONRPCException({
|
||||
'code': -343, 'message': 'missing JSON-RPC result'}, status)
|
||||
elif status != HTTPStatus.OK:
|
||||
raise JSONRPCException({
|
||||
'code': -342, 'message': 'non-200 HTTP status code but no JSON-RPC error'}, status)
|
||||
else:
|
||||
return response['result']
|
||||
else:
|
||||
assert response['jsonrpc'] == '2.0'
|
||||
if status != HTTPStatus.OK:
|
||||
raise JSONRPCException({
|
||||
'code': -342, 'message': 'non-200 HTTP status code'}, status)
|
||||
if 'error' in response:
|
||||
raise JSONRPCException(response['error'], status)
|
||||
elif 'result' not in response:
|
||||
raise JSONRPCException({
|
||||
'code': -343, 'message': 'missing JSON-RPC 2.0 result and error'}, status)
|
||||
return response['result']
|
||||
|
||||
def batch(self, rpc_call_list):
|
||||
@@ -142,7 +155,7 @@ class AuthServiceProxy():
|
||||
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
|
||||
if status != HTTPStatus.OK:
|
||||
raise JSONRPCException({
|
||||
'code': -342, 'message': 'non-200 HTTP status code but no JSON-RPC error'}, status)
|
||||
'code': -342, 'message': 'non-200 HTTP status code'}, status)
|
||||
return response
|
||||
|
||||
def _get_response(self):
|
||||
|
||||
Reference in New Issue
Block a user