Пример #1
0
    def handleWork(self, work, headers, pushed=False):
        if work is None:
            return

        rollntime = headers.get('x-roll-ntime')

        submitold = work.get('submitold')
        if submitold is not None:
            self.submitold = bool(submitold)

        if rollntime:
            if rollntime.lower().startswith('expire='):
                try:
                    maxtime = int(rollntime[7:])
                except:
                    #if the server supports rollntime but doesn't format the
                    #request properly, then use a sensible default
                    maxtime = self.maxtime
            else:
                if rollntime.lower() in ('t', 'true', 'on', '1', 'y', 'yes'):
                    maxtime = self.maxtime
                elif rollntime.lower() in ('f', 'false', 'off', '0', 'n',
                                           'no'):
                    maxtime = 0
                else:
                    try:
                        maxtime = int(rollntime)
                    except:
                        maxtime = self.maxtime
        else:
            maxtime = 0

        if self.maxtime < maxtime:
            maxtime = self.maxtime

        if not self.saidConnected:
            self.saidConnected = True
            self.runCallback('connect')
            self.useAskrate('askrate')

        aw = AssignedWork()
        aw.data = work['data'].decode('hex')[:80]
        aw.target = work['target'].decode('hex')
        aw.mask = work.get('mask', 32)
        aw.setMaxTimeIncrement(maxtime)
        aw.identifier = work.get('identifier', aw.data[4:36])
        if pushed:
            self.runCallback('push', aw)
        self.runCallback('work', aw)
Пример #2
0
    def handleWork(self, work, headers, pushed=False):
        if work is None:
            return;

        rollntime = headers.get('x-roll-ntime')

        submitold = work.get('submitold')
        if submitold is not None:
            self.submitold = bool(submitold)

        if rollntime:
            if rollntime.lower().startswith('expire='):
                try:
                    maxtime = int(rollntime[7:])
                except:
                    #if the server supports rollntime but doesn't format the
                    #request properly, then use a sensible default
                    maxtime = self.maxtime
            else:
                if rollntime.lower() in ('t', 'true', 'on', '1', 'y', 'yes'):
                    maxtime = self.maxtime
                elif rollntime.lower() in ('f', 'false', 'off', '0', 'n', 'no'):
                    maxtime = 0
                else:
                    try:
                        maxtime = int(rollntime)
                    except:
                        maxtime = self.maxtime
        else:
            maxtime = 0

        if self.maxtime < maxtime:
            maxtime = self.maxtime

        if not self.saidConnected:
            self.saidConnected = True
            self.runCallback('connect')
            self.useAskrate('askrate')

        aw = AssignedWork()
        aw.data = work['data'].decode('hex')[:80]
        aw.target = work['target'].decode('hex')
        aw.mask = work.get('mask', 32)
        aw.setMaxTimeIncrement(maxtime)
        aw.identifier = work.get('identifier', aw.data[4:36])
        if pushed:
            self.runCallback('push', aw)
        self.runCallback('work', aw)
Пример #3
0
        ntime = pack('>I', timestamp).encode('hex') #NOTE: must be big endian!
        hex_nonce = pack('<I', nonce).encode('hex')
        id_ = job_id + hex_nonce
        self.submits[id_] = time() #'id': id_,
        return self.send_message({'params': [self.url.username, job_id, extranonce2, ntime, hex_nonce], 'id': id_, 'method': u'mining.submit'})

    def handleWork(self, (work, extranonce2, job_id), pushed=False):
        if work is None:
            return;

        aw = AssignedWork()
        aw.data = work['data'].decode('hex')[:80] #should be 80 anyhow, but we leave it
        aw.target = work['target'].decode('hex')
        aw.mask = work.get('mask', 32) #TODO direct
        aw.setMaxTimeIncrement(self.maxtime) #This might be really important, somehow... Figure out the best setting!
        aw.identifier = work.get('identifier', aw.data[4:36]) #Wait what is this??
        aw.extranonce2 = extranonce2
        aw.job_id = job_id
        
        if pushed:
            self.runCallback('push', aw)
        self.runCallback('work', aw)

    def _failure(self):
        if self.saidConnected:
            self.saidConnected = False
            self.runCallback('disconnect')
            if self.socket_handler:
                self.socket_handler.close_when_done() #thread should stop when done?
            self.connect() #Try once more
        else:
Пример #4
0
            u'mining.submit'
        })

    def handleWork(self, (work, extranonce2, job_id), pushed=False):
        if work is None:
            return

        aw = AssignedWork()
        aw.data = work['data'].decode(
            'hex')[:80]  #should be 80 anyhow, but we leave it
        aw.target = work['target'].decode('hex')
        aw.mask = work.get('mask', 32)  #TODO direct
        aw.setMaxTimeIncrement(
            self.maxtime
        )  #This might be really important, somehow... Figure out the best setting!
        aw.identifier = work.get('identifier',
                                 aw.data[4:36])  #Wait what is this??
        aw.extranonce2 = extranonce2
        aw.job_id = job_id

        if pushed:
            self.runCallback('push', aw)
        self.runCallback('work', aw)

    def _failure(self):
        if self.saidConnected:
            self.saidConnected = False
            self.runCallback('disconnect')
            if self.socket_handler:
                self.socket_handler.close_when_done(
                )  #thread should stop when done?
            self.connect()  #Try once more