Exemple #1
0
def best_price():
    if len(request.args) == 0:
        mess = 'len(request.args)==0'
        print mess
        return mess
    import db_client
    import db_common

    s_b = None
    if request.args[0] == 'sell': s_b = True
    _in = request.args[1]
    _out = request.args[2]
    volume_in = request.args[3]
    acurr_in, x, e = db_common.get_currs_by_abbrev(db, _in)
    acurr_out, x, e = db_common.get_currs_by_abbrev(db, _out)
    expired = datetime.datetime.now() - datetime.timedelta(2, 60)
    dealer_id = None
    d_e = None
    best_rate, pair = db_client.get_best_price_for_volume(
        db, acurr_in.id, acurr_out.id, float(volume_in), expired, s_b,
        dealer_id, d_e)
    res = best_rate and "%s, 1/X = %s" % (best_rate,
                                          1 / best_rate) or best_rate
    print res, pair
    return res
Exemple #2
0
def conv_pow():
    if len(request.args) < 2:
        mess = 'len(request.args)==0 - [curr_in]/[curr_out]/[amo]'
        print mess
        return mess
    import rates_lib
    import db_common
    curr_in, x, e = db_common.get_currs_by_abbrev(db, request.args[0])
    curr_out, x, e = db_common.get_currs_by_abbrev(db, request.args[1])
    amo = float(len(request.args) > 2 and request.args[2] or 1)
    conv_amo = rates_lib.conv_pow(db, curr_in, amo, curr_out)
    print conv_amo, amo / conv_amo
    return conv_amo
Exemple #3
0
def ophrans():
    if len(request.args) == 0:
        mess = 'len(request.args)==0 - [BTC]'
        return mess
    import db_common
    #import crypto_client
    curr, xcurr, e = db_common.get_currs_by_abbrev(db, request.args[0])
    conn = crypto_client.conn(curr, xcurr)
    h = CAT()
    cnt = 0
    for r in db((db.deal_acc_addrs.xcurr_id == xcurr.id)
                & (db.pay_ins.ref_ == db.deal_acc_addrs.id)).select():
        cnt += 1
        txid = r.pay_ins.txid
        #print txid
        if len(txid) > 60 and len(txid) < 70:
            res = conn.gettransaction(txid)  # выдает только для кошелька
            if res:
                conf = res.get('confirmations')
                #print conf
                if conf > 2:
                    continue
            h += P(BEAUTIFY(r.pay_ins))
            h += P(BEAUTIFY(res))
            h += HR()
    return dict(h=CAT(H3('counter:', cnt), h))
Exemple #4
0
def get_best_price_for_volume():
    if len(request.args) == 0:
        mess = 'len(request.args)==0'
        print mess
        return mess
    import db_client
    import db_common
    a_in, x, e = db_common.get_currs_by_abbrev(db, request.args[0])
    a_out, x, e = db_common.get_currs_by_abbrev(db, request.args[1])
    expired = datetime.datetime.now() - datetime.timedelta(5, 600)
    s_b = len(request.args) < 4 or request.args[3] == 'sell'
    #s_b = not 3 in request.args or request.args[3]=='sell'
    print s_b
    print db_client.get_best_price_for_volume(db, a_in.id, a_out.id,
                                              float(request.args[2]), expired,
                                              s_b)
Exemple #5
0
def make_simple_shop(db, name, vars, noseek=False, curr=None, xcurr=None):
    if not noseek: shop = db(db.shops.name == name).select().first()
    #print shop
    if noseek or not shop:
        if not curr and vars.get('conv_curr'):
            # найдем по абривиатуре
            curr, xcurr, _ = db_common.get_currs_by_abbrev(
                db, vars['conv_curr'])
        if not xcurr:
            return
        # проверим на слэш в конце УРЛ - он мешает при уведомлении - удалим
        url = vars.get('shop_url')
        # от / не зависит if url[-1:] == '/': url = url[:-1]
        shop_id = db.shops.insert(
            name=name,
            simple_curr=curr.id,
            url=url,
            show_text=vars.get('show_text'),
            note_url=vars.get('note_url'),
            back_url=vars.get('back_url'),
            note_on=vars.get('note_on'),
            icon_url=vars.get('icon_url'),
            email=vars.get('email'),
            not_listed=True,
        )
        shop = db.shops[shop_id]
        # и добавим адрес кошелька
        db.shops_xwallets.insert(shop_id=shop_id, xcurr_id=xcurr.id, addr=name)

    return shop
