Ejemplo n.º 1
0
def btc_cash_sendCointoUser_asAdmin(amount, comment, userid):
    """
    #TO User
    ##this function will move the coin from agoras wallet_btc to a user as an admin
    :param amount:
    :param comment:
    :param userid:
    :return:
    """
    try:
        type_transaction = 9

        userswallet = btccash_Wallet.query.filter_by(userid=userid).first()
        curbal = Decimal(userswallet.currentbalance)
        amounttomod = Decimal(amount)
        newbalance = Decimal(curbal) + Decimal(amounttomod)
        userswallet.currentbalance = newbalance
        db.session.add(userswallet)
        db.session.commit()

        btc_cash_addtransaction(category=type_transaction,
                                amount=amount,
                                userid=userid,
                                comment=comment,
                                shard=userswallet.shard,
                                orderid=0,
                                balance=newbalance
                                )
    except Exception as e:
        print(str(e))
        errorLogger(function='sendcointouser', error=e, kindoferror=4, user=userid)
        db.session.rollback()
Ejemplo n.º 2
0
def createWallet(userid):
    """
    THIS function creates the wallet_btc and puts its first address there
    :param userid:
    :return:
    """
    try:
        type_transaction = 1
        user = db.session.query(User).filter(User.id == userid).first()
        timestamp = datetime.utcnow()

        wallet = BtcWalletWork(userid=userid,
                               type=type_transaction,
                               amount=0,
                               sendto=0,
                               comment=0,
                               created=timestamp,
                               txtcomment='',
                               shard=user.shard)
        db.session.add(wallet)
        db.session.commit()

    except Exception as e:
        errorLogger(function='createWallet',
                    error=e,
                    kindoferror=4,
                    user=userid)
        db.session.rollback()
Ejemplo n.º 3
0
def sendCointoHoldings(amount, userid, comment):
    """
    # TO Agora
    # this function will move the coin from vendor to agora holdings.  This is for vendor verification
    :param amount:
    :param userid:
    :param comment:
    :return:
    """
    a = checkbalance(userid=userid, amount=amount)
    if a == 1:
        try:
            type_transaction = 7
            now = datetime.utcnow()

            user = db.session.query(User).filter(User.id == userid).first()
            userswallet = BtcWallet.query.filter_by(userid=userid).first()
            curbal = Decimal(userswallet.currentbalance)
            amounttomod = floating_decimals(amount, 8)
            newbalance = floating_decimals(curbal, 8) - floating_decimals(
                amounttomod, 8)
            userswallet.currentbalance = newbalance
            db.session.add(userswallet)
            db.session.commit()

            c = str(comment)
            a = Decimal(amount)
            commentstring = "Vendor Verification: Level " + c
            addtransaction(category=type_transaction,
                           amount=amount,
                           userid=user.id,
                           comment=commentstring,
                           shard=user.shard,
                           orderid=0,
                           balance=newbalance)

            getcurrentholdings = db.session.query(Agoraholdings).order_by(
                Agoraholdings.id.desc()).first()
            currentamount = floating_decimals(getcurrentholdings.total, 8)
            newamount = floating_decimals(currentamount,
                                          8) + floating_decimals(a, 8)
            holdingsaccount = Agoraholdings(amount=a,
                                            timestamp=now,
                                            userid=userid,
                                            total=newamount)
            db.session.add(holdingsaccount)
            db.session.commit()

        except Exception as e:
            print(str(e))
            errorLogger(function='sendcointoholdings',
                        error=e,
                        kindoferror=4,
                        user=userid)
            db.session.rollback()
    else:
        pass
Ejemplo n.º 4
0
def btc_cash_sendCoinfromHoldings(amount, userid, comment):
    """
    # TO Agora
    # this function will move the coin from holdings back to vendor.  This is for vendor verification
    :param amount:
    :param userid:
    :param comment:
    :return:
    """
    try:
        type_transaction = 8
        now = datetime.utcnow()
        user = db.session.query(User).filter(User.id == userid).first()
        userswallet = btccash_Wallet.query.filter_by(userid=userid).first()
        curbal = Decimal(userswallet.currentbalance)
        amounttomod = Decimal(amount)
        newbalance = Decimal(curbal) + Decimal(amounttomod)
        userswallet.currentbalance = newbalance

        db.session.add(userswallet)
        db.session.commit()

        c = str(comment)
        a = Decimal(amount)
        commentstring = "Vendor Verification Refund: Level " + c

        btc_cash_addtransaction(category=type_transaction,
                                amount=amount,
                                userid=user.id,
                                comment=commentstring,
                                shard=user.shard_btccash,
                                orderid=0,
                                balance=newbalance
                                )

        getcurrentholdings = db.session.query(Agoraholdings_btccash).order_by(Agoraholdings_btccash.id.desc()).first()
        currentamount = floating_decimals(getcurrentholdings.total, 8)
        newamount = floating_decimals(currentamount, 8) - floating_decimals(a, 8)

        holdingsaccount = Agoraholdings_btccash(
            amount=a,
            timestamp=now,
            userid=userid,
            total=newamount
        )
        db.session.add(holdingsaccount)
        db.session.commit()

    except Exception as e:
        print(str(e))
        errorLogger(function='sendcoinfromholdings', error=e, kindoferror=4, user=userid)
        db.session.rollback()
Ejemplo n.º 5
0
def takeCointoUser_asAdmin(amount, comment, userid):
    """
    # TO User
    # this function will move the coin from agoras wallet_btc to a user as an admin
    :param amount:
    :param comment:
    :param userid:
    :return:
    """
    try:
        type_transaction = 10
        a = Decimal(amount)
        userswallet = BtcWallet.query.filter_by(userid=userid).first()
        curbal = Decimal(userswallet.currentbalance)
        amounttomod = Decimal(amount)
        newbalance = Decimal(curbal) - Decimal(amounttomod)
        userswallet.currentbalance = newbalance
        db.session.add(userswallet)
        db.session.commit()

        addtransaction(category=type_transaction,
                       amount=amount,
                       userid=userid,
                       comment=comment,
                       shard=userswallet.shard,
                       orderid=0,
                       balance=newbalance)

        getcurrentprofit = db.session.query(Agoraprofit).order_by(
            Agoraprofit.id.desc()).first()
        currentamount = floating_decimals(getcurrentprofit.total, 8)
        newamount = floating_decimals(currentamount, 8) + floating_decimals(
            a, 8)
        prof = Agoraprofit(amount=amount,
                           timestamp=datetime.utcnow(),
                           total=newamount)
        db.session.add(prof)
        db.session.commit()

    except Exception as e:
        print(str(e))
        errorLogger(function='sendcointouser',
                    error=e,
                    kindoferror=4,
                    user=userid)
        db.session.rollback()
Ejemplo n.º 6
0
def btc_cash_sendCointoAgora(amount, comment, shard):
    """
    # TO Agora
    # this function will move the coin from agoras escrow to profit account
    # no balance necessary
    :param amount:
    :param comment:
    :param shard:
    :return:
    """
    try:
        type_transaction = 6
        now = datetime.utcnow()
        oid = int(comment)
        a = Decimal(amount)
        btc_cash_addtransaction(
            category=type_transaction,
            amount=amount,
            userid=1,
            comment='Sent Coin to Agora profit',
            shard=shard,
            orderid=oid,
            balance=0
        )

        getcurrentprofit = db.session.query(Agoraprofit_btccash).order_by(Agoraprofit_btccash.id.desc()).first()
        currentamount = floating_decimals(getcurrentprofit.total, 8)
        newamount = floating_decimals(currentamount, 8) + floating_decimals(a, 8)
        prof = Agoraprofit_btccash(
            amount=amount,
            order=oid,
            timestamp=now,
            total=newamount
        )
        db.session.add(prof)
        db.session.commit()

    except Exception as e:
        print(str(e))
        errorLogger(function='sendcointoagora', error=e, kindoferror=4, user=1)
        db.session.rollback()
Ejemplo n.º 7
0
def sendCointoEscrow(amount, comment, userid):
    """
    #TO Agora Wallet
    ##this function will move the coin to agoras wallet_btc from a user
    :param amount:
    :param comment:
    :param userid:
    :return:
    """
    a = checkbalance(userid=userid, amount=amount)
    if a == 1:
        try:
            type_transaction = 4
            userswallet = BtcWallet.query.filter_by(userid=userid).first()
            curbal = Decimal(userswallet.currentbalance)
            amounttomod = Decimal(amount)
            newbalance = Decimal(curbal) - Decimal(amounttomod)
            userswallet.currentbalance = newbalance
            db.session.add(userswallet)
            db.session.commit()

            oid = int(comment)

            addtransaction(category=type_transaction,
                           amount=amount,
                           userid=userid,
                           comment='Sent Coin To Escrow',
                           shard=userswallet.shard,
                           orderid=oid,
                           balance=newbalance)
        except Exception as e:
            errorLogger(function='sendcointoescrow',
                        error=e,
                        kindoferror=4,
                        user=userid)
            # find order and cancel it
            order = db.session.query(Orders).filter(
                Orders.id == comment).first()
            # change the order status
            order.disputed_order = 0
            order.cancelled = 1
            order.completed = 1
            order.buyorsell = 1
            order.released = 1
            order.completed_time = datetime.utcnow()
            db.session.add(order)
            db.session.commit()
    else:
        order = db.session.query(Orders).filter(Orders.id == comment).first()
        # change the order status
        # change the order status
        order.disputed_order = 0
        order.cancelled = 1
        order.completed = 1
        order.buyorsell = 1
        order.released = 1
        order.completed_time = datetime.utcnow()
        db.session.add(order)
        db.session.commit()

        notification(type=34,
                     username='',
                     userid=userid,
                     salenumber=comment,
                     bitcoin=amount)