コード例 #1
0
ファイル: makePayouts.py プロジェクト: zhuk2303/grin-pool
def main():
    global LOGGER
    global CONFIG
    CONFIG = lib.get_config()
    LOGGER = lib.get_logger(PROCESS)
    LOGGER.warn("=== Starting {}".format(PROCESS))

    # Connect to DB
    database = lib.get_db()
    # Configs
    minimum_payout = int(CONFIG[PROCESS]["minimum_payout"])
    walletauth = (wallet_api_user, wallet_api_key)

    utxos = Pool_utxo.getPayable(minimum_payout)

    # XXX TODO: Use the current balance, timestamp, the last_attempt timestamp, last_payout, and failed_attempts
    # XXX TODO: to filter and sort by order we want to make payment attempts
    for utxo in utxos:
        try:
            # Try less often for wallets that dont answer
            if utxo.amount < utxo.failure_count:
                if randint(0, 11) != 0:
                    continue
            LOGGER.warn(
                "Processing utxo for: {} {} {} using method: {}".format(
                    utxo.user_id, utxo.address, utxo.amount, utxo.method))
            if utxo.method in ["http", "https", "keybase"]:
                try:
                    #user_id,      address,      logger, database, wallet_auth, method,     invoked_by
                    payments.atomic_send(utxo.user_id, utxo.address, LOGGER,
                                         database, walletauth, utxo.method,
                                         "schedule")
                except payments.PaymentError as e:
                    LOGGER.error("Failed to make http payment: {}".format(e))
            else:
                LOGGER.warn(
                    "Automatic payment does not (yet?) support method: {}".
                    format(utxo.method))

        except Exception as e:
            LOGGER.error("Failed to process utxo: {} because {}".format(
                utxo.user_id, str(e)))
            database.db.getSession().rollback()
            sys.exit(1)

    LOGGER.warn("=== Completed {}".format(PROCESS))
コード例 #2
0
ファイル: testdb.py プロジェクト: smith7800/grin-pool
from grinbase.constants.MysqlConstants import MysqlConstants
from grinbase.dbaccess import database
from grinbase.dbaccess.database import database_details
from grinbase.model.pool_utxo import Pool_utxo

if __name__ == '__main__':
    database.db = database_details(MYSQL_CONSTANTS=MysqlConstants())
    database.db.initialize()

#    for i in range(0,10):
#        tmp = Pool_utxo(id=str(i), address=str(i), amount=1.5*i)
#        database.db.createDataObj(tmp)


    utxo = Pool_utxo.getPayable(0)[0]
    print(utxo)
    locked_utxo = Pool_utxo.get_locked_by_id(utxo.id)
    print(locked_utxo)
    locked_utxo.amount=1.0
    database.db.getSession().begin_nested();
    locked_utxo.amount=7.0
    database.db.getSession().commit()
    database.db.getSession().commit()

    utxo = Pool_utxo.getPayable(0)[0]
    print(utxo)


#    for utxo in Pool_utxo.getPayable(0):
#        Pool_utxo.get_locked_by_id(utxo.id)
コード例 #3
0
def main():
    global LOGGER
    global CONFIG
    CONFIG = lib.get_config()
    LOGGER = lib.get_logger(PROCESS)
    LOGGER.warn("=== Starting {}".format(PROCESS))

    # Connect to DB
    try:
        database = lib.get_db()
    except Exception as e:
        LOGGER.error("Failed to connect to the db: {}".format(e))

    wallet_dir = CONFIG[PROCESS]["wallet_dir"]
    minimum_payout = int(CONFIG[PROCESS]["minimum_payout"])
    os.chdir(wallet_dir)
    utxos = Pool_utxo.getPayable(minimum_payout)
    database.db.getSession().commit()
    # XXX TODO: Use the current balance, timestamp, the last_attempt timestamp, last_payout, and failed_attempts
    # XXX TODO: to filter and sort by order we want to make payment attempts
    for utxo in utxos:
        try:
            # Try less often for wallets that dont answer
            if utxo.amount < utxo.failure_count:
                if randint(0, 11) != 0:
                    continue
            LOGGER.warn("Trying to pay: {} {} {}".format(utxo.id, utxo.address, utxo.amount))
            # Lock just this current record for update
            locked_utxo = Pool_utxo.get_locked_by_id(utxo.id)
            # Save and Zero the balance
            original_balance = locked_utxo.amount
            locked_utxo.amount = 0
            # Savepoint changes - if we crash after sending coins but before commit we roll back to here.
            #   The pool audit service (coming soon) finds lost payouts and restores user balance
            database.db.getSession().begin_nested();
            # Attempt to make the payment
            timestamp = datetime.utcnow()
            status =  makePayout(locked_utxo.address, original_balance)
            LOGGER.warn("Payout status: {}".format(status))
            if status == 0:
                LOGGER.warn("Made payout for {} {} {} at {}".format(locked_utxo.id, locked_utxo.address, original_balance, timestamp))
                # Create a payment record
                payment_record = Pool_payment(locked_utxo.id, timestamp, locked_utxo.address, original_balance, 0, locked_utxo.failure_count, "schedule" )
                database.db.getSession().add(payment_record)
                # Update timestamp of last payout, number of failed payout attempts
                locked_utxo.amount = 0
                locked_utxo.failure_count = 0
                locked_utxo.last_try = timestamp
                locked_utxo.last_success = timestamp
                locked_utxo.total_amount += original_balance
                # Commit changes
                database.db.getSession().commit() 
            else:
                LOGGER.error("Failed to make payout: {} {} {}".format(locked_utxo.id, locked_utxo.address, original_balance))
                # Restore the users balance 
                locked_utxo.amount = original_balance
                # Update number of failed payout attempts
                if locked_utxo.failure_count is None:
                    locked_utxo.failure_count = 0
                locked_utxo.failure_count += 1
                locked_utxo.last_try = timestamp
                # Commit changes
                database.db.getSession().commit()
            database.db.getSession().commit()

        except Exception as e:
            LOGGER.error("Failed to process utxo: {} because {}".format(utxo.id, str(e)))
            database.db.getSession().rollback()
            sys.exit(1)

    LOGGER.warn("=== Completed {}".format(PROCESS))
コード例 #4
0
ファイル: makePayouts.py プロジェクト: permaetheus/grin-pool
def main():
    global LOGGER
    global CONFIG
    CONFIG = lib.get_config()
    LOGGER = lib.get_logger(PROCESS)
    LOGGER.warn("=== Starting {}".format(PROCESS))

    # DB connection details
    db_host = CONFIG["db"]["address"] + ":" + CONFIG["db"]["port"]
    db_user = CONFIG["db"]["user"]
    db_password = CONFIG["db"]["password"]
    db_name = CONFIG["db"]["db_name"]
    mysqlcontsraints = MysqlConstants(db_host, db_user, db_password, db_name)

    # Connect to DB
    database.db = database_details(MYSQL_CONSTANTS=mysqlcontsraints)
    database.db.initialize()

    wallet_dir = CONFIG[PROCESS]["wallet_dir"]
    minimum_payout = int(CONFIG[PROCESS]["minimum_payout"])
    os.chdir(wallet_dir)
    utxos = Pool_utxo.getPayable(minimum_payout)
    database.db.getSession().commit()
    # XXX TODO: Use the current balance, timestamp, the last_attempt timestamp, last_payout, and failed_attempts
    # XXX TODO: to filter and sort by order we want to make payment attempts
    for utxo in utxos:
        try:
            LOGGER.warn("Trying to pay: {} {} {}".format(
                utxo.id, utxo.address, utxo.amount))
            # Lock just this current record for update
            locked_utxo = Pool_utxo.get_locked_by_id(utxo.id)
            # Save and Zero the balance
            original_balance = locked_utxo.amount
            locked_utxo.amount = 0
            # Savepoint changes - if we crash after sending coins but before commit we roll back to here.
            #   The pool audit service finds lost payouts and restores user balance
            database.db.getSession().begin_nested()
            # Attempt to make the payment
            timestamp = "{:%B %d, %Y %H:%M:%S.%f}".format(datetime.now())
            status = makePayout(locked_utxo.address, original_balance)
            LOGGER.warn("Payout status: {}".format(status))
            if status == 0:
                LOGGER.warn("Made payout for {} {} {}".format(
                    locked_utxo.id, locked_utxo.address, original_balance))
                # Update timestamp of last payout, number of failed payout attempts
                locked_utxo.amount = 0
                locked_utxo.failure_count = 0
                locked_utxo.last_try = timestamp
                locked_utxo.last_success = timestamp
                # Commit changes
                database.db.getSession().commit()
            else:
                LOGGER.error("Failed to make payout: {} {} {}".format(
                    locked_utxo.id, locked_utxo.address, original_balance))
                # Restore the users balance
                locked_utxo.amount = original_balance
                # Update number of failed payout attempts
                if locked_utxo.failure_count is None:
                    locked_utxo.failure_count = 0
                locked_utxo.failure_count += 1
                locked_utxo.last_try = timestamp
                # Commit changes
                database.db.getSession().commit()
            database.db.getSession().commit()

        except Exception as e:
            LOGGER.error("Failed to process utxo: {} because {}".format(
                utxo.id, str(e)))
            database.db.getSession().rollback()
            sys.exit(1)

    LOGGER.warn("=== Completed {}".format(PROCESS))