Exemple #6
0
def curr_get_info():
    import time
    time.sleep(1)

    curr_abbrev = request.args(0)
    if not curr_abbrev:
        return {"error": "empty curr - example: curr_get_info/btc"}
    curr_abbrev = curr_abbrev.upper()
    from db_common import get_currs_by_abbrev
    curr, xcurr, e = get_currs_by_abbrev(db, curr_abbrev)
    if not xcurr:
        return {"error": "invalid curr: " + curr_abbrev}
    from crypto_client import conn
    try:
        conn = conn(curr, xcurr)
    except:
        conn = None
    if not conn:
        return {
            'error':
            'Connection to ' + curr_abbrev + ' wallet is lost. Try later'
        }
    print conn
    try:
        res = conn.getinfo()
    #except Exception as e:
    except Exception, e:
        return {
            'error':
            'Connection to ' + curr_abbrev +
            ' wallet raise error [%s]. Try later' % e
        }
Exemple #7
0
def tx_senders():
    session.forget(response)
    txid = request.args(1)
    if not txid:
        #raise HTTP(501, {"error": "empty pars"})
        return {'error':"need txid: /tx_senders.json/[curr]/[txid]"}
    curr_abbrev = request.args(0)
    import db_common
    curr, xcurr, e = db_common.get_currs_by_abbrev(db, curr_abbrev)
    if not xcurr:
        return {"error": "invalid curr"}
    
    token_system = None
    token_key = xcurr.as_token
    if token_key:
        token = db.tokens[token_key]
        token_system = db.systems[token.system_id]
        res = dict(result=crypto_client.sender_addrs(conn, token_system, txid))
        return res

    import crypto_client
    conn = crypto_client.conn(curr, xcurr)
    if not conn:
        return {"error": "not connected to wallet"}
    res = dict(result=crypto_client.sender_addrs(conn, token_system, txid))
    return res
Exemple #8
0
def tx_info():
    session.forget(response)

    txid = request.args(1)
    if not txid:
        return {'error':"need txid: /tx_info.json/[curr]/[txid]"}
    curr_abbrev = request.args(0)
    import db_common
    curr,xcurr,e = db_common.get_currs_by_abbrev(db, curr_abbrev)
    if not xcurr:
        return {"error": "invalid curr:  /tx_info.json/[curr]/[txid]"}

    import crypto_client

    token_system = conn = None
    token_key = xcurr.as_token
    if token_key:
        token = db.tokens[token_key]
        token_system = db.systems[token.system_id]
        res = dict(result=crypto_client.get_tx_info(conn, token_system, txid))
        return res

    conn = crypto_client.conn(curr, xcurr)
    if not conn:
        return {"error": "not connected to wallet"}
    res = crypto_client.get_tx_info(conn, txid, request.vars)
    return res
def add_pay_in_tx():
    curr = request.vars.curr
    if not curr:
        return 'error - need curr'
    txid = request.vars.txid
    if not txid:
        return 'error - need txid'
    vout = request.vars.vout
    if not vout:
        return 'error - need vout'
    import db_common
    curr, xcurr, e = db_common.get_currs_by_abbrev(db, curr)
    if not xcurr:
        return 'error - invalid curr'

    from time import sleep
    sleep(1)

    pay_in = db((db.pay_ins.txid == txid)
                & (db.pay_ins.vout == vout)).select().first()
    if pay_in:
        return CAT(H2('already in PAY_INS'), BEAUTIFY(pay_in))

    import crypto_client
    conn = crypto_client.conn(curr, xcurr)
    if not conn:
        return 'error - not connected to wallet'
    res = None
    try:
        res = conn.getrawtransaction(txid, 1)  # все выдает
    except Exception as e:
        return 'error %s' % e

    if 'hex' in res: res.pop('hex')
    txid = res.get('txid')
    if not txid:
        return BEAUTIFY(res)

    res.pop('vin')
    vout = int(vout)
    vouts = res['vout']
    if len(vouts) <= vout:
        return CAT(H3('vout so BIG'), BEAUTIFY(vouts))
    vout = vouts[vout]
    res.pop('vout')

    scriptPubKey = vout['scriptPubKey']
    addr = scriptPubKey['addresses'][0]
    acc_addr = db(db.deal_acc_addrs.addr == addr).select().first()
    if not acc_addr:
        return H3('not found order for address: ' + addr)

    value = vout['value']
    confs = res['confirmations']

    return CAT(LABEL('confs'), INPUT(_name='confs', _value=confs), ' ',
               LABEL('address:'), INPUT(_name='addr', _value=addr), ' ',
               LABEL('value:'), INPUT(_name='amount', _value=value), BR(),
               INPUT(_type='submit'))
