예제 #1
0
async def make_transaction_to_address(source_user, amount, withdraw_address, uid, target_id=None, giveaway_id=0, verify_address=False):
	# Do not validate address for giveaway tx because we do not know it yet
	if verify_address:
		# Check to see if the withdraw address is valid
		#pulowi falta servicio de validacion
		#wallet_command = {'action': 'validate_account_number',
		#		  'account': withdraw_address}
		#address_validation = await communicate_wallet_async(wallet_command)

		#if ((withdraw_address[:4] == 'ban_' and len(withdraw_address) != 64)
		#		or address_validation['valid'] != '1'):
		#	raise util.TipBotException('invalid_address')

		if ((withdraw_address[:4] == 'tgm_' and len(withdraw_address) != 106)):
			raise util.TipBotException('invalid_address')


	amount = int(amount)
	if amount >= 1:
		# See if destination address belongs to a user
		if target_id is None:
			user = db.get_user_by_wallet_address(withdraw_address)
			if user is not None:
				target_id=user.user_id
		# Update pending send for user
		db.create_transaction(source_user, uid, withdraw_address,amount, target_id, giveaway_id)
		logger.info('TX queued, uid %s', uid)
	else:
		raise util.TipBotException('balance_error')

	return amount
예제 #2
0
파일: app.py 프로젝트: PooneetThaper/TTP-FS
def buy_ticker(email, ticker, quantity):
    price = api.get_price(request.form['ticker']).json()
    if price == 'Unknown symbol':
        # error
        return False
    else:
        total_price = price * quantity
        user_cash = db.get_user_cash(session['email'])
        if total_price <= user_cash:
            db.update_user_cash(session['email'], user_cash - total_price)
            db.create_transaction(session['email'], 'buy', ticker, quantity,
                                  total_price)
            db.update_holding(session['email'], ticker, quantity)
            return True
        else:
            # error
            return False
예제 #3
0
파일: app.py 프로젝트: PooneetThaper/TTP-FS
def sell_ticker(email, ticker, quantity):
    price = api.get_price(request.form['ticker']).json()
    if price == 'Unknown symbol':
        # error
        return False
    else:
        user_holding = db.get_user_holdings(session['email'], ticker)
        if user_holding == None:
            return False
        elif user_holding.quantity >= quantity:
            total_price = price * quantity
            user_cash = db.get_user_cash(session['email'])
            db.update_user_cash(session['email'], user_cash + total_price)
            db.create_transaction(session['email'], 'sell', ticker, quantity,
                                  total_price)
            db.update_holding(session['email'], ticker, quantity * -1)
            return True
        else:
            #error
            return False
예제 #4
0
async def make_transaction_to_address(source_user,
                                      amount,
                                      withdraw_address,
                                      uid,
                                      target_id=None,
                                      giveaway_id=0,
                                      verify_address=False):
    # Do not validate address for giveaway tx because we do not know it yet
    if verify_address:
        # Check to see if the withdraw address is valid
        wallet_command = {
            'action': 'validate_account_number',
            'account': withdraw_address
        }
        address_validation = await asyncio.get_event_loop().run_in_executor(
            None, communicate_wallet, wallet_command)

        # If the address was the incorrect length, did not start with xrb_ or nano_ or was deemed invalid by the node, return an error.
        address_prefix_valid = withdraw_address[:4] == 'ban_' \
         or withdraw_address[:5] == 'ban_'
        if len(withdraw_address) != 64 or not address_prefix_valid \
         or address_validation['valid'] != '1':
            raise util.TipBotException('invalid_address')

    amount = int(amount)
    if amount >= 1:
        # See if destination address belongs to a user
        if target_id is None:
            user = db.get_user_by_wallet_address(withdraw_address)
            if user is not None:
                target_id = user.user_id
        # Update pending send for user
        db.create_transaction(source_user, uid, withdraw_address, amount,
                              target_id, giveaway_id)
        logger.info('TX queued, uid %s', uid)
    else:
        raise util.TipBotException('balance_error')

    return amount