Beispiel #1
0
def faucet():
    update_counters()

    c2, conn = connect_to_db(config['DB_PATH'])
    bver = str(get_latest_version(c2))

    message = ''
    if request.method == 'POST':
        try:
            acct = request.form.get('acct')
            print(acct)
            amount = request.form.get('amount')
            print(amount)
            if float(amount) < 0:
                message = 'Amount must be >= 0'
            elif not is_valid_account(acct):
                message = 'Invalid account format'
            else:
                do_cmd('a mb 0 ' + str(float(amount)), p=p)
                do_cmd('tb 0 ' + acct + ' ' + str(float(amount)), p=p)
                acct_link = '<a href="/account/{0}">{0}</a>'.format(acct)
                message = 'Sent ' + amount + ' <small>Libra</small> to ' + acct_link
        except:
            traceback.print_exception(*sys.exc_info())
            message = 'Invalid request logged!'

        if message:
            message = faucet_alert_template.format(message)

    return faucet_template.format(bver, message)
Beispiel #2
0
def acct_details(acct):
    print(acct)
    update_counters()
    try:
        page = int(request.args.get('page'))
    except:
        page = 0

    if not is_valid_account(acct):
        return invalid_account_template

    c2, conn = connect_to_db(config['DB_PATH'])
    bver = str(get_latest_version(c2))

    acct_state_raw = get_acct_raw(acct)
    acct_info = get_acct_info(acct_state_raw)
    print('acct_info', acct_info)

    try:
        tx_list = get_all_account_tx(c2, acct, page)
        tx_tbl = ''
        for tx in tx_list:
            tx_tbl += gen_tx_table_row(tx)
    except:
        print(sys.exc_info())
        traceback.print_exception(*sys.exc_info())
        print('error in building table')

    next_page = "/account/" + acct + "?page=" + str(page + 1)

    conn.close()
    return account_template.format(bver, *acct_info, tx_tbl, next_page)
Beispiel #3
0
def version(ver):
    update_counters()
    c2, conn = connect_to_db(config['DB_PATH'])

    bver = str(get_latest_version(c2))

    try:
        ver = int(ver)
        tx = get_tx_from_db_by_version(ver, c2)
    except:
        conn.close()
        return version_error_template

    # for toggle raw view
    if request.args.get('raw') == '1':
        extra = """<tr>
                    <td><strong>Program Raw</strong></td>
                    <td><pre>{0}</pre></td>
                   </tr>""".format(tx[-1])
        not_raw = '0'
    else:
        extra = ''
        not_raw = '1'

    conn.close()
    return version_template.format(bver, *tx, add_br_every64(tx[12]), extra,
                                   not_raw, tx[-2].replace('<', '&lt;'))
Beispiel #4
0
def index():
    update_counters()
    c2, conn = connect_to_db(config['DB_PATH'])

    bver = str(get_latest_version(c2))

    conn.close()
    return index_template.format(bver)
Beispiel #5
0
def stats():
    update_counters()
    c2, conn = connect_to_db(config['DB_PATH'])
    try:
        # get stats
        stats_all_time = calc_stats(c2)
        stats_24_hours = calc_stats(c2, limit = 3600 * 24)[5:]
        stats_one_hour = calc_stats(c2, limit = 3600)[5:]

        ret = stats_template.format(*stats_all_time, *stats_24_hours, *stats_one_hour)
    except:
        app.logger.exception('error in stats')

    conn.close()

    return ret
Beispiel #6
0
import os
from dotenv import load_dotenv, find_dotenv
from db_funcs import connect_to_db

load_dotenv(find_dotenv())

MY_LOG = os.environ.get('MONGO_LOG')
MY_PASS = os.environ.get('MONGO_PASS')
MY_SERVER = os.environ.get('MONGO_SERVER')
MY_DB = os.environ.get('MONGO_DB')

my_config = {
    'login': MY_LOG,
    'paswd': MY_PASS,
    'host': MY_SERVER,
    'database': MY_DB
}

my_client = connect_to_db(my_config)
print(type(my_client))