Skip to content

Commit

Permalink
Consolidate rpc Proxy headers in single class property
Browse files Browse the repository at this point in the history
  • Loading branch information
Titan-C committed Jul 21, 2022
1 parent d3fea9c commit 201b4e2
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions bitcoin/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,8 @@ def __init__(self,
self.__conn = httplib.HTTPConnection(self.__url.hostname, port=port,
timeout=timeout)

def _call(self, service_name, *args):
self.__id_count += 1

postdata = json.dumps({'version': '1.1',
'method': service_name,
'params': args,
'id': self.__id_count})

@property
def _headers(self):
headers = {
'Host': self.__url.hostname,
'User-Agent': DEFAULT_USER_AGENT,
Expand All @@ -254,7 +248,18 @@ def _call(self, service_name, *args):
if self.__auth_header is not None:
headers['Authorization'] = self.__auth_header

self.__conn.request('POST', self.__url.path, postdata, headers)
return headers

def _call(self, service_name, *args):
self.__id_count += 1

postdata = json.dumps({'version': '1.1',
'method': service_name,
'params': args,
'id': self.__id_count})


self.__conn.request('POST', self.__url.path, postdata, self._headers)

response = self._get_response()
err = response.get('error')
Expand All @@ -272,17 +277,7 @@ def _call(self, service_name, *args):

def _batch(self, rpc_call_list):
postdata = json.dumps(list(rpc_call_list))

headers = {
'Host': self.__url.hostname,
'User-Agent': DEFAULT_USER_AGENT,
'Content-type': 'application/json',
}

if self.__auth_header is not None:
headers['Authorization'] = self.__auth_header

self.__conn.request('POST', self.__url.path, postdata, headers)
self.__conn.request('POST', self.__url.path, postdata, self._headers)
return self._get_response()

def _get_response(self):
Expand Down

0 comments on commit 201b4e2

Please sign in to comment.