From 9a4feb93a01492584eac8c2a2f14a5041d087f43 Mon Sep 17 00:00:00 2001 From: Terrtia Date: Thu, 25 May 2023 16:11:55 +0200 Subject: [PATCH] fix: [correlation btc info] catch btc txs error --- bin/lib/btc_ail.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/lib/btc_ail.py b/bin/lib/btc_ail.py index e17e257c..34ddd9d5 100755 --- a/bin/lib/btc_ail.py +++ b/bin/lib/btc_ail.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import json +import logging import os import sys import requests @@ -8,6 +10,8 @@ import requests sys.path.append(os.environ['AIL_BIN']) from lib.objects.CryptoCurrencies import CryptoCurrency +logger = logging.getLogger() + blockchain_all = 'https://blockchain.info/rawaddr' # pre-alpha script @@ -18,23 +22,26 @@ def get_bitcoin_info(bitcoin_address, nb_transaction=50): set_btc_in = set() set_btc_out = set() try: - req = requests.get('{}/{}?limit={}'.format(blockchain_all, bitcoin_address, nb_transaction)) + req = requests.get(f'{blockchain_all}/{bitcoin_address}?limit={nb_transaction}') jreq = req.json() except Exception as e: - print(e) + logger.warning(e) + return dict_btc + + if not jreq.get('n_tx'): + logger.critical(json.dumps(jreq)) return dict_btc - # print(json.dumps(jreq)) dict_btc['n_tx'] = jreq['n_tx'] dict_btc['total_received'] = float(jreq['total_received'] / 100000000) dict_btc['total_sent'] = float(jreq['total_sent'] / 100000000) dict_btc['final_balance'] = float(jreq['final_balance'] / 100000000) for transaction in jreq['txs']: - for input in transaction['inputs']: - if 'addr' in input['prev_out']: - if input['prev_out']['addr'] != bitcoin_address: - set_btc_in.add(input['prev_out']['addr']) + for t_input in transaction['inputs']: + if 'addr' in t_input['prev_out']: + if t_input['prev_out']['addr'] != bitcoin_address: + set_btc_in.add(t_input['prev_out']['addr']) for output in transaction['out']: if 'addr' in output: if output['addr'] != bitcoin_address: