def deposit(currency): """ Returns deposit address for given currency from SQL. """ if not is_logged_in(session): return home_page("ltc_btc",danger="Please log in to perform that action.") if not config.is_valid_currency(currency): return account_page(danger="Invalid Currency!") addr = Address.query.filter(Address.currency==currency).filter(Address.user==session['userid']).first().address return account_page(deposit=addr)
def withdraw(currency): if not is_logged_in(session): return home_page("ltc_btc",danger="Please log in to perform that action.") if not config.is_valid_currency(currency): return account_page(danger="Invalid Currency!") if request.method == 'GET': return account_page(withdraw=currency) elif request.method == 'POST': if 'amount' not in request.form or 'address' not in request.form: return account_page(danger="Please enter an address and an amount!") #TODO: change this error try: total = string_to_currency_unit(request.form['amount'], config.get_multiplier(currency)) except: return account_page(danger="Invalid amount!") if check_balance(currency,session['userid']) < total or total < 0: return account_page(danger="Balance too low to execute withdrawal!") #TODO: add valid address checking adjustbalance(currency,session['userid'],-1 * total) co = CompletedOrder(currency + "_" + currency, "WITHDRAWAL", total, 0, session['userid'], is_withdrawal=True, withdrawal_address=request.form['address']) db_session.add(co) db_session.commit() return account_page(success="Deposit to " + request.form['address'] + " completed!")
def withdraw(currency): if not is_logged_in(session): return home_page("ltc_btc",danger="Please log in to perform that action.") if not config.is_valid_currency(currency): return account_page(danger="Invalid Currency!") if request.method == 'GET': return account_page(withdraw=currency) elif request.method == 'POST': if 'amount' not in request.form or 'address' not in request.form: return account_page(danger="Please enter an address and an amount!") #TODO: change this error try: total = float(request.form['amount']) except: return account_page(danger="Invalid amount!") if check_balance(currency,session['userid']) < int(total * config.get_multiplier(currency)) or total < 0: return account_page(danger="Balance too low to execute withdrawal!") #TODO: add valid address checking adjustbalance(currency,session['userid'],-1 * int(total * config.get_multiplier(currency))) co = CompletedOrder(currency + "_" + currency, "WITHDRAWAL", total, 0, session['userid'], is_withdrawal=True, withdrawal_address=request.form['address']) db_session.add(co) db_session.commit() return account_page(success="Deposit to " + request.form['address'] + " completed!")
def generate_deposit_address(currency): addr = "" if config.is_valid_currency(currency): rpc = ServiceProxy(config.getRPC(currency)) addr = rpc.getnewaddress() return addr
def history(currency): if not is_logged_in(session): return home_page("ltc_btc",danger="Please log in to perform that action.") if not config.is_valid_currency(currency): return account_page(danger="Invalid Currency!") return account_page(history=currency, orders=tradehistory(currency, session['userid']))