Exemple #10
0
def e_gold():
    import rates_lib, db_common
    session.forget(response)
    #ss = common.page_stats(db,response['view'])
    #print response['view'], ss, common.ip()

    title = response.title = T("Биткоин - Настоящее цифровое золото...")
    subtitle = response.subtitle = 'Здесь мы научим тебя как заработать на своё будущее.'
    a_in, x, e = db_common.get_currs_by_abbrev(db, 'BTC')
    a_out, x, e = db_common.get_currs_by_abbrev(db, 'RUB')
    b, s, avg = rates_lib.get_average_rate_bsa(db, a_in.id, a_out.id, None)
    rate2 = rate = avg and int(avg) or '****'  #round(float(avg or 0),2)
    #a_in2,x,e = db_common.get_currs_by_abbrev(db, 'SIB')
    #b,s, avg2 = rates_lib.get_average_rate_bsa(db, a_in2.id, a_out.id, None)
    #rate2 = avg2 and round(float(avg2 or 0), 2) or -1

    return dict(title=title, subtitle=subtitle, rate=rate, rate2=rate2)
Exemple #11
0
def conv_to_curr():
    return 'switch OFF'
    db.currs.truncate()
    for r in db(db.xcurrs).select():
        if r.abbrev == '---': continue
        curr_id = db.currs.insert(abbrev=r.abbrev,
                                  used=True,
                                  name=r.name,
                                  name2=r.name2,
                                  icon=r.icon,
                                  xcurr_id=r.id)
        r.curr_id = curr_id
        r.update_record()
    for r in db(db.ecurrs).select():
        if r.abbrev == '---': continue
        curr_id = db.currs.insert(abbrev=r.abbrev,
                                  used=True,
                                  name=r.name,
                                  name2=r.name,
                                  icon=r.icon,
                                  ecurr_id=r.id)
        r.curr_id = curr_id
        r.update_record()
    #return
    for r in db(db.deal_accs).select():
        e_id = r.ecurr_id
        a_id = db(db.currs.ecurr_id == e_id).select().first()
        r.curr_id = a_id.id
        r.update_record()

    import db_common
    for r in db(db.exchg_limits).select():
        xe_rec, _ = get_acurr_rec_xe(db, r.acurr_id)
        r.curr_id = xe_rec.curr_id
        r.update_record()

    for r in db(db.exchg_pairs).select():
        xe_rec, _ = get_acurr_rec_xe(db, r.acurr1_id)
        r.curr1_id = xe_rec.curr_id
        xe_rec, _ = get_acurr_rec_xe(db, r.acurr2_id)
        r.curr2_id = xe_rec.curr_id
        r.update_record()

    db.clients_balances.truncate()
    db.clients_trans.truncate()

    db.currs_stats.truncate()
    for r in db(db.xcurrs_stats).select():
        abbrev = db.xcurrs[r.xcurr_id].abbrev
        curr, x, e = db_common.get_currs_by_abbrev(db, abbrev)
        db.currs_stats.insert(
            curr_id=curr.id,
            deal_id=r.deal_id,
            average=r.average,
            count=r.count,
        )

    return 'Done'
