Пример #1
0
async def move_many(request):
    try:
        post = await web_base.content_type_json_check(request)
        ant_from = post.get('from', C.ANT_NAME_UNKNOWN)
        ant_to = post['to']
        coins = CoinObject()
        for k, v in post['coins'].items():
            coins[int(k)] += int(v)
        with closing(create_db(V.DB_ACCOUNT_PATH)) as db:
            cur = db.cursor()
            _from = read_name2user(ant_from, cur)
            _to = read_name2user(ant_to, cur)
            txhash = user_account.move_balance(_from, _to, coins, cur)
            db.commit()
        return web_base.json_res({
            'txhash': hexlify(txhash).decode(),
            'from_id': _from, 'to_id': _to})
    except Exception as e:
        return web.Response(text=str(e), status=400)
Пример #2
0
async def move_many(request):
    try:
        post = await utils.content_type_json_check(request)
        ant_from = post.get('from', C.account2name[C.ANT_UNKNOWN])
        ant_to = post['to']
        coins = Balance()
        for k, v in post['coins'].items():
            coins[int(k)] += int(v)
        with create_db(V.DB_ACCOUNT_PATH, f_strict=True) as db:
            cur = db.cursor()
            _from = read_name2userid(ant_from, cur)
            _to = read_name2userid(ant_to, cur)
            txhash = user_account.move_balance(_from, _to, coins, cur)
            db.commit()
        return utils.json_res({
            'txhash': txhash.hex(),
            'from_id': _from,
            'to_id': _to
        })
    except Exception as e:
        return web.Response(text=str(e), status=400)
Пример #3
0
async def move_one(request):
    try:
        post = await utils.content_type_json_check(request)
        ant_from = post.get('from', C.account2name[C.ANT_UNKNOWN])
        ant_to = post['to']
        coin_id = int(post.get('coin_id', 0))
        amount = int(post['amount'])
        coins = Balance(coin_id, amount)
        with create_db(V.DB_ACCOUNT_PATH, f_strict=True) as db:
            cur = db.cursor()
            _from = read_name2userid(ant_from, cur)
            _to = read_name2userid(ant_to, cur)
            txhash = user_account.move_balance(_from, _to, coins, cur)
            db.commit()
        return utils.json_res({
            'txhash': txhash.hex(),
            'from_id': _from,
            'to_id': _to
        })
    except Exception:
        return utils.error_res()