Skip to content

Commit

Permalink
Raise a broadcast error if etherscan api error #166
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyRonning committed Feb 17, 2020
1 parent 18f875d commit d7e3119
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cert_issuer/blockchain_handlers/ethereum/connectors.py
Expand Up @@ -101,6 +101,8 @@ def broadcast_tx(self, tx, api_token):
logging.error("Etherscan returned an error: %s", response.json()['error'])
raise BroadcastError(response.json()['error'])
if int(response.status_code) == 200:
if response.json().get('message', None) == 'NOTOK':
raise BroadcastError(response.json().get('result', None))
tx_id = response.json().get('result', None)
logging.info("Transaction ID obtained from broadcast through Etherscan: %s", tx_id)
return tx_id
Expand All @@ -119,6 +121,8 @@ def get_balance(self, address, api_token):
'&apikey=%s' % api_token
response = requests.get(broadcast_url)
if int(response.status_code) == 200:
if response.json().get('message', None) == 'NOTOK':
raise BroadcastError(response.json().get('result', None))
balance = int(response.json().get('result', None))
logging.info('Balance check succeeded: %s', response.json())
return balance
Expand All @@ -136,7 +140,8 @@ def get_address_nonce(self, address, api_token):
'&apikey=%s' % api_token
response = requests.get(broadcast_url, )
if int(response.status_code) == 200:
# the int(res, 0) transforms the hex nonce to int
if response.json().get('message', None) == 'NOTOK':
raise BroadcastError(response.json().get('result', None))
nonce = int(response.json().get('result', None), 0)
logging.info('Nonce check went correct: %s', response.json())
return nonce
Expand Down

0 comments on commit d7e3119

Please sign in to comment.