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 Jan 2, 2021
1 parent ad40578 commit 4ac23c0
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 @@ -224,14 +224,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 @@ -241,7 +235,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 @@ -259,17 +264,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 4ac23c0

Please sign in to comment.