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)
async def icx_sendTransaction(**kwargs): url = kwargs['context']['url'] path = urlparse(url).path del kwargs['context'] request = make_request("icx_sendTransaction", kwargs, RequestParamType.send_tx) channel = StubCollection().conf[ConfigKey.CHANNEL] icon_stub = StubCollection().icon_score_stubs[channel] response = await icon_stub.async_task().validate_transaction(request) # Error Check response_to_json_query(response) channel_name = StubCollection().conf[ConfigKey.CHANNEL] channel_tx_creator_stub = StubCollection( ).channel_tx_creator_stubs[channel_name] response_code, tx_hash, relay_target = \ await channel_tx_creator_stub.async_task().create_icx_tx(kwargs) if response_code == message_code.Response.fail_no_permission: return await Version2Dispatcher.__relay_icx_transaction( url, path, kwargs, channel, relay_target) response_data = {'response_code': response_code} if response_code != message_code.Response.success: response_data['message'] = message_code.responseCodeMap[ response_code][1] else: response_data['tx_hash'] = tx_hash return response_data
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)
async def icx_call(context: Dict[str, str], **kwargs): channel = context.get('channel') method = 'icx_call' request = make_request(method, kwargs) score_stub = get_icon_stub_by_channel_name(channel) response = await score_stub.async_task().query(request) return response_to_json_query(response)
async def icx_getReceiptProof(context: Dict[str, str], **kwargs): channel = context.get('channel') channel_stub = get_channel_stub_by_channel_name(channel) tx_hash = kwargs['txHash'] response = await channel_stub.async_task().get_receipt_proof(tx_hash) return response_to_json_query(response)
async def icx_getBlock(context: Dict[str, str], **kwargs): channel = context.get("channel") request = convert_params(kwargs, RequestParamType.get_block) if "hash" in request: block_hash, result = await get_block_by_params( block_hash=request.get("hash"), channel_name=channel) elif "height" in request: block_hash, result = await get_block_by_params( block_height=request.get("height"), channel_name=channel, unconfirmed=request.get("unconfirmed", False)) else: block_hash, result = await get_block_by_params( block_height=-1, channel_name=channel) response_code = result['response_code'] check_response_code(response_code) block = result['block'] if block['version'] == BLOCK_v0_1a: response = convert_params(result['block'], ResponseParamType.get_block_v0_1a_tx_v3) elif block['version'] == BLOCK_v0_3: response = convert_params(result['block'], ResponseParamType.get_block_v0_3_tx_v3) else: response = block return response_to_json_query(response)
async def icx_call(**kwargs): channel = kwargs['context']['channel'] method = 'icx_call' request = make_request(method, kwargs) score_stub = get_icon_stub_by_channel_name(channel) response = await score_stub.async_task().query(request) return response_to_json_query(response)
async def debug_getAccount(context, **kwargs): channel = context.get('channel') method = "debug_getAccount" request = make_request(method, kwargs) score_stub = get_icon_stub_by_channel_name(channel) response = await score_stub.async_task().query(request) return response_to_json_query(response)
async def icx_getBlock(**kwargs): channel = kwargs['context']['channel'] request = convert_params(kwargs, RequestParamType.get_block) if all(param in request for param in ["hash", "height"]): raise GenericJsonRpcServerError( code=JsonError.INVALID_PARAMS, message='Invalid params (only one parameter is allowed)', http_status=status.HTTP_BAD_REQUEST) if 'hash' in request: block_hash, result = await get_block_by_params( block_hash=request['hash'], channel_name=channel) elif 'height' in request: block_hash, result = await get_block_by_params( block_height=request['height'], channel_name=channel) else: block_hash, result = await get_block_by_params( block_height=-1, channel_name=channel) response_code = result['response_code'] check_response_code(response_code) block = result['block'] if block['version'] == BLOCK_v0_1a: response = convert_params(result['block'], ResponseParamType.get_block_v0_1a_tx_v3) elif block['version'] == BLOCK_v0_3: response = convert_params(result['block'], ResponseParamType.get_block_v0_3_tx_v3) else: response = block return response_to_json_query(response)
async def icx_getReceiptProof(**kwargs): channel = kwargs['context']['channel'] channel_stub = get_channel_stub_by_channel_name(channel) tx_hash = kwargs['txHash'] response = await channel_stub.async_task().get_receipt_proof(tx_hash) return response_to_json_query(response)
async def icx_proveTransaction(**kwargs): channel = kwargs['context']['channel'] channel_stub = get_channel_stub_by_channel_name(channel) tx_hash = kwargs['txHash'] proof = kwargs['proof'] response = await channel_stub.async_task().prove_tx(tx_hash, proof) return response_to_json_query(response)
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)
async def icx_getBalance(**kwargs): channel_name = StubCollection().conf[ConfigKey.CHANNEL] method = 'icx_getBalance' request = make_request(method, kwargs, RequestParamType.get_balance) stub = StubCollection().icon_score_stubs[channel_name] response = await stub.async_task().query(request) return response_to_json_query(response, True)
async def icx_getLastBlock(context: Dict[str, str], **kwargs): channel = context.get('channel') block_hash, result = await get_block_by_params(block_height=-1, channel_name=channel) response = convert_params(result['block'], ResponseParamType.get_block_v0_1a_tx_v3) return response_to_json_query(response)
async def rep_getListByHash(**kwargs): channel = kwargs['context']['channel'] channel_stub = get_channel_stub_by_channel_name(channel) request = convert_params(kwargs, RequestParamType.get_reps_by_hash) reps_hash = request.get('repsHash') reps = await channel_stub.async_task().get_reps_by_hash(reps_hash=reps_hash) Logger.debug(f"reps_hash: {reps_hash}, reps: {reps}") response = [{'address': rep['id'], 'p2pEndpoint': rep['p2pEndpoint']} for rep in reps] return response_to_json_query(response)
async def icx_getTotalSupply(context: Dict[str, str], **kwargs): channel_name = StubCollection().conf[ConfigKey.CHANNEL] method = 'icx_getTotalSupply' request = make_request(method, kwargs, RequestParamType.get_total_supply) stub = StubCollection().icon_score_stubs[channel_name] response = await stub.async_task().query(request) return response_to_json_query(response, True)
async def ise_getStatus(context, **kwargs): channel = context.get('channel') method = 'ise_getStatus' request = make_request(method, kwargs) score_stub = get_icon_stub_by_channel_name(channel) response = await score_stub.async_task().query(request) error = response.get('error') if error is None: IseDispatcher._hash_convert(None, response) return response_to_json_query(response)
async def icx_sendTransaction(context: Dict[str, str], **kwargs): channel = context.get('channel') url = context.get('url') path = urlparse(url).path 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) # DosGuard if StubCollection().conf.get(ConfigKey.DOS_GUARD_ENABLE, False): response = await icon_stub.async_task().dos_guard(kwargs) # Error Check response_to_json_query(response) channel_tx_creator_stub = StubCollection( ).channel_tx_creator_stubs[channel] response_code, tx_hash, relay_target = \ 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( path, kwargs, relay_target) 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, ResponseParamType.send_tx)
async def icx_sendTransaction(**kwargs): url = kwargs['context']['url'] path = urlparse(url).path del kwargs['context'] if RestProperty().node_type == NodeType.CitizenNode: dispatch_protocol = Version2Dispatcher.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[1:], ApiVersion.v2.name) request = make_request("icx_sendTransaction", kwargs, ParamType.send_tx) channel = StubCollection().conf[ConfigKey.CHANNEL] icon_stub = StubCollection().icon_score_stubs[channel] response = await icon_stub.async_task().validate_transaction(request) # Error Check response_to_json_query(response) channel_name = StubCollection().conf[ConfigKey.CHANNEL] channel_tx_creator_stub = StubCollection( ).channel_tx_creator_stubs[channel_name] response_code, tx_hash = await channel_tx_creator_stub.async_task( ).create_icx_tx(kwargs) response_data = {'response_code': response_code} if response_code != message_code.Response.success: response_data['message'] = message_code.responseCodeMap[ response_code][1] else: response_data['tx_hash'] = tx_hash return response_data
async def ise_getStatus(**kwargs): Logger.warning(f'Hello World2') # channel = kwargs['context']['channel'] # method = 'ise_getStatus' # request = make_request(method, kwargs) # score_stub = get_icon_stub_by_channel_name(channel) # response = await score_stub.async_task().query(request) # error = response.get('error') # if error is None: # IseDispatcher._hash_convert(None, response) response = {'hello': 'world'} return response_to_json_query(response)
async def icx_getBlockReceipts(context: Dict[str, str], **kwargs): channel = context.get('channel') request = convert_params(kwargs, RequestParamType.get_block_receipts) if all(param in request for param in ["hash", "height"]): raise GenericJsonRpcServerError( code=JsonError.INVALID_PARAMS, message='Invalid params (only one parameter is allowed)', http_status=status.HTTP_BAD_REQUEST) if 'hash' in request: code, block_receipts = await get_block_recipts_by_params( block_hash=request['hash'], channel_name=channel) elif 'height' in request: code, block_receipts = await get_block_recipts_by_params( block_height=request['height'], channel_name=channel) else: code, block_receipts = await get_block_recipts_by_params( block_height=-1, channel_name=channel) check_response_code(code) response = convert_params(block_receipts, ResponseParamType.get_block_receipts) return response_to_json_query(response)
async def rep_getList(**kwargs): channel = kwargs['context']['channel'] channel_infos = await StubCollection().peer_stub.async_task( ).get_channel_infos() channel_infos_by_channel = channel_infos.get(channel) rep_list = [{ 'id': peer['id'] } for peer in channel_infos_by_channel['peers']] Logger.debug(f'rep list: {rep_list}') start_term_height = '0x0' end_term_height = '0x0' rep_hash = '' # term_height, rep_root_hash should be updated after IISS is implemented. response = { 'startTermHeight': start_term_height, 'endTermHeight': end_term_height, 'repHash': rep_hash, 'rep': rep_list } return response_to_json_query(response)
async def rep_getList(**kwargs): channel = kwargs['context']['channel'] score_stub = get_icon_stub_by_channel_name(channel) method = "ise_getPReps" request = make_request(method, kwargs) response = score_stub.sync_task().call(request) rep_list = [{ "id": rep_info["id"], "target": rep_info["target"] } for rep_info in response["result"]["preps"]] Logger.debug(f'rep list: {rep_list}') start_term_height = '0x0' end_term_height = '0x0' rep_hash = '' # term_height, rep_root_hash should be updated after IISS is implemented. response = { 'startTermHeight': start_term_height, 'endTermHeight': end_term_height, 'repHash': rep_hash, 'rep': rep_list } return response_to_json_query(response)