async def get(self, request): logging.debug('transaction result') args = request.raw_args tx_hash = args['hash'] verify_result = dict() if utils.is_hex(tx_hash): logging.debug('tx_hash : ' + tx_hash) channel_name = get_channel_name_from_args(args) grpc_response = PeerServiceStub().get_invoke_result( channel=channel_name, tx_hash=tx_hash) verify_result['response_code'] = str(grpc_response.response_code) if len(grpc_response.result) is not 0: try: result = json.loads(grpc_response.result) result['jsonrpc'] = '2.0' verify_result['response'] = result except json.JSONDecodeError as e: logging.warning("your data is not json, your data(" + str(grpc_response.data) + ")") verify_result['response_code'] = str( message_code.Response.fail.value) else: verify_result['response_code'] = str( message_code.Response.fail.value) else: verify_result['response_code'] = str( message_code.Response.fail_validate_params.value) verify_result['message'] = "Invalid transaction hash." return response.json(verify_result)
async def get(self, request): args = request.raw_args channel = get_channel_name_from_args(args) block_data = dict() if 'hash' in args: block_hash = args['hash'] if utils.is_hex(block_hash): grpc_response = PeerServiceStub().get_block( channel=channel, block_hash=block_hash) logging.debug(f"response : {grpc_response}") block_data['block_hash'] = grpc_response.block_hash block_data['block_data_json'] = json.loads( grpc_response.block_data_json) if len(grpc_response.tx_data_json) < 1: block_data['tx_data_json'] = '' else: tx_data = list() tx_json_data = grpc_response.tx_data_json for i in range(0, len(tx_json_data)): tx_data.append(json.loads(tx_json_data[i])) block_data['tx_data_json'] = json.loads( json.dumps(tx_data)) else: block_data['response_code'] = str( message_code.Response.fail_validate_params.value) block_data['message'] = "Invalid transaction hash." else: block_hash = PeerServiceStub().get_last_block_hash(channel=channel) grpc_response = PeerServiceStub().get_block(channel=channel, block_hash=block_hash) logging.debug(f"response : {grpc_response}") block_data['response_code'] = grpc_response.response_code block_data['block_hash'] = grpc_response.block_hash block_data['block_data_json'] = json.loads( grpc_response.block_data_json) return response.json(block_data)
async def get(self, request): status = HTTPStatus.OK result = PeerServiceStub().get_status( get_channel_name_from_args(request.raw_args)) # parse result and set HTTPStatus error while service is not avail. # util.logger.spam(f"result({result['status']})") if result['status'] != "Service is online: 0": status = HTTPStatus.SERVICE_UNAVAILABLE return response.json(result, status=status)
async def get(self, request): return response.json(PeerServiceStub().get_status( get_channel_name_from_args(request.raw_args)))
def get_transaction(self, tx_hash, channel): return PeerServiceStub().call( "GetTx", loopchain_pb2.GetTxRequest(tx_hash=tx_hash, channel=channel), PeerServiceStub.REST_GRPC_TIMEOUT)
def create_transaction(self, data, channel): # logging.debug("Grpc Create Tx Data : " + data) return PeerServiceStub().call( "CreateTx", loopchain_pb2.CreateTxRequest(data=data, channel=channel), PeerServiceStub.REST_GRPC_TIMEOUT)
def query(self, data, channel): return PeerServiceStub().call( "Query", loopchain_pb2.QueryRequest(params=data, channel=channel), PeerServiceStub.REST_SCORE_QUERY_TIMEOUT)