示例#1
0
文件: icx.py 项目: ssdred1250/iconnex
    async def icx_getTransactionResult(**kwargs):
        channel = kwargs['context']['channel']
        request = convert_params(kwargs, ParamType.get_tx_request)
        channel_stub = StubCollection().channel_stubs[channel]
        verify_result = dict()

        tx_hash = request["txHash"]
        response_code, result = await channel_stub.async_task().get_invoke_result(tx_hash)

        if response_code == message_code.Response.fail_tx_not_invoked:
            raise GenericJsonRpcServerError(
                code=JsonError.INVALID_PARAMS,
                message=message_code.responseCodeMap[response_code][1],
                http_status=status.HTTP_BAD_REQUEST
            )
        elif response_code == message_code.Response.fail_invalid_key_error or \
                response_code == message_code.Response.fail:
            raise GenericJsonRpcServerError(
                code=JsonError.INVALID_PARAMS,
                message='Invalid params txHash',
                http_status=status.HTTP_BAD_REQUEST
            )

        if result:
            try:
                result_dict = json.loads(result)
                verify_result = result_dict
            except json.JSONDecodeError as e:
                Logger.warning(f"your result is not json, result({result}), {e}")

        response = convert_params(verify_result, ParamType.get_tx_result_response)
        return response
示例#2
0
文件: icx.py 项目: ssdred1250/iconnex
    async def icx_getBlockByHeight(**kwargs):
        channel = kwargs['context']['channel']
        request = convert_params(kwargs, ParamType.get_block_by_height_request)
        block_hash, result = await get_block_by_params(block_height=request['height'],
                                                       channel_name=channel)
        response_code = result['response_code']
        if response_code != message_code.Response.success:
            raise GenericJsonRpcServerError(
                code=JsonError.INVALID_PARAMS,
                message=message_code.responseCodeMap[response_code][1],
                http_status=status.HTTP_BAD_REQUEST
            )

        response = convert_params(result['block'], ParamType.get_block_response)
        return response
示例#3
0
文件: icx.py 项目: ssdred1250/iconnex
    async def icx_sendTransaction(**kwargs):
        channel = kwargs['context']['channel']
        url = kwargs['context']['url']
        path = urlparse(url).path
        del kwargs['context']

        method = 'icx_sendTransaction'
        request = make_request(method, kwargs)
        score_stub = get_icon_stub_by_channel_name(channel)
        icon_stub = score_stub
        response = await icon_stub.async_task().validate_transaction(request)
        # Error Check
        response_to_json_query(response)

        channel_tx_creator_stub = StubCollection().channel_tx_creator_stubs[channel]
        response_code, tx_hash = await channel_tx_creator_stub.async_task().create_icx_tx(kwargs)

        if response_code == message_code.Response.fail_no_permission:
            return await IcxDispatcher.__relay_icx_transaction(url, path, kwargs)

        if response_code != message_code.Response.success:
            raise GenericJsonRpcServerError(
                code=JsonError.INVALID_REQUEST,
                message=message_code.responseCodeMap[response_code][1],
                http_status=message_code.get_response_http_status_code(response_code, status.HTTP_BAD_REQUEST)
            )

        if tx_hash is None:
            raise GenericJsonRpcServerError(
                code=JsonError.INVALID_REQUEST,
                message='txHash is None',
                http_status=status.HTTP_BAD_REQUEST
            )

        return convert_params(tx_hash, ParamType.send_tx_response)
示例#4
0
文件: icx.py 项目: ssdred1250/iconnex
    async def icx_getLastBlock(**kwargs):
        channel = kwargs['context']['channel']

        block_hash, result = await get_block_by_params(block_height=-1,
                                                       channel_name=channel)
        response = convert_params(result['block'], ParamType.get_block_response)

        return response_to_json_query(response)
示例#5
0
 async def node_getBlockByHeight(**kwargs):
     channel = kwargs['context']['channel']
     request = convert_params(kwargs, ParamType.get_block_by_height_request)
     block_hash, response = await get_block_by_params(
         channel_name=channel,
         block_height=request['height'],
         with_commit_state=True)
     return response
示例#6
0
 async def node_GetBlockByHeight(**kwargs):
     try:
         channel = kwargs['context']['channel']
         del kwargs['context']
         channel = channel if channel is not None else kwargs.get('channel', None)
     except KeyError:
         channel = kwargs.get("channel", None)
     request = convert_params(kwargs, ParamType.get_block_by_height_request)
     block_hash, response = await get_block_by_params(channel_name=channel, block_height=request['height'],
                                                      with_commit_state=True)
     return response
示例#7
0
文件: icx.py 项目: ssdred1250/iconnex
    async def icx_getTransactionByHash(**kwargs):
        channel = kwargs['context']['channel']
        request = convert_params(kwargs, ParamType.get_tx_request)
        channel_stub = StubCollection().channel_stubs[channel]

        response_code, tx_info = await channel_stub.async_task().get_tx_info(request["txHash"])
        if response_code == message_code.Response.fail_invalid_key_error:
            raise GenericJsonRpcServerError(
                code=JsonError.INVALID_PARAMS,
                message='Invalid params txHash',
                http_status=status.HTTP_BAD_REQUEST
            )

        result = tx_info["transaction"]
        result['txHash'] = request['txHash']
        result["txIndex"] = tx_info["tx_index"]
        result["blockHeight"] = tx_info["block_height"]
        result["blockHash"] = tx_info["block_hash"]

        response = convert_params(result, ParamType.get_tx_by_hash_response)
        return response
示例#8
0
    async def icx_sendTransaction(**kwargs):
        channel = kwargs['context']['channel']
        url = kwargs['context']['url']
        path = urlparse(url).path
        del kwargs['context']

        if RestProperty().node_type == NodeType.CitizenNode:
            dispatch_protocol = IcxDispatcher.get_dispatch_protocol_from_url(
                url)
            Logger.debug(f'Dispatch Protocol: {dispatch_protocol}')
            redirect_protocol = StubCollection().conf.get(
                ConfigKey.REDIRECT_PROTOCOL)
            Logger.debug(f'Redirect Protocol: {redirect_protocol}')
            if redirect_protocol:
                dispatch_protocol = redirect_protocol
            Logger.debug(f'Protocol: {dispatch_protocol}')

            return await redirect_request_to_rs(dispatch_protocol,
                                                kwargs,
                                                RestProperty().rs_target,
                                                path=path[1:])

        method = 'icx_sendTransaction'
        request = make_request(method, kwargs)
        score_stub = get_icon_stub_by_channel_name(channel)
        icon_stub = score_stub
        response = await icon_stub.async_task().validate_transaction(request)
        # Error Check
        response_to_json_query(response)

        channel_tx_creator_stub = StubCollection(
        ).channel_tx_creator_stubs[channel]
        response_code, tx_hash = await channel_tx_creator_stub.async_task(
        ).create_icx_tx(kwargs)

        if response_code != message_code.Response.success:
            raise GenericJsonRpcServerError(
                code=JsonError.INVALID_REQUEST,
                message=message_code.responseCodeMap[response_code][1],
                http_status=status.HTTP_BAD_REQUEST)

        if tx_hash is None:
            raise GenericJsonRpcServerError(
                code=JsonError.INVALID_REQUEST,
                message='txHash is None',
                http_status=status.HTTP_BAD_REQUEST)

        return convert_params(tx_hash, ParamType.send_tx_response)