def error_logger(self,error): self.logger.error('#' * 100) self.logger.error(error) self.logger.error('#' * 100) models.insert_sql(self, 'error_logs', { 'category': self.category, 'file_name': os.path.basename(__file__), 'error': error, 'timestamp': datetime.datetime.now() })
def generate_address(user_name, token): try: # Logs obj_logger = common_util.MyLogger(logs_directory, category) # Generate Crypto Secure Number crypto_secure = ''.join( [str(int(math.pow(number, 2))) for number in os.urandom(20)]) # Generate Private Key private_key = web3.Web3().sha3(text=crypto_secure).hex() # Genrate public Address address = web3.Account.privateKeyToAccount(private_key).address.lower() # Encrypt PK enc_pk = common_util.AESCipher(token, log).encrypt(private_key) # Insert in DB models.insert_sql(logger=obj_logger, table_name='address_master', data={ 'user_name': user_name, 'address': address, 'private_key': enc_pk, }) # Check if encryption algorithm pass enc_pk = models.find_sql(obj_logger, 'address_master', { 'user_name': user_name, 'address': address })[0]['private_key'] dec_pk = common_util.AESCipher(token, log).decrypt(enc_pk) if private_key != dec_pk: raise custom_exception.UserException( exception_str.UserExceptionStr.some_error_occurred) redis_conn.sadd('eth_eth_aw_set', address.encode('utf-8')) return address except custom_exception.UserException: raise except Exception as e: obj_logger.error_logger('Error get_balance : ' + str(e)) raise custom_exception.UserException( exception_str.UserExceptionStr.bad_request)
def user_details(*args, **kwargs): try: # Before request = args[0] time = datetime.datetime.now() ip = self.get_client_ip(request) url = request.build_absolute_uri() type = request.method header = '' body = '' if request.method == 'POST': for key, value in request.POST.items(): body += key + " = " + value + ", " elif request.method == 'GET': for key, value in request.GET.items(): body += key + " = " + value + ", " # Main response = func(*args, **kwargs) response_data = str(response.content) # Insert in DB obj_logger = MyLogger(self.logs_directory, self.category) models.insert_sql( obj_logger, 'server_logs', { 'requestIP': str(ip), 'url': str(url), 'type': type, 'headers': header, 'body': body[:-2] if body else '', 'response': response_data, 'timestamp': time }) return response except Exception as e: obj_logger.error_logger('who_is_hitting : %s' % (e)) return JsonResponse({ 'error ': exception_str.UserExceptionStr.bad_request, 'status': 400 })