Exemple #12
0
def curr_get_info():
    import time
    time.sleep(1)

    curr_abbrev = request.args(0)
    if not curr_abbrev:
        return {"error": "empty curr - example: curr_get_info/btc"}
    curr_abbrev = curr_abbrev.upper()
    from db_common import get_currs_by_abbrev
    curr, xcurr, e = get_currs_by_abbrev(db, curr_abbrev)
    if not xcurr:
        return {"error": "invalid curr: " + curr_abbrev}

    token_system = None
    token_key = xcurr.as_token
    if token_key:
        token = db.tokens[token_key]
        token_system = db.systems[token.system_id]
    if token_system and token_system.name == 'Erachain':
        # UESE tokenSystem
        import rpc_erachain
        res = rpc_erachain.get_info(token_system.connect_url)
        res = {
            'height':
            res,
            'balances':
            rpc_erachain.get_balances(token_system.connect_url,
                                      token_system.account),
            'from_block':
            token_system.from_block
        }
    else:
        from crypto_client import conn
        try:
            conn = conn(curr, xcurr)
            #return {'error': '%s' % conn}
        except:
            conn = None
        if not conn:
            return {
                'error':
                'Connection to ' + curr_abbrev + ' wallet is lost. Try later'
            }
        #print conn
        try:
            #getblockchaininfo, getnetworkinfo, and getwalletinfo
            #res = conn.getinfo()
            res = conn.getnetworkinfo()
            #res = conn.getblockchaininfo()
            #res = conn.getwalletinfo() (!!!!) - дает ключи?
        #except Exception as e:
        except Exception, e:
            return {
                'error':
                'Connection to ' + curr_abbrev +
                ' wallet raise error [%s]. Try later' % e
            }
Exemple #13
0
def get_average_rate_bsa(db, in_id, out_id, expired=None):
    if in_id == out_id: return 1, 1, 1
    # берем в расчет только недавние цены
    expired = expired or datetime.datetime.now() - datetime.timedelta(
        0, RATES_TIME)

    b, s, avg = get_average_rate_bsa_2(db, in_id, out_id, expired)
    if b and s:
        b, s = add_tax(db, in_id, out_id, b, s)
        return b, s, avg

    # иначе попробуем взять через кросскурс
    xcurr_in = db(db.xcurrs.curr_id == in_id).select().first()
    if xcurr_in:
        # это криптовалюта ее через кросскурс к биткоину
        cross1, x, e = db_common.get_currs_by_abbrev(db, 'BTC')
    else:
        # это фиат - ее через кроссурс к доллару
        cross1, x, e = db_common.get_currs_by_abbrev(db, 'USD')
    b1, s1, avg1 = get_average_rate_bsa_2(db, in_id, cross1.id, expired)
    #print 'b1,s1,avg1 -> cross1', b1,s1,avg1

    xcurr_out = db(db.xcurrs.curr_id == out_id).select().first()
    if xcurr_out:
        # это криптовалюта ее через кросскурс к биткоину
        cross2, x, e = db_common.get_currs_by_abbrev(db, 'BTC')
    else:
        # это фиат - ее через кроссурс к доллару
        cross2, x, e = db_common.get_currs_by_abbrev(db, 'USD')
    b2, s2, avg2 = get_average_rate_bsa_2(db, cross2.id, out_id, expired)
    #print 'cross2 -> b2,s2,avg2', b2,s2,avg2

    if b1 and s1 and b2 and s2:
        # нашли кросскурс
        # незабудем взять курс между USD <-> BTC
        b3, s3, avg3 = get_average_rate_bsa_2(db, cross1.id, cross2.id,
                                              expired)
        if not avg3:
            # курс между долларом и биткоином не найден
            return None, None, None
        #print 'cross1 -> cross2 b3,s3,avg3', cross1.abbrev, cross2.abbrev, b3,s3,avg3
        b, s = add_tax(db, in_id, out_id, b1 * b2 * b3, s1 * s2 * s3)
        return b, s, avg1 * avg2 * avg3
    return None, None, None
