def processBtcTransactions(FreezedCurrency): r = { "processed_addresses": 0, "created_transactions": [], "errors_transactions": [], "errors_addresses": [] } allWallets = Wallet.objects.filter() for wallet in allWallets: for btcAddress in wallet.getWalletToCcAddresses(currency='BTC'): r['processed_addresses'] += 1 atm = AtmBtc(btcAddress.address.address) btcAddress.address.address = atm.clean(btcAddress.address.address) try: addressRemoteTransactions = atm.getTransactions() except Exception, ex: addressRemoteTransactions = [] r['errors_addresses'].append("%s" % (traceback.format_exc())) if len(addressRemoteTransactions) > 0: for art in addressRemoteTransactions: if art.get("error"): r['errors_addresses'].append( "failed get data for address: %s" % (btcAddress.address.address)) else: if art['positive'] and art['confirmations'] > 0: try: new = False try: transaction = Transaction.objects.get( hash=art['hash'], currency="BTC", address=btcAddress.address) except Transaction.DoesNotExist: previousCredit = wallet.credit transaction = Transaction() transaction.hash = art['hash'] transaction.date = art['date'] transaction.type = 'deposit' transaction.currency = 'BTC' transaction.freezedUsd = FreezedCurrency.usd transaction.freezedEur = FreezedCurrency.eur transaction.amount = art['value'] transaction.wallet = wallet transaction.address = btcAddress.address transaction.save() # update wallet credit feePercentage = Configuration( ).getConfiguration( "btc_deposit_percentage") wallet.depositIn( FreezedCurrency, transaction, art['value'], 'by AtmBtc found new tx: %s with positive amount: %s (BTC)' % (art['hash'], art['value']), feePercentage) new = True #all good # create transactions info btc transactionInfo = TransactionInfo() transactionInfo.transaction = transaction transactionInfo.description = 'Currency Rate Date: %s' % strftime( FreezedCurrency.dateUpdated, '%Y-%m-%d %H:%M:%S') transactionInfo.save() transactionInfo = TransactionInfo() transactionInfo.transaction = transaction transactionInfo.description = 'BTC -> USD' transactionInfo.cost = FreezedCurrency.usd transactionInfo.save() transactionInfo = TransactionInfo() transactionInfo.transaction = transaction transactionInfo.description = 'BTC -> EUR' transactionInfo.cost = FreezedCurrency.eur transactionInfo.save() transactionInfo = TransactionInfo() transactionInfo.transaction = transaction transactionInfo.description = 'Previous Credit' transactionInfo.cost = previousCredit transactionInfo.save() transactionInfo = TransactionInfo() wallet = Wallet.objects.get(id=wallet.id) transactionInfo.transaction = transaction transactionInfo.description = 'Current Credit' transactionInfo.cost = wallet.credit transactionInfo.save() except Exception, ex: transaction = None r['errors_transactions'].append( "failed insert for transaction: %s" % (art['hash'])) if new: if transaction: if not any(x.hash == art['hash'] for x in r['created_transactions']): r['created_transactions'].append( transaction) # Admin Notification adminNotification = Notification() adminNotification.email = True adminNotification.user = User.objects.get( username="******") adminNotification.setEmailData( "New BTC deposit transaction confirmed", "notifications/email/admin_email_new_deposit_transaction_confirmed.html", { 'transaction': transaction, })
save_question_response(sr, improve_question, line.replace(improve_prefix, '')) elif line.startswith(skills_prefix): save_question_response(sr, skills_question, line.replace(skills_prefix, '')) save_question_response(sr, t_and_c_question, 'Y') save_question_response(sr, bene_question, 'Y') if len(row[1]) > 0: t = Transaction() t.user = user t.date = est.localize(dateparser.parse(row[1])) t.item = common_item t.qty = 1 t.amount = 3000 if user.email.split( '@')[1] == "3cross.coop" else 150 t.save() members_group.user_set.add(user) else: pending_group.user_set.add(user) preferred_shares = 0 if len(row[21]) > 0: preferred_shares = int(row[21]) if preferred_shares > 0: t = Transaction() t.user = user t.date = est.localize(datetime.today()) t.item = preferred_item t.qty = preferred_shares