예제 #1
0
 def _handle_request(self, data: Dict) -> None:
     # only request accepted is a 'mining.notify' notification
     if data['method'] != 'mining.notify':
         self.log.warn('unknown method received', data=data)
         return
     block_templates = BlockTemplates(BlockTemplate.from_dict(d) for d in data.get('params', []))
     if self._queue.done():
         self._queue = self.loop.create_future()
     self._queue.set_result(block_templates)
예제 #2
0
 async def submit(self, block: Block) -> Optional[BlockTemplate]:
     resp: Union[bool, Dict] = await self._do_request('mining.submit', {
         'hexdata': bytes(block).hex(),
     })
     if resp:
         assert isinstance(resp, Dict)
         error = resp.get('error')
         if error:
             raise APIError(error)
         return BlockTemplate.from_dict(resp['result'])
     return None