Exemple #14
0
def get_rate():
    if len(request.args) < 2:
        mess = 'len(request.args)==0 - [pay_in]/[pay_out]/[amo]'
        print mess
        return mess
    import rates_lib
    import db_common
    curr_in, x, e = db_common.get_currs_by_abbrev(db, request.args[0])
    curr_out, x, e = db_common.get_currs_by_abbrev(db, request.args[1])
    amo = float(len(request.args) > 2 and request.args[2] or 1) / 10
    res = ''
    for i in range(1, 4):
        amo = amo * 10
        amo_out, rate_order, rate = rates_lib.get_rate(db, curr_in, curr_out,
                                                       amo)
        res = res + '%s[%s] -> %s[%s] x%s /%s <br>' % (
            amo, curr_in.abbrev, amo_out, curr_out.abbrev, rate,
            rate and 1 / rate or 0)
    return res
Exemple #15
0
def send_to_many():
    import db_common
    import crypto_client
    curr, xcurr, ecurr = db_common.get_currs_by_abbrev(db, request.args[0])
    if not curr or not xcurr: raise HTTP(503, 'ERROR: xcurr [%s] not found' % request.args[0] )

    if not request.vars or len(request.vars)==0: HTTP(500, 'list ={}' )

    res = crypto_client.send_to_many(curr, xcurr, request.vars)
    print res
    return '%s' % res
Exemple #16
0
def get_pow_rate_par(db, curr_in, curr_out, rate_rev, expired):
    if curr_in.id == curr_out.id: return [100000, 0]

    rate_par = get_pow_rate_par_1(db, curr_in, curr_out, rate_rev)
    if rate_par:
        return rate_par

    # иначе попробуем взять через кросскурс
    xcurr1 = db(db.xcurrs.curr_id == curr_in.id).select().first()
    if xcurr1:
        # это криптовалюта ее через кросскурс к биткоину
        cross1, x, e = db_common.get_currs_by_abbrev(db, 'BTC')
    else:
        # это фиат ее через кросскурс к доллару
        cross1, x, e = db_common.get_currs_by_abbrev(db, 'USD')

    pr_b1, pr_s, pr_avg = get_average_rate_bsa(db, curr_in.id, cross1.id,
                                               expired)
    rate_par1 = get_pow_rate_par_1(db, curr_in, cross1, pr_b1)
    #print 'rate_par1:',rate_par1, pr_b1

    xcurr2 = db(db.xcurrs.curr_id == curr_out.id).select().first()
    if xcurr2:
        # это криптовалюта ее через кросскурс к биткоину
        cross2, x, e = db_common.get_currs_by_abbrev(db, 'BTC')
    else:
        # это фиат ее через кросскурс к доллару
        cross2, x, e = db_common.get_currs_by_abbrev(db, 'USD')
    pr_b2, pr_s, pr_avg = get_average_rate_bsa(db, cross2.id, curr_out.id,
                                               expired)
    rate_par2 = get_pow_rate_par_1(db, cross2, curr_out,
                                   pr_b2)  # курс для <-БТС берем
    #print 'rate_par2:',rate_par2, pr_b2

    if rate_par1 and rate_par2:
        # нашли кросскурс
        pr_b3, pr_s, pr_avg = get_average_rate_bsa(db, cross1.id, cross2.id,
                                                   expired)
        rate_par3 = get_pow_rate_par_1(db, cross1, cross2, pr_b3)
        #return [(rate_par1[0]*rate_par2[0]*rate_par3[0]/pr_b1/pr_b2/pr_b3)**0.5, rate_par1[1]+rate_par2[1]+rate_par3[1]]
        return [rate_par1[0], rate_par1[1] + rate_par2[1] + rate_par3[1]]
Exemple #17
0
def all_blocks():
    session.forget(response)
    return

    curr, xcurr, _ = db_common.get_currs_by_abbrev(db, 'CLR')
    dd = 10
    while dd > 0:
        dd = dd - 1
        print '\n', dd, datetime.datetime.now()
        xcurr.update_record(from_block=xcurr.from_block + 1)
        db.commit()
        sleep(interval)
Exemple #18
0
def  get_reserve():
    if len(request.args) == 0:
        mess = 'len(request.args)==0'
        print mess
        return mess
    #import db_client
    import db_common
    import crypto_client
    curr, xcurr, e = db_common.get_currs_by_abbrev(db,request.args[0])
    if not xcurr: return 'xcurr not found'
    cn = crypto_client.conn(curr, xcurr)
    if not cn: return 'xcurr not connected'
    return crypto_client.get_reserve(curr, xcurr, cn) or 'None'
