Exemplo n.º 1
0
def pools(miner: Miner):
    '''Gets the current pool for the miner'''
    def sort_by_priority(j):
        return j['Priority']

    try:
        api = MinerApi(host=miner.ipaddress, port=int(miner.port))
        jstatuspools = api.pools()
        if jstatuspools['STATUS'][0]['STATUS'] == 'error':
            if not miner.is_disabled():
                raise MinerMonitorException(
                    jstatuspools['STATUS'][0]['description'])
        else:
            jpools = jstatuspools["POOLS"]
            #sort by priority
            jpools.sort(key=sort_by_priority)
            #try to do elegant way, but not working
            #cPool = namedtuple('Pool', 'POOL, URL, Status,Priority,Quota,Getworks,Accepted,Rejected,Long Poll')
            #colpools = [cPool(**k) for k in jsonpools["POOLS"]]
            #for pool in colpools:
            #    print(pool.POOL)
            for pool in jpools:
                if str(pool["Status"]) == "Alive":
                    currentpool = pool["URL"]
                    currentworker = pool["User"]
                    #print("{0} {1} {2} {3} {4} {5}".format(pool["POOL"],pool["Priority"],pool["URL"],pool["User"],pool["Status"],pool["Stratum Active"]))
                    break
            minerpool = MinerCurrentPool(miner, currentpool, currentworker,
                                         jstatuspools)
            return minerpool
    except BaseException as ex:
        print('Failed to call miner pools api: ' + str(ex))
    return None
Exemplo n.º 2
0
 def getpool(self, miner: Miner):
     '''get pool from cache'''
     valu = self.trygetvaluefromcache(miner.name + '.pool')
     if valu is None: return None
     entity = MinerCurrentPool(miner, **self.deserialize(MinerCurrentPoolSchema(), valu))
     #entity.Miner = miner
     return entity
Exemplo n.º 3
0
    def test_minerserialization(self):
        sch = MinerSchema()
        miner = Miner('test')
        miner.status = MinerStatus.Offline
        miner.status = MinerStatus.Online
        miner.minerinfo = MinerInfo('Antminer S9', '123')
        miner.minerpool = MinerCurrentPool(miner,
                                           'test pool',
                                           'test worker',
                                           allpools={})
        miner.minerpool.poolname = 'unittest'
        miner.minerstats = MinerStatistics(miner, datetime.datetime.utcnow(),
                                           0, 1, 0, 99, 98, 97, 123, '', '',
                                           '')
        miner.minerstats.boardstatus1 = 'o'
        miner.minerstats.boardstatus2 = 'oo'
        miner.minerstats.boardstatus3 = 'ooo'
        jminer = sch.dumps(miner).data

        #rehydrate miner
        reminer = MinerSchema().loads(jminer).data
        self.assertTrue(isinstance(reminer.minerinfo, MinerInfo))
        self.assertTrue(isinstance(reminer.minerpool, MinerCurrentPool))
        self.assertTrue(reminer.minerpool.poolname == 'unittest')
        self.assertTrue(isinstance(reminer.minerstats, MinerStatistics))
        self.assertTrue(reminer.laststatuschanged)
        self.assertTrue(reminer.minerstats.boardstatus1 == 'o')
        self.assertTrue(reminer.minerstats.boardstatus2 == 'oo')
        self.assertTrue(reminer.minerstats.boardstatus3 == 'ooo')
Exemplo n.º 4
0
 def test_miner_monitored_pool(self):
     miner = Miner('test')
     stats = domain.minerstatistics.MinerStatistics(miner)
     miner.monitored(stats,
                     pool=MinerCurrentPool(miner),
                     info=None,
                     sec=None)
     self.assertTrue(miner.minerpool)
Exemplo n.º 5
0
 def getpool(self, miner: Miner):
     '''get pool from cache'''
     if not self.cache:
         return None
     valu = self.cache.trygetvaluefromcache(miner.name + '.pool')
     if valu is None:
         return None
     entity = MinerCurrentPool(
         miner, **utils.deserialize(MinerCurrentPoolSchema(), valu))
     return entity
Exemplo n.º 6
0
 def test_miner_currentpoolname(self):
     miner = Miner('test')
     self.assertTrue(miner.currentpoolname() == '?')
     miner.minerpool = MinerCurrentPool(miner,
                                        'test pool',
                                        'test worker',
                                        allpools={},
                                        poolname='unit test')
     self.assertTrue(miner.currentpoolname() == 'unit test')
     self.assertFalse(
         miner.minerpool.findpoolnumberforpool('test pool', 'test worker'))
Exemplo n.º 7
0
 def test_minermessage(self):
     sch = messaging.messages.MinerMessageSchema()
     entity = messaging.messages.MinerMessage(self.make_miner())
     entity.command = MinerCommand('test', 'test')
     entity.minerpool = MinerCurrentPool(entity.miner,
                                         'test pool',
                                         'test worker',
                                         allpools={})
     entity.minerstats = domain.minerstatistics.MinerStatistics(
         entity.miner, datetime.datetime.utcnow(), 0, 1, 0, 99, 98, 97, 123,
         '', '', '')
     j = sch.dumps(entity).data
     reentity = sch.loads(j).data
     self.assertTrue(isinstance(reentity, messaging.messages.MinerMessage))
Exemplo n.º 8
0
 def test_miner_pools_available(self):
     miner = Miner('test')
     self.assertTrue(miner.pools_available is None)
     miner.minerpool = MinerCurrentPool(miner,
                                        'test pool',
                                        'test worker',
                                        allpools={})
     self.assertTrue(len(miner.pools_available) == 0)
     miner.minerpool.allpools = {
         "POOLS": [{
             "Pool Stale%": 0,
             "Accepted": 421743,
             "Difficulty Stale": 0,
             "Stratum URL": "test",
             "Rejected": 85,
             "Difficulty Accepted": 6587318272,
             "Best Share": 4019408192,
             "User": "******",
             "Stratum Active": True,
             "Difficulty Rejected": 1343488,
             "Diff": "16.4K",
             "Remote Failures": 3,
             "Discarded": 1094132,
             "Long Poll": "N",
             "Proxy": "",
             "Priority": 0,
             "Has GBT": False,
             "Pool Rejected%": 0.0204,
             "Stale": 63,
             "Last Share Difficulty": 16384,
             "Diff1 Shares": 0,
             "Has Stratum": True,
             "Status": "Alive",
             "URL": "test",
             "Quota": 1,
             "Last Share Time": "0:00:05",
             "Getworks": 70163,
             "Get Failures": 3,
             "POOL": 3,
             "Proxy Type": ""
         }]
     }
     self.assertTrue(len(miner.pools_available) > 0)
     self.assertTrue(miner.minerpool.findpoolnumberforpool('test', 'test'))
     self.assertFalse(miner.minerpool.findpoolnumberforpool('not', 'found'))
Exemplo n.º 9
0
    def test_minerserialization(self):
        sch = messaging.messages.MinerSchema()
        miner = self.make_miner()
        miner.status = MinerStatus.Offline
        miner.status = MinerStatus.Online
        miner.minerinfo = MinerInfo('Antminer S9', '123')
        miner.minerpool = MinerCurrentPool(miner,
                                           'test pool',
                                           'test worker',
                                           allpools={})
        miner.minerpool.poolname = 'unittest'
        miner.minerstats = domain.minerstatistics.MinerStatistics(
            miner, datetime.datetime.utcnow(), 0, 1, 0, 99, 98, 97, 123, '',
            '', '')
        miner.minerstats.boardstatus1 = 'o'
        miner.minerstats.boardstatus2 = 'oo'
        miner.minerstats.boardstatus3 = 'ooo'
        miner.minerstats.hardware_errors = 123
        miner.minerstats.hash_avg = 13000
        miner.location = 'unittest'
        miner.in_service_date = datetime.datetime.today().replace(
            microsecond=0)
        jminer = sch.dumps(miner).data

        #rehydrate miner
        reminer = messaging.messages.MinerSchema().loads(jminer).data
        self.assertTrue(reminer.customerid == miner.customerid)
        self.assertTrue(isinstance(reminer.minerinfo, MinerInfo))
        self.assertTrue(isinstance(reminer.minerpool, MinerCurrentPool))
        self.assertTrue(reminer.minerpool.poolname == 'unittest')
        self.assertTrue(
            isinstance(reminer.minerstats,
                       domain.minerstatistics.MinerStatistics))
        self.assertTrue(reminer.laststatuschanged)
        self.assertTrue(reminer.minerstats.boardstatus1 == 'o')
        self.assertTrue(reminer.minerstats.boardstatus2 == 'oo')
        self.assertTrue(reminer.minerstats.boardstatus3 == 'ooo')
        self.assertTrue(reminer.minerstats.hardware_errors == 123)
        self.assertTrue(reminer.minerstats.hash_avg == 13000)
        self.assertTrue(reminer.location == miner.location)
        self.assertTrue(reminer.in_service_date == miner.in_service_date)
Exemplo n.º 10
0
def parse_minerpool(miner, jstatuspools):
    def sort_by_priority(j):
        return j['Priority']

    jpools = jstatuspools["POOLS"]
    #sort by priority
    jpools.sort(key=sort_by_priority)
    #try to do elegant way, but not working
    #cPool = namedtuple('Pool', 'POOL, URL, Status,Priority,Quota,Getworks,Accepted,Rejected,Long Poll')
    #colpools = [cPool(**k) for k in jsonpools["POOLS"]]
    #for pool in colpools:
    #    print(pool.POOL)
    for pool in jpools:
        if str(pool["Status"]) == "Alive":
            currentpool = pool["URL"]
            currentworker = pool["User"]
            #print("{0} {1} {2} {3} {4} {5}".format(pool["POOL"],pool["Priority"],pool["URL"],pool["User"],pool["Status"],pool["Stratum Active"]))
            break
    minerpool = MinerCurrentPool(miner, currentpool, currentworker,
                                 jstatuspools)
    return minerpool
Exemplo n.º 11
0
 def make(self, data):
     onlyparams = {x: data[x] for x in data if x not in {'poolname'}}
     minerpool = MinerCurrentPool(miner=None, **onlyparams)
     if 'poolname' in data:
         minerpool.poolname = data['poolname']
     return minerpool