Exemplo n.º 1
0
    def _handle_withdrawals(self):
        session = Session()

        plugin_name = __name__.split('.')[1]
        my_currency_ids = [
            c for c, p in currencies.items() if p == plugin_name
        ]

        pending_withdrawals = session.query(Withdrawal).filter_by(
            currency=my_currency_ids[0],
            accepted=True,
            executed=False,
            rejected=False)
        for withdrawal in pending_withdrawals:
            account = session.query(Account).filter_by(
                address=withdrawal.address).first()
            logger.info("New withdrawal: %s %s" % (account, withdrawal))
            withdrawal.executed = True
            session.commit()
            session.flush()
            real_amount = withdrawal.amount - dogecoin_withdrawal_fee * (
                10**self.DOGECOIN_DECIMAL_PLACES)
            withdrawal.dogecoin_txid = send_dogecoin(
                withdrawal.dogecoin_address, real_amount)
            session.commit()
            session.flush()

        session.commit()
Exemplo n.º 2
0
    def _handle_deposits(self):
        session = Session()

        plugin_name = __name__.split('.')[1]
        my_currency_ids = [
            c for c, p in currencies.items() if p == plugin_name
        ]

        # TODO: List unconfirmed deposits
        for transaction in get_last_transactions():
            if transaction['category'] == 'receive' and transaction[
                    'confirmations'] >= dogecoin_confirmations:
                account = session.query(Account).filter_by(
                    dogecoin_deposit_address=transaction['address']).first()
                if account is not None:
                    deposit = session.query(Deposit).filter_by(
                        dogecoin_txid=transaction['txid']).first()
                    if deposit is None:
                        real_amount = transaction['amount']
                        if real_amount <= 0:
                            amount = 0
                        amount = int(real_amount *
                                     (10**self.DOGECOIN_DECIMAL_PLACES))
                        deposit = Deposit(account.address, my_currency_ids[0],
                                          amount)
                        deposit.dogecoin_txid = transaction['txid']
                        deposit.accepted = True
                        logger.info("New deposit: %s %s" % (account, deposit))
                        session.add(deposit)
                        session.commit()
                        session.flush()

        session.commit()
Exemplo n.º 3
0
    def _handle_withdrawals(self):
        session = Session()

        # TODO: Optimize this query to use relations
        pending_withdrawals = session.query(Withdrawal).filter_by(
            accepted=False, executed=False, rejected=False)
        for withdrawal in pending_withdrawals:
            transaction = session.query(BlockchainTransaction).filter_by(
                attachment=withdrawal.attachment).first()
            if transaction is not None:
                withdrawal.accept(transaction)
                session.commit()
                session.flush()
        session.commit()
        session.flush()
Exemplo n.º 4
0
    def _handle_withdrawals(self):
        session = Session()

        # TODO: API for this
        plugin_name = __name__.split('.')[1]
        my_currency_ids = [c for c, p in currencies.items() if p == plugin_name]

        # TODO: Create a cutesy API for plugin creators
        print("asdfasdfasdfadsf")
        withdrawals = session.query(Withdrawal).filter_by(accepted=True, executed=False, rejected=False).filter(
            Withdrawal.currency.in_(my_currency_ids))
        for withdrawal in withdrawals:
            logger.info("Executing withdrawal %s" % withdrawal)
            withdrawal.executed = True
            session.commit()
            self.bank_sim.send_money(session, withdrawal.bank_account, withdrawal.amount)
            session.commit()
            session.flush()

        session.commit()
Exemplo n.º 5
0
    def _handle_deposits(self):
        session = Session()

        pending_deposits = session.query(Deposit).filter_by(accepted=True,
                                                            executed=False,
                                                            rejected=False)
        for deposit in pending_deposits:
            logger.info("Handling deposit %s" % deposit)
            # TODO: Double verify deposits [check for amount of confirmations] ???
            # TODO: Use two phased transactions here to protect against two WavesManagers running at once

            deposit.executed = True
            session.commit()
            deposit.waves_transaction_id = send_currency(
                deposit.currency, deposit.address, deposit.amount)
            session.commit()
            session.flush()
            # Send 0.1 Waves for transaction fees if the client has less than 0.01
            if get_waves_balance(deposit.address) < 1000000:
                send_currency(None, deposit.address, 10000000)

        session.commit()
        session.flush()