Exemple #19
0
def addrs():
    if not request.args(0): return '/EMC/[addr]'
    curr, xcurr, e = db_common.get_currs_by_abbrev(db, request.args(0))
    if not xcurr: return 'xcurr not found'
    cn = crypto_client.conn(curr, xcurr)
    if not cn: return 'xcurr not connected'

    res = {}
    addr = request.args(1)
    if True or addr:
        #res = {'addr': addr , 'res': cn.getreceivedbyaddress(addr) }
        res1 = cn.listaddressgroupings()
        res = {}
        i = 1
        cnt = cnt1 = 0
        for rr in res1:
            #res ['k%s' % i ] = r
            i += 1
            j = 1
            for r in rr:
                cnt += 1
                res['i%s-j%s' % (i, j)] = r
                j += 1
                # r = [addr, amo, acc]
                #print r
                if len(r) > 2:
                    cnt1 += 1
        res['1all'] = cnt
        res['1used'] = cnt1
    else:
        #res = cn.listreceivedbyaddress(0, True) # accs only
        #res = cn.listreceivedbyaccount(0, True)
        #res = cn.listaddress(0)
        #res = cn.listaccounts()
        #res = cn.getaddressesbyaccount('.main.')
        #res = cn.listtransactions('', 10, 0)

        # с минусом - это то что было отправлено комуто на их адрес !
        # а наш адрес в предыдущей транз смтреть
        # походу тут выдает с минусом только выходы на чужие адреса
        res1 = cn.listtransactions('', 3333, 0)
        res = []
        for k in res1:
            amo = Decimal(k['amount'])
            if amo >= 0:
                k['1getreceivedbyaddress'] = cn.getreceivedbyaddress(
                    k['address'], 0)
                k['1getaccount'] = cn.getaccount(k['address'])
                res.append(k)

    return BEAUTIFY(res)
Exemple #20
0
def get_pow_rate_par(db, curr_in, curr_out, rate_rev, expired):
    #print curr_in.abbrev, '->>', curr_out.abbrev
    rate_par = get_pow_rate_par_1(db, curr_in, curr_out, rate_rev)
    #print rate_par
    if rate_par:
        return rate_par

    # попробуем крос курс BTC
    btc, x, e = db_common.get_currs_by_abbrev(db, 'BTC')
    pr_b1, pr_s, pr_avg = get_average_rate_bsa(db, curr_in.id, btc.id, expired)
    rate_par1 = get_pow_rate_par_1(db, curr_in, btc,
                                   pr_b1)  # курс для ->БТС берем
    #print 'rate_par1:',rate_par1, pr_b1
    pr_b2, pr_s, pr_avg = get_average_rate_bsa(db, btc.id, curr_out.id,
                                               expired)
    rate_par2 = get_pow_rate_par_1(db, btc, curr_out,
                                   pr_b2)  # курс для <-БТС берем
    #print 'rate_par2:',rate_par2, pr_b2
    if rate_par1 and rate_par2:
        # нашли кросскурс
        return [(rate_par1[0] * rate_par2[0] / pr_b1)**0.5,
                rate_par1[1] + rate_par2[1]]

    # попробуем крос курс USD
    btc, x, e = db_common.get_currs_by_abbrev(db, 'USD')
    pr_b1, pr_s, pr_avg = get_average_rate_bsa(db, curr_in.id, btc.id, expired)
    rate_par1 = get_pow_rate_par_1(db, curr_in, btc,
                                   pr_b1)  # курс для ->БТС берем
    #print 'rate_par1:',rate_par1, pr_b1
    pr_b2, pr_s, pr_avg = get_average_rate_bsa(db, btc.id, curr_out.id,
                                               expired)
    rate_par2 = get_pow_rate_par_1(db, btc, curr_out,
                                   pr_b2)  # курс для <-БТС берем
    #print 'rate_par2:',rate_par2, pr_b2
    if rate_par1 and rate_par2:
        # нашли кросскурс
        return [(rate_par1[0] * rate_par2[0] / pr_b1)**0.5,
                rate_par1[1] + rate_par2[1]]
Exemple #21
0
def parse_mess(mess):
    args = mess.strip().split(':')
    #print args
    import db_common
    curr_out, xcurr_out, e = db_common.get_currs_by_abbrev(db, args[0].strip())
    if xcurr_out:
        if len(args) > 1:
            addr = args[1].strip()
            return curr_out.name + ':' + addr
        else:
            token_key = xcurr_out.as_token
            if token_key:
                token = db.tokens[token_key]
                token_system = db.systems[token.system_id]
                return curr_out.name + ':' + 'as RECIPIENT'
Exemple #22
0
def edealer_acc_min():
    if len(request.args) == 0: return 'edealer_acc_min/edealer/amo'
    dealer = db.dealers[request.args(0) or 1]
    if not dealer: return 'dealer not found'
    vol = int(request.args(1) or 333)
    # берем только рубль
    import db_common, ed_common
    curr, x, ecurr = db_common.get_currs_by_abbrev(db,"RUB")
    import ed_common
    dealer_acc = ed_common.sel_acc_min(db, dealer, ecurr, vol)
    h = DIV(
        H3(dealer.name),' <- ', vol,
        BEAUTIFY(dealer_acc),
    )
    return dict(h = h)
Exemple #23
0
def tx_info():
    session.forget(response)

    txid = request.args(1)
    if not txid:
        return {'error': "need txid: /tx_info.json/[curr]/[txid]"}
    curr_abbrev = request.args(0)
    import db_common
    curr, xcurr, e = db_common.get_currs_by_abbrev(db, curr_abbrev)
    if not xcurr:
        return {"error": "invalid curr:  /tx_info.json/[curr]/[txid]"}
    import crypto_client
    conn = crypto_client.conn(curr, xcurr)
    if not conn:
        return {"error": "not connected to wallet"}
    res = crypto_client.get_tx_info(conn, txid, request.vars)
    return res
Exemple #24
0
def tx_senders():
    time.sleep(1)
    txid = request.args(1)
    if not txid:
        #raise HTTP(501, {"error": "empty pars"})
        return {'error': "need txid: /tx_senders.json/[curr]/[txid]"}
    curr_abbrev = request.args(0).upper()
    from db_common import get_currs_by_abbrev
    curr, xcurr, e = get_currs_by_abbrev(db, curr_abbrev)
    if not xcurr:
        return {"error": "invalid curr"}
    from crypto_client import conn
    conn = conn(curr, xcurr)
    if not conn:
        return {"error": "not connected to wallet"}
    res = dict(result=crypto_client.sender_addrs(conn, txid))
    return res
Exemple #25
0
def tx():
    if request.extension == 'html':
        response.view = 'blockchain/res.html'

    txid = request.args(1)
    if not txid:
        return {'error': "need txid: /tx_info.json/[curr]/[txid]"}
    curr_abbrev = request.args(0)
    import db_common
    curr, xcurr, e = db_common.get_currs_by_abbrev(db, curr_abbrev)
    if not xcurr:
        return {"error": "invalid curr:  /tx_info.json/[curr]/[txid]"}

    sleep(1)

    token_system = conn = None
    token_key = xcurr.as_token
    if token_key:
        token = db.tokens[token_key]
        token_system = db.systems[token.system_id]
        res = dict(result=crypto_client.get_tx_info(conn, token_system, txid))
        return res

    conn = crypto_client.conn(curr, xcurr)
    if not conn:
        return {"error": "not connected to wallet"}
    res = None
    try:
        res = conn.getrawtransaction(txid, 1)  # все выдает
    except Exception as e:
        return {'error': e}

    if 'hex' in res: res.pop('hex')
    txid = res.get('txid')
    if txid:
        res['txid'] = A(txid, _href=URL('tx', args=[request.args(0), txid]))
    for inp in res.get('vin', []):
        if 'scriptSig' in inp: inp.pop('scriptSig')
        txid = inp.get('txid')
        if txid:
            inp['txid'] = A(txid,
                            _href=URL('tx', args=[request.args(0), txid]))
        else:
            pass
        pass
    return res
Exemple #26
0
def get_unspents():
    if len(request.args) == 0:
        mess = 'len(request.args)==0'
        print mess
        return mess
    #import db_client
    import db_common
    import crypto_client
    curr, x, e = db_common.get_currs_by_abbrev(db,request.args[0])
    if not x: return 'xcurr not found'
    cn = crypto_client.conn(curr,x)
    if not cn: return 'xcurr not connected'
    vol = None
    conf = len(request.args)>1 and int(request.args[1]) or None
    tab, summ = crypto_client.get_unspents(cn, conf, vol)
    print tab, summ
    return '%s <br>%s' % (summ, BEAUTIFY(tab))
def parse_mess(db, mess, creator):

    if not mess:
        return None

    args = mess.strip().split('\n')[0].split(':')
    print 'parse_mess:', mess, args

    import db_common

    arg1 = args[0].strip()
    if len(arg1) < 20:
        # as ABBREV
        curr_out, xcurr_out, _ = db_common.get_currs_by_abbrev(db, arg1)
        if xcurr_out:
            if len(args) > 1:
                addr = args[1].strip()
                if addr[0] == '[':
                    addr = addr[1:]
                if addr[-1] == ']':
                    addr = addr[:-1]
                return curr_out.abbrev + ':' + addr
            else:
                return curr_out.abbrev + ':' + creator

    # may be here only ADDRESS
    if len(arg1) > 30:
        from db_common import get_currs_by_addr
        curr_out, xcurr_out, _ = get_currs_by_addr(db, arg1)
        if xcurr_out:
            return curr_out.abbrev + ':' + arg1

    try:
        token_id = int(arg1)
        if len(args) > 1:
            addr = args[1].strip()
            if addr[0] == '[':
                addr = addr[1:]
            if addr[-1] == ']':
                addr = addr[:-1]
            return arg1 + ':' + addr
        else:
            return arg1 + ':' + creator
    except:
        pass
Exemple #28
0
def pay_test():
    session.forget(response)
    import db_common
    import ed_common
    scid = request.vars.get('pattern_id')
    curr, xcurr, ecurr= db_common.get_currs_by_abbrev(db,'RUB')
    dealer_deal = db((db.dealer_deals.scid==scid)
            & (db.dealer_deals.dealer_id==dealer.id)).select().first()
    deal = db.deals[dealer_deal.deal_id]
    print deal.name
    dealer, dealer_acc, d_ = ed_common.select_ed_acc(db, deal, ecurr)
    print dealer_acc.acc, dealer_acc.balance
    vol = float(request.vars.get('sum') or request.vars.get('redsum') or 13)

    acc = '---???---'
    res = ed_common.pay_test(db, deal, dealer, dealer_acc, dealer_deal, acc, vol, True, request.vars)
    print res
    return BEAUTIFY(res)
Exemple #29
0
def tx_info():
    time.sleep(1)

    txid = request.args(1)
    if not txid:
        return {'error': "need txid: /tx_info.json/[curr]/[txid]"}
    curr_abbrev = request.args(0).upper()
    from db_common import get_currs_by_abbrev
    curr, xcurr, e = get_currs_by_abbrev(db, curr_abbrev)
    if not xcurr:
        return {"error": "invalid curr: " + curr_abbrev}
    from crypto_client import conn
    conn = conn(curr, xcurr)
    if not conn:
        return {
            'error':
            'Connection to ' + curr_abbrev + ' wallet is lost. Try later'
        }
    from crypto_client import get_tx_info
    res = get_tx_info(conn, txid, request.vars)
    return res
Exemple #30
0
def curr_get_info():
    import time
    time.sleep(1)

    curr_abbrev = request.args(0)
    if not curr_abbrev:
        return {"error": "empty curr - example: curr_get_info/btc"}
    curr_abbrev = curr_abbrev.upper()
    #from applications.shop.modules.db_common import get_currs_by_abbrev
    from db_common import get_currs_by_abbrev
    curr, xcurr, e = get_currs_by_abbrev(db, curr_abbrev)
    if not xcurr:
        return {"error": "invalid curr: " + curr_abbrev}
    from crypto_client import conn
    conn = conn(curr, xcurr)
    if not conn:
        return {
            'error':
            'Connection to ' + curr_abbrev + ' wallet is lost. Try later'
        }
    res = conn.getinfo()
    return res