예제 #1
0
def check_balance(user_or_wallet):
    w = Wallet.get(user=user_or_wallet) if isinstance(user_or_wallet, Users) \
        else user_or_wallet if isinstance(user_or_wallet, Wallet) \
        else Wallet.get(address=user_or_wallet)
    if not w:
        return
    r = api.get_balance(w.address)
    balance = float(
        MinterConvertor.convert_value(r['result']['balance']['BIP'], 'bip'))
    w.balance = balance
    w.updated_dt = datetime.utcnow()
    w.save()
    return balance
예제 #2
0
def add_transaction(user):
    wallets = user.wallets
    for wallet in wallets:
        print(wallet.id, wallet.name, wallet.balance)

    ch = int(input("Choose a Wallet ID: "))

    wallet = Wallet.get(Wallet.id == ch)
    is_expense = int(input("Choose Type:\n0. Income\n1.Expense"))

    if not is_expense:
        from_person = input("From Who: ")
    else:
        from_person = "None"

    tranx_name = input("Enter Purpose: ")
    amount = float(input("Enter Amount: "))
    comment = input("Any comments? \n")

    Transaction.create(owner=user,
                       wallet=wallet,
                       name=tranx_name,
                       amount=amount,
                       comment=comment,
                       from_person=from_person,
                       timestamp=datetime.now(),
                       is_expense=bool(is_expense))
예제 #3
0
def BasicWalletInfoEndpoint():
    invite_code = request.args.get('invite_code')
    try:
        wallet = Wallet.get(invite_code=invite_code)
    except Wallet.DoesNotExist:
        raise APIError("Wallet not found", status_code=404)

    return get_wallet_scheme(wallet)
예제 #4
0
def JoinWalletEndpoint(session, data):
    pk = session.public_key
    try:
        wallet = Wallet.get(invite_code=data['invite_code'])
    except Wallet.DoesNotExist:
        raise APIError("Wallet not found", status_code=404)

    device_uid = data.get('device_uid')
    if device_uid is not None:
        if MultisigInfo.select().where((MultisigInfo.device_uid == device_uid) &
                                   (MultisigInfo.wallet_id == wallet.id)).exists():
            raise APIError("Already joined", status_code=409)

    if not wallet.is_new:
        try:
            multisig = MultisigInfo.get(source=pk)
        except MultisigInfo.DoesNotExist:
            raise APIError("Wallet is already fulfilled", status_code=409)

        return ('', 200)

    (info, created) = MultisigInfo.get_or_create(
        wallet=wallet.id,
        source=pk,
        level=0,
        device_uid=device_uid,
        defaults={"info": data['multisig_info']})

    if not created:
        info.info = data['multisig_info']
        info.save()

    app.redis.publish("stream:wallet_info:%s" % wallet.id, wallet.status)
    data2 = {
        'wallet_id': wallet.id,
        'public_key': pk,
        'status': wallet.status,
        'changed_keys': len(wallet.changed_keys),
        'joined': len(wallet.multisig_infos),
        'participants': wallet.participants,
        'signers': wallet.signers,
        'event': 'joined'
    }
    app.redis.publish("stream:wallet_info", json.dumps(data2))

    if wallet.multisig_infos.count() >= wallet.participants:
        if wallet.level > 0:
            wallet.status = "fulfilled"
        else:
            wallet.status = "changing_keys"
        wallet.save()

        app.redis.publish("stream:multisig_info:%s" % wallet.id, "complete")
        data2 = {
            "wallet_id": wallet.id,
            "public_key": pk,
            "multisig_infos": [{"multisig_info": x.info} for x in wallet.multisig_infos],
            "event": "completed"
        }
        app.redis.publish("stream:multisig_info", json.dumps(data2))

    return ('', 204)