@Test public void getAliasByAddressTest() throws Exception { int count = 1; String address="tNULSeBaMvEtDfvZuukDf2mVyfGo3DdiN8KLRG"; Map<String, Object> params = new HashMap<>(); params.put(Constants.VERSION_KEY_STR, "1.0"); params.put(Constants.CHAIN_ID, chainId); params.put("address", address); Response cmdResp = ResponseMessageProcessor.requestAndResponse(ModuleE.AC.abbr, "ac_getAliasByAddress", params); assertNotNull(cmdResp); HashMap result = (HashMap) ((HashMap) cmdResp.getResponseData()).get("ac_getAliasByAddress"); assertNotNull(result); String alias = (String) result.get("alias"); System.out.println(alias); assertNotNull(alias); }
@CmdAnnotation(cmd = "ac_getAliasByAddress", version = 1.0, description = "根据地址获取别名/get the alias by address") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "alias", description = "别名") })) public Response getAliasByAddress(Map params) { String alias; Chain chain = null; Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object addressObj = params == null ? null : params.get(RpcParameterNameConstant.ADDRESS); String address; try { if (params == null || chainIdObj == null || addressObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } address = (String) addressObj; alias = aliasService.getAliasByAddress(chain.getChainId(), address); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } Map<String, String> result = new HashMap<>(AccountConstant.INIT_CAPACITY_2); result.put("alias", alias); return success(result); }
AliasCmd extends BaseCmd { @CmdAnnotation(cmd = "ac_getAliasByAddress", version = 1.0, description = "根据地址获取别名/get the alias by address") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "alias", description = "别名") })) public Response getAliasByAddress(Map params) { String alias; Chain chain = null; Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object addressObj = params == null ? null : params.get(RpcParameterNameConstant.ADDRESS); String address; try { if (params == null || chainIdObj == null || addressObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } address = (String) addressObj; alias = aliasService.getAliasByAddress(chain.getChainId(), address); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } Map<String, String> result = new HashMap<>(AccountConstant.INIT_CAPACITY_2); result.put("alias", alias); return success(result); } }
AliasCmd extends BaseCmd { @CmdAnnotation(cmd = "ac_getAliasByAddress", version = 1.0, description = "根据地址获取别名/get the alias by address") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "alias", description = "别名") })) public Response getAliasByAddress(Map params) { String alias; Chain chain = null; Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object addressObj = params == null ? null : params.get(RpcParameterNameConstant.ADDRESS); String address; try { if (params == null || chainIdObj == null || addressObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } address = (String) addressObj; alias = aliasService.getAliasByAddress(chain.getChainId(), address); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } Map<String, String> result = new HashMap<>(AccountConstant.INIT_CAPACITY_2); result.put("alias", alias); return success(result); }  }
AliasCmd extends BaseCmd { @CmdAnnotation(cmd = "ac_getAliasByAddress", version = 1.0, description = "根据地址获取别名/get the alias by address") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "alias", description = "别名") })) public Response getAliasByAddress(Map params) { String alias; Chain chain = null; Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object addressObj = params == null ? null : params.get(RpcParameterNameConstant.ADDRESS); String address; try { if (params == null || chainIdObj == null || addressObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } address = (String) addressObj; alias = aliasService.getAliasByAddress(chain.getChainId(), address); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } Map<String, String> result = new HashMap<>(AccountConstant.INIT_CAPACITY_2); result.put("alias", alias); return success(result); }  @CmdAnnotation(cmd = "ac_setAlias", version = 1.0, description = "设置别名/Set the alias of account") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码"), @Parameter(parameterName = "alias", parameterType = "String", parameterDes = "别名") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "txHash", description = "设置别名交易hash") })) Response setAlias(Map params); @CmdAnnotation(cmd = "ac_getAliasByAddress", version = 1.0, description = "根据地址获取别名/get the alias by address") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "alias", description = "别名") })) Response getAliasByAddress(Map params); @CmdAnnotation(cmd = "ac_isAliasUsable", version = 1.0, description = "检查别名是否可用/check whether the account is usable") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "alias", parameterType = "String", parameterDes = "别名") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "value", valueType = Boolean.class, description = "别名是否可以使用") })) Response isAliasUsable(Map params); }
AliasCmd extends BaseCmd { @CmdAnnotation(cmd = "ac_getAliasByAddress", version = 1.0, description = "根据地址获取别名/get the alias by address") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "alias", description = "别名") })) public Response getAliasByAddress(Map params) { String alias; Chain chain = null; Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object addressObj = params == null ? null : params.get(RpcParameterNameConstant.ADDRESS); String address; try { if (params == null || chainIdObj == null || addressObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } address = (String) addressObj; alias = aliasService.getAliasByAddress(chain.getChainId(), address); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } Map<String, String> result = new HashMap<>(AccountConstant.INIT_CAPACITY_2); result.put("alias", alias); return success(result); }  @CmdAnnotation(cmd = "ac_setAlias", version = 1.0, description = "设置别名/Set the alias of account") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码"), @Parameter(parameterName = "alias", parameterType = "String", parameterDes = "别名") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "txHash", description = "设置别名交易hash") })) Response setAlias(Map params); @CmdAnnotation(cmd = "ac_getAliasByAddress", version = 1.0, description = "根据地址获取别名/get the alias by address") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "alias", description = "别名") })) Response getAliasByAddress(Map params); @CmdAnnotation(cmd = "ac_isAliasUsable", version = 1.0, description = "检查别名是否可用/check whether the account is usable") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "alias", parameterType = "String", parameterDes = "别名") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "value", valueType = Boolean.class, description = "别名是否可以使用") })) Response isAliasUsable(Map params);  }