@Test public void isAliasUsableTest() throws Exception { Map<String, Object> params = new HashMap<>(); params.put(Constants.VERSION_KEY_STR, "1.0"); params.put(Constants.CHAIN_ID, chainId); params.put("alias", "nuls2"); Response cmdResp = ResponseMessageProcessor.requestAndResponse(ModuleE.AC.abbr, "ac_isAliasUsable", params); assertNotNull(cmdResp); HashMap result = (HashMap) ((HashMap) cmdResp.getResponseData()).get("ac_isAliasUsable"); assertNotNull(result); Boolean value = (Boolean) result.get("value"); System.out.println(value); }
@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 = "别名是否可以使用") })) public Response isAliasUsable(Map params) { boolean isAliasUsable = false; Chain chain = null; String alias; Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object aliasObj = params == null ? null : params.get(RpcParameterNameConstant.ALIAS); try { if (params == null || chainIdObj == null || aliasObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } alias = (String) aliasObj; isAliasUsable = aliasService.isAliasUsable(chain.getChainId(), alias); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } Map<String, Boolean> result = new HashMap<>(AccountConstant.INIT_CAPACITY_2); result.put("value", isAliasUsable); return success(result); }
AliasCmd extends BaseCmd { @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 = "别名是否可以使用") })) public Response isAliasUsable(Map params) { boolean isAliasUsable = false; Chain chain = null; String alias; Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object aliasObj = params == null ? null : params.get(RpcParameterNameConstant.ALIAS); try { if (params == null || chainIdObj == null || aliasObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } alias = (String) aliasObj; isAliasUsable = aliasService.isAliasUsable(chain.getChainId(), alias); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } Map<String, Boolean> result = new HashMap<>(AccountConstant.INIT_CAPACITY_2); result.put("value", isAliasUsable); return success(result); } }
AliasCmd extends BaseCmd { @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 = "别名是否可以使用") })) public Response isAliasUsable(Map params) { boolean isAliasUsable = false; Chain chain = null; String alias; Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object aliasObj = params == null ? null : params.get(RpcParameterNameConstant.ALIAS); try { if (params == null || chainIdObj == null || aliasObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } alias = (String) aliasObj; isAliasUsable = aliasService.isAliasUsable(chain.getChainId(), alias); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } Map<String, Boolean> result = new HashMap<>(AccountConstant.INIT_CAPACITY_2); result.put("value", isAliasUsable); return success(result); }  }
AliasCmd extends BaseCmd { @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 = "别名是否可以使用") })) public Response isAliasUsable(Map params) { boolean isAliasUsable = false; Chain chain = null; String alias; Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object aliasObj = params == null ? null : params.get(RpcParameterNameConstant.ALIAS); try { if (params == null || chainIdObj == null || aliasObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } alias = (String) aliasObj; isAliasUsable = aliasService.isAliasUsable(chain.getChainId(), alias); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } Map<String, Boolean> result = new HashMap<>(AccountConstant.INIT_CAPACITY_2); result.put("value", isAliasUsable); 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_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 = "别名是否可以使用") })) public Response isAliasUsable(Map params) { boolean isAliasUsable = false; Chain chain = null; String alias; Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object aliasObj = params == null ? null : params.get(RpcParameterNameConstant.ALIAS); try { if (params == null || chainIdObj == null || aliasObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } alias = (String) aliasObj; isAliasUsable = aliasService.isAliasUsable(chain.getChainId(), alias); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } Map<String, Boolean> result = new HashMap<>(AccountConstant.INIT_CAPACITY_2); result.put("value", isAliasUsable); 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);  }