mirror of https://github.com/CIRCL/AIL-framework
				
				
				
			fix: [correlation btc info] catch btc txs error
							parent
							
								
									ee951ca948
								
							
						
					
					
						commit
						9a4feb93a0
					
				|  | @ -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: | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Terrtia
						Terrtia