import time import hashlib import lib.settings as settings import lib.logger log = lib.logger.get_logger('DB_Mysql') import MySQLdb import DB_Mysql class DB_Mysql_Vardiff(DB_Mysql.DB_Mysql): def __init__(self): DB_Mysql.DB_Mysql.__init__(self) def import_shares(self, data): # Data layout # 0: worker_name, # 1: block_header, # 2: block_hash, # 3: difficulty, # 4: timestamp, # 5: is_valid, # 6: ip, # 7: self.block_height, # 8: self.prev_hash, # 9: invalid_reason, # 10: share_diff log.debug("Importing Shares") checkin_times = {} total_shares = 0 best_diff = 0 log.debug(data) for k, v in enumerate(data): # for database compatibility we are converting our_worker to Y/N format if v[5]: v[5] = 'Y' else: v[5] = 'N' self.execute( """ INSERT INTO `shares` (time, rem_host, username, our_result, upstream_result, reason, solution, difficulty) VALUES (FROM_UNIXTIME(%(time)s), %(host)s, %(uname)s, %(lres)s, %(result)s, %(reason)s, %(solution)s, %(difficulty)s) """, { "time": v[4], "host": v[6], "uname": v[0], "lres": v[5], "result": v[5], "reason": v[9], "solution": v[2], "difficulty": v[3] } ) self.dbh.commit() def update_worker_diff(self, username, diff): log.debug("Setting difficulty for %s to %s", username, diff) self.execute( """ UPDATE `pool_worker` SET `difficulty` = %(diff)s WHERE `username` = %(uname)s """, { "uname": username, "diff": diff } ) self.dbh.commit() def clear_worker_diff(self): log.debug("Resetting difficulty for all workers") self.execute( """ UPDATE `pool_worker` SET `difficulty` = 0 """ ) self.dbh.commit()