Skip to content

Commit

Permalink
Add api-key to Blocksmurfer provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryp Toon committed Jan 13, 2025
1 parent bb98235 commit b6fb079
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 2 additions & 4 deletions bitcoinlib/services/baseclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,16 @@ def __init__(self, network, provider, base_url, denominator, api_key='', provide
except Exception:
raise ClientError("This Network is not supported by %s Client" % provider)

def request(self, url_path, variables=None, method='get', secure=True, post_data=''):
def request(self, url_path, variables=None, method='get', secure=True, post_data='', header=None):
url_vars = ''
url = self.base_url + url_path
if not url or not self.base_url:
raise ClientError("No (complete) url provided: %s" % url)
headers = {
'User-Agent': 'BitcoinLib/%s' % BITCOINLIB_VERSION,
'Accept': 'application/json',
# 'Content-Type': 'application/json',
"Referrer": "https://www.github.com/1200wd/bitcoinlib",
}
# ToDo: Check use 'headers = None' for some providers?
} | (header or {})
if method == 'get':
if variables is None:
variables = {}
Expand Down
9 changes: 5 additions & 4 deletions bitcoinlib/services/blocksmurfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

class BlocksmurferClient(BaseClient):

def __init__(self, network, base_url, denominator, *args):
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args)
def __init__(self, network, base_url, denominator, api_key, *args):
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, api_key, *args)

def compose_request(self, function, parameter='', parameter2='', variables=None, post_data='', method='get'):
url_path = function
Expand All @@ -43,9 +43,10 @@ def compose_request(self, function, parameter='', parameter2='', variables=None,
url_path += '/' + str(parameter2)
if variables is None:
variables = {}
header = {}
if self.api_key:
variables.update({'token': self.api_key})
return self.request(url_path, variables, method, post_data=post_data)
header = {'auth-key': self.api_key}
return self.request(url_path, variables, method, post_data=post_data, header=header)

def getbalance(self, addresslist):
balance = 0
Expand Down

0 comments on commit b6fb079

Please sign in to comment.