Exemple #1
0
def getblocktemplate(wallet_address):
    stub = get_mining_stub()
    request = qrlmining_pb2.GetBlockToMineReq(
        wallet_address=wallet_address.encode())
    grpc_response = stub.GetBlockToMine(request=request, timeout=10)
    resp = {
        'blocktemplate_blob': grpc_response.blocktemplate_blob,
        'difficulty': grpc_response.difficulty,
        'height': grpc_response.height,
        'status': 'OK'
    }

    return resp
Exemple #2
0
    def test_GetBlockToMine(self):
        blocktemplate_blob = b'blob'
        difficulty = 100
        self.qrlnode.get_block_to_mine = MagicMock(
            return_value=(blocktemplate_blob, difficulty))

        req = qrlmining_pb2.GetBlockToMineReq(wallet_address=b'fake address')
        answer = self.service.GetBlockToMine(request=req, context=None)

        self.assertEqual(answer.height, 1)
        self.assertEqual(answer.reserved_offset, config.dev.extra_nonce_offset)

        # What happens if QRLNode could not generate a blocktemplate? Then the response should be blank.
        self.qrlnode.get_block_to_mine.return_value = None
        answer = self.service.GetBlockToMine(request=req, context=None)
        self.assertEqual('', answer.blocktemplate_blob)
        self.assertEqual(0, answer.height)
        self.assertEqual(0, answer.reserved_offset)
        self.assertEqual(0, answer.difficulty)