示例#1
0
    def handleWork(self, work, pushed=False):

        if work is None:
            return

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

        if 'block' in work:
            try:
                block = int(work['block'])
            except (TypeError, ValueError):
                pass
            else:
                if self.block != block:
                    self.block = block
                    self.runCallback('block', block)

        aw = AssignedWork()
        aw.data = work['data'].decode('hex')[:80]
        aw.target = work['target'].decode('hex')
        aw.mask = work.get('mask', 32)
        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
 def _processResponse(self, body, push):
     """Handle an unparsed JSON-RPC response, either from getwork() or
     longpoll.
     """
     
     result = self._parseJSONResult(body)
     if result is None:
         return
     
     try:
         aw = AssignedWork()
         aw.data = result['data'].decode('hex')[:80]
         aw.mask = result.get('mask', 32)
         aw.target = result['target'].decode('hex')
         self._success()
         if push:
             self.runCallback('push', aw)
         else:
             self.requesting = False
         self.runCallback('work', aw)
     except (TypeError, KeyError):
         self._failure()
示例#4
0
        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)