예제 #1
0
 def GetBlock(self, request: qrl_pb2.GetBlockReq,
              context) -> qrl_pb2.GetBlockResp:
     logger.debug("[PublicAPI] GetBlock")
     block = self.qrlnode.get_block_from_hash(request.header_hash)
     if block:
         return qrl_pb2.GetBlockResp(block=block.pbdata)
     return qrl_pb2.GetBlockResp()
예제 #2
0
    def GetBlock(self, request: qrl_pb2.GetBlockReq,
                 context) -> qrl_pb2.GetBlockResp:
        response = qrl_pb2.GetBlockResp()
        response.node_info.CopyFrom(self.qrlnode.getNodeInfo())

        if request.HasField("index"):
            block = self.qrlnode.get_block_from_index(request.index)
            if isinstance(block, Block):
                response.block.CopyFrom(block.pbdata)
        else:
            raise NotImplementedError()

        return response
예제 #3
0
    def test_get_block_by_number(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()

            block = qrl_pb2.Block()
            block.header.hash_header = b'001122'
            block.header.block_number = 1

            walletd._public_stub.GetBlockByNumber = Mock(
                return_value=qrl_pb2.GetBlockResp(block=block))

            b = walletd.get_block_by_number(1)
            self.assertEqual(b.header.hash_header,
                             bin2hstr(block.header.hash_header))
            self.assertEqual(b.header.block_number, block.header.block_number)
예제 #4
0
    def test_getBlockByNumber(self):
        with set_qrl_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            block = qrl_pb2.Block()
            block.header.hash_header = b'001122'
            block.header.block_number = 1

            walletd._public_stub.GetBlockByNumber = Mock(
                return_value=qrl_pb2.GetBlockResp(block=block))

            resp = service.GetBlockByNumber(qrlwallet_pb2.BlockByNumberReq(block_number=1), context=None)

            self.assertEqual(resp.code, 0)
            self.assertEqual(resp.block.header.hash_header, bin2hstr(block.header.hash_header))
            self.assertEqual(resp.block.header.block_number, block.header.block_number)