Esempio n. 1
0
    async def f(session_data, *args, **kwargs):
        """get wallet by session.public_key"""
        pk = session_data.public_key
        try:
            wallet = await objects.get(Wallet.select().where(Wallet.source == pk))
        except Wallet.DoesNotExist:
            try:
                wallet = await objects.get(Wallet.select().join(MultisigInfo).where(MultisigInfo.source == pk))
            except Wallet.DoesNotExist:
                raise web.HTTPBadRequest(reason="No wallet assigned to your key")

        return await func(session_data, wallet, *args, **kwargs)
Esempio n. 2
0
def CreateWalletEndpoint(session, data):
    check_wallet_schema(data)
    pk = session.public_key
    invite_code = generate_random_string(48)

    if Wallet.select().where(Wallet.source == pk).exists():
        raise APIError("Shared wallet linked with your key is already exists", 409)

    level = data['participants'] - data['signers']

    device_uid = data.get('device_uid')
    wallet = Wallet.create(
        name=data['name'],
        signers=data['signers'],
        participants=data['participants'],
        invite_code=invite_code,
        level=level,
        source=pk)

    MultisigInfo.create(
        wallet=wallet.id,
        info=data['multisig_info'],
        level=0,
        device_uid=device_uid,
        source=pk)

    return jsonify({"invite_code": wallet.invite_code})
Esempio n. 3
0
def ExistsWalletInfoEndpoint():
    pk = request.args.get('public_key')
    wallet = Wallet.select().join(MultisigInfo).where(
        (Wallet.source == pk) | (Wallet.multisig_source == pk)
        | (MultisigInfo.source == pk)
        | (MultisigInfo.multisig_source == pk)).first()

    if not wallet:
        raise APIError("Wallet not found", status_code=404)

    return get_wallet_scheme(wallet)
Esempio n. 4
0
    def f(session_data, *args, **kwargs):
        """get wallet by session.public_key"""
        pk = session_data.public_key
        wallet = Wallet.select().join(MultisigInfo).where(
            (Wallet.source == pk) | (Wallet.multisig_source == pk)
            | (MultisigInfo.source == pk)
            | (MultisigInfo.multisig_source == pk)).first()

        if not wallet:
            raise APIError("No wallet assigned to your key", status_code=400)
        return func(session_data, wallet, *args, **kwargs)
Esempio n. 5
0
def _update_balances(ctx: CallbackContext):
    wallets_to_update = Wallet.select() \
        .where(Wallet.updated_dt <= (datetime.utcnow() - timedelta(seconds=5))) \
        .limit(100) \
        .order_by(Wallet.updated_dt.asc())
    wallets = {w.address: w for w in wallets_to_update}
    # info(pformat(wallets))
    addresses = list(wallets.keys())

    chunk_size = 10
    address_chunks = [[a for a in addresses[i:i + chunk_size]]
                      for i in range(0, len(addresses), chunk_size)]

    notify_users = {}
    for chunk in address_chunks:
        response = batch_check_balances(chunk)
        try:
            data = response['data']
        except Exception as e:
            msg_err = '\n{et}\n{e}\n{response}'
            info(msg_err.format(et=type(e), e=e, response=pformat(response)))
            continue

        for item in data:
            address = item['address']
            w = wallets[address]
            w.updated_dt = datetime.utcnow()
            # info(f'Updating address {address} of user {w.user.first_name}')
            for balance in item['balances']:
                coin = balance['coin']
                # temp
                if coin != 'BIP':
                    continue
                amount = round(float(balance['amount']), 4)
                delta = round(amount - float(w.balance), 4)
                w.balance = amount
                if delta <= 0:
                    continue
                notify_users[w] = TOP_UP_MSG_TMPL.format(coin=coin,
                                                         amount=delta)
            w.save()

    for w, msg in notify_users.items():
        ctx.bot.send_message(w.user.telegram_id,
                             msg,
                             parse_mode=ParseMode.HTML)
Esempio n. 6
0
def CreateWalletEndpointV2(session, data):
    check_wallet_schema(data)
    pk = session.public_key
    invite_code = generate_random_string(48)

    if Wallet.select().where(Wallet.source == pk).exists():
        raise APIError("Shared wallet linked with your key is already exists", 409)

    level = data['participants'] - data['signers']

    wallet = Wallet.create(
        signers=data['signers'],
        participants=data['participants'],
        invite_code=invite_code,
        supported_protocols=','.join(data['supported_protocols']),
        level=level,
        source=pk,
    )

    return jsonify({"invite_code": wallet.invite_code})