@Test public void importAccountByPriKeyTest() { try { List<String> accountList = CommonRpcOperation.createAccount(chainId, 1, password); String priKey = getPriKeyByAddress(chainId, accountList.get(0), password); assertNotNull(priKey); Map<String, Object> params = new HashMap<>(); params.put(Constants.VERSION_KEY_STR, version); params.put(Constants.CHAIN_ID, chainId); params.put("priKey", "5d3ee4ab8f9d5c03fb061ad14fe014c999a35c4a03d19a56d10cb4ad95d8463c"); params.put("password", password); params.put("overwrite", true); Response cmdResp = ResponseMessageProcessor.requestAndResponse(ModuleE.AC.abbr, "ac_importAccountByPriKey", params); HashMap result = (HashMap) ((HashMap) cmdResp.getResponseData()).get("ac_importAccountByPriKey"); String address = (String) result.get("address"); params.put("overwrite", false); cmdResp = ResponseMessageProcessor.requestAndResponse(ModuleE.AC.abbr, "ac_importAccountByPriKey", params); assertNotEquals(AccountConstant.SUCCESS_CODE, cmdResp.getResponseStatus()); Map<String, Object> params2 = new HashMap<>(); params2.put(Constants.VERSION_KEY_STR, version); params2.put("chainId", chainId); params2.put("address", accountList.get(0)); params2.put("password", password); ResponseMessageProcessor.requestAndResponse(ModuleE.AC.abbr, "ac_removeAccount", params2); params.put("priKey", priKey); cmdResp = ResponseMessageProcessor.requestAndResponse(ModuleE.AC.abbr, "ac_importAccountByPriKey", params); assertEquals(AccountConstant.SUCCESS_CODE, cmdResp.getResponseStatus()); String addressx = "KMNPqwARu77qAL4UCkd5Vwvj5PAtw3930"; priKey = "00af59aa43536f6162a7166cdc1a389b32be0a06bc06f71a601a92e08fd2788dfe"; params.remove("password"); params.put("priKey", priKey); params.put("overwrite", true); cmdResp = ResponseMessageProcessor.requestAndResponse(ModuleE.AC.abbr, "ac_importAccountByPriKey", params); result = (HashMap) ((HashMap) cmdResp.getResponseData()).get("ac_importAccountByPriKey"); address = (String) result.get("address"); assertEquals(addressx, address); } catch (NulsRuntimeException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
@CmdAnnotation(cmd = "ac_importAccountByPriKey", version = 1.0, description = "根据私钥导入账户/Import accounts by private key") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "设置新密码"), @Parameter(parameterName = "priKey", parameterType = "String", parameterDes = "账户私钥"), @Parameter(parameterName = "overwrite", requestType = @TypeDescriptor(value = boolean.class), parameterDes = "如果账户已存在,是否覆盖") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.ADDRESS, description = "导入的账户地址") })) public Response importAccountByPriKey(Map params) { Map<String, String> map = new HashMap<>(AccountConstant.INIT_CAPACITY_2); Chain chain = null; try { Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object priKeyObj = params == null ? null : params.get(RpcParameterNameConstant.PRIKEY); Object passwordObj = params == null ? null : params.get(RpcParameterNameConstant.PASSWORD); Object overwriteObj = params == null ? null : params.get(RpcParameterNameConstant.OVERWRITE); if (params == null || chainIdObj == null || priKeyObj == null || passwordObj == null || overwriteObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } String priKey = (String) priKeyObj; String password = (String) passwordObj; Boolean overwrite = (Boolean) overwriteObj; Account account = accountService.importAccountByPrikey(chain, priKey, password, overwrite); map.put(RpcConstant.ADDRESS, account.getAddress().toString()); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (NulsException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } return success(map); }
AccountCmd extends BaseCmd { @CmdAnnotation(cmd = "ac_importAccountByPriKey", version = 1.0, description = "根据私钥导入账户/Import accounts by private key") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "设置新密码"), @Parameter(parameterName = "priKey", parameterType = "String", parameterDes = "账户私钥"), @Parameter(parameterName = "overwrite", requestType = @TypeDescriptor(value = boolean.class), parameterDes = "如果账户已存在,是否覆盖") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.ADDRESS, description = "导入的账户地址") })) public Response importAccountByPriKey(Map params) { Map<String, String> map = new HashMap<>(AccountConstant.INIT_CAPACITY_2); Chain chain = null; try { Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object priKeyObj = params == null ? null : params.get(RpcParameterNameConstant.PRIKEY); Object passwordObj = params == null ? null : params.get(RpcParameterNameConstant.PASSWORD); Object overwriteObj = params == null ? null : params.get(RpcParameterNameConstant.OVERWRITE); if (params == null || chainIdObj == null || priKeyObj == null || passwordObj == null || overwriteObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } String priKey = (String) priKeyObj; String password = (String) passwordObj; Boolean overwrite = (Boolean) overwriteObj; Account account = accountService.importAccountByPrikey(chain, priKey, password, overwrite); map.put(RpcConstant.ADDRESS, account.getAddress().toString()); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (NulsException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } return success(map); } }
AccountCmd extends BaseCmd { @CmdAnnotation(cmd = "ac_importAccountByPriKey", version = 1.0, description = "根据私钥导入账户/Import accounts by private key") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "设置新密码"), @Parameter(parameterName = "priKey", parameterType = "String", parameterDes = "账户私钥"), @Parameter(parameterName = "overwrite", requestType = @TypeDescriptor(value = boolean.class), parameterDes = "如果账户已存在,是否覆盖") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.ADDRESS, description = "导入的账户地址") })) public Response importAccountByPriKey(Map params) { Map<String, String> map = new HashMap<>(AccountConstant.INIT_CAPACITY_2); Chain chain = null; try { Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object priKeyObj = params == null ? null : params.get(RpcParameterNameConstant.PRIKEY); Object passwordObj = params == null ? null : params.get(RpcParameterNameConstant.PASSWORD); Object overwriteObj = params == null ? null : params.get(RpcParameterNameConstant.OVERWRITE); if (params == null || chainIdObj == null || priKeyObj == null || passwordObj == null || overwriteObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } String priKey = (String) priKeyObj; String password = (String) passwordObj; Boolean overwrite = (Boolean) overwriteObj; Account account = accountService.importAccountByPrikey(chain, priKey, password, overwrite); map.put(RpcConstant.ADDRESS, account.getAddress().toString()); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (NulsException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } return success(map); }  }
AccountCmd extends BaseCmd { @CmdAnnotation(cmd = "ac_importAccountByPriKey", version = 1.0, description = "根据私钥导入账户/Import accounts by private key") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "设置新密码"), @Parameter(parameterName = "priKey", parameterType = "String", parameterDes = "账户私钥"), @Parameter(parameterName = "overwrite", requestType = @TypeDescriptor(value = boolean.class), parameterDes = "如果账户已存在,是否覆盖") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.ADDRESS, description = "导入的账户地址") })) public Response importAccountByPriKey(Map params) { Map<String, String> map = new HashMap<>(AccountConstant.INIT_CAPACITY_2); Chain chain = null; try { Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object priKeyObj = params == null ? null : params.get(RpcParameterNameConstant.PRIKEY); Object passwordObj = params == null ? null : params.get(RpcParameterNameConstant.PASSWORD); Object overwriteObj = params == null ? null : params.get(RpcParameterNameConstant.OVERWRITE); if (params == null || chainIdObj == null || priKeyObj == null || passwordObj == null || overwriteObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } String priKey = (String) priKeyObj; String password = (String) passwordObj; Boolean overwrite = (Boolean) overwriteObj; Account account = accountService.importAccountByPrikey(chain, priKey, password, overwrite); map.put(RpcConstant.ADDRESS, account.getAddress().toString()); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (NulsException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } return success(map); }  @CmdAnnotation(cmd = "ac_createAccount", version = 1.0, description = "创建指定个数的账户/create a specified number of accounts") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "count", requestType = @TypeDescriptor(value = int.class), parameterDes = "需要创建账户的数量"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.LIST, valueType = List.class, valueElement = String.class, description = "创建的账户地址集合"), })) Response createAccount(Map params); @CmdAnnotation(cmd = "ac_createOfflineAccount", version = 1.0, description = "创建离线账户, 该账户不保存到数据库, 并将直接返回账户的所有信息/" + "create an offline account, which is not saved to the database and will directly return all information to the account.") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "count", requestType = @TypeDescriptor(value = int.class), parameterDes = "需要创建账户的数量"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.LIST, valueType = List.class, valueElement = AccountOfflineDTO.class, description = "离线账户集合"), })) Response createOfflineAccount(Map params); @CmdAnnotation(cmd = "ac_createContractAccount", version = 1.0, description = "创建智能合约账户/create smart contract account") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "address", description = "智能合约地址") })) Response createContractAccount(Map params); @CmdAnnotation(cmd = "ac_getAccountByAddress", version = 1.0, description = "通过地址获取账户信息/get account info according to address") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址") }) @ResponseData(name = "返回值", responseType = @TypeDescriptor(value = SimpleAccountDTO.class)) Response getAccountByAddress(Map params); @CmdAnnotation(cmd = "ac_getAccountList", version = 1.0, description = "获取所有账户集合,并放入缓存/query all account collections and put them in cache") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.LIST, valueType = List.class, valueElement = SimpleAccountDTO.class, description = "返回账户集合"), })) Response getAccountList(Map params); @CmdAnnotation(cmd = "ac_getEncryptedAddressList", version = 1.0, description = "获取本地加密账户列表/Get a list of locally encrypted accounts") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.LIST, valueType = List.class, valueElement = String.class, description = "返回账户地址集合"), })) Response getEncryptedAddressList(Map params); @CmdAnnotation(cmd = "ac_getAddressList", version = 1.0, description = "分页查询账户地址列表/Paging query account address list") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = RpcParameterNameConstant.PAGE_NUMBER, requestType = @TypeDescriptor(value = int.class), parameterDes = "页码"), @Parameter(parameterName = RpcParameterNameConstant.PAGE_SIZE, requestType = @TypeDescriptor(value = int.class), parameterDes = "每一页记录数") }) @ResponseData(name = "返回值", description = "返回一个Page对象，账户集合", responseType = @TypeDescriptor(value = List.class, collectionElement = String.class) ) Response getAddressList(Map params); @CmdAnnotation(cmd = "ac_removeAccount", version = 1.0, description = "移除指定账户/Remove specified 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 = "账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.VALUE, valueType = boolean.class, description = "是否成功") })) Response removeAccount(Map params); @CmdAnnotation(cmd = "ac_getPubKey", version = 1.0, description = "根据账户地址和密码,查询账户公钥/Get the account's key") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map，包含一个key", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "pubKey", description = "公钥") })) Response getPubKey(Map params); @CmdAnnotation(cmd = "ac_getPriKeyByAddress", version = 1.0, description = "通过账户地址和密码,查询账户私匙/Inquire the account's private key according to the address") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map，包含二个key", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "priKey", description = "私钥"), @Key(name = "pubKey", description = "公钥") })) Response getPriKeyByAddress(Map params); @CmdAnnotation(cmd = "ac_getAllPriKey", version = 1.0, description = "获取所有本地账户账户私钥，必须保证所有账户密码一致，如果本地账户中的密码不一致，将返回错误信息/" + "Get the all local private keys. if the password in the local account is different, the error message will be returned.") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.LIST, valueType = List.class, valueElement = String.class, description = "私钥集合") })) Response getAllPriKey(Map params); @CmdAnnotation(cmd = "ac_setRemark", version = 1.0, description = "为账户设置备注/Set remark for accounts") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址"), @Parameter(parameterName = "remark", parameterType = "String", parameterDes = "备注") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "value", valueType = boolean.class, description = "是否成功") })) Response setRemark(Map params); @CmdAnnotation(cmd = "ac_importAccountByPriKey", version = 1.0, description = "根据私钥导入账户/Import accounts by private key") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "设置新密码"), @Parameter(parameterName = "priKey", parameterType = "String", parameterDes = "账户私钥"), @Parameter(parameterName = "overwrite", requestType = @TypeDescriptor(value = boolean.class), parameterDes = "如果账户已存在,是否覆盖") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.ADDRESS, description = "导入的账户地址") })) Response importAccountByPriKey(Map params); @CmdAnnotation(cmd = "ac_importAccountByKeystore", version = 1.0, description = "根据AccountKeyStore导入账户/Import accounts by AccountKeyStore") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "设置新密码"), @Parameter(parameterName = "keyStore", parameterType = "String", parameterDes = "keyStore字符串"), @Parameter(parameterName = "overwrite", requestType = @TypeDescriptor(value = boolean.class), parameterDes = "如果账户已存在,是否覆盖") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.ADDRESS, description = "导入的账户地址") })) Response importAccountByKeystore(Map params); @CmdAnnotation(cmd = "ac_exportKeyStoreJson", version = 1.0, description = "导出AccountKeyStore字符串/export account KeyStore json") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码")}) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "keyStore", description = "keyStore字符串") })) Response exportKeyStoreJson(Map params); @CmdAnnotation(cmd = "ac_exportAccountKeyStore", version = 1.0, description = "账户备份，导出AccountKeyStore字符串/export account KeyStore") @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 = "filePath", parameterType = "String", parameterDes = "备份地址", canNull = true) }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.PATH, description = "实际备份文件的地址") })) Response exportAccountKeyStore(Map params); @CmdAnnotation(cmd = "ac_updatePassword", version = 1.0, description = "根据原密码修改账户密码/Modify the account password by the original password") @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 = "newPassword", parameterType = "String", parameterDes = "账户新密码") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.VALUE, valueType = boolean.class, description = "是否设置成功") })) Response updatePassword(Map params); @CmdAnnotation(cmd = "ac_updateOfflineAccountPassword", version = 1.0, description = "离线账户修改密码/Offline account change password") @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 = "newPassword", parameterType = "String", parameterDes = "账户新密码"), @Parameter(parameterName = "priKey", parameterType = "String", parameterDes = "账户私钥") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.ENCRYPTED_PRIKEY, description = "返回修改后加密的私钥") })) Response updateOfflineAccountPassword(Map params); @CmdAnnotation(cmd = "ac_validationPassword", version = 1.0, description = "验证账户密码是否正确/Verify that the account password is correct") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.VALUE, valueType = boolean.class, description = "账户密码是否正确") })) Response validationPassword(Map params); @CmdAnnotation(cmd = "ac_signDigest", version = 1.0, description = "数据摘要签名/Data digest signature") @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 = "data", parameterType = "String", parameterDes = "待签名数据") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.SIGNATURE, description = "签名后数据") })) Response signDigest(Map params); @CmdAnnotation(cmd = "ac_signBlockDigest", version = 1.0, description = "区块数据摘要签名/Block data digest signature") @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 = "data", parameterType = "String", parameterDes = "待签名数据") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.SIGNATURE, description = "签名后数据") })) Response signBlockDigest(Map params); @CmdAnnotation(cmd = "ac_verifySignData", version = 1.0, description = "验证数据签名/Verification Data Signature") @Parameters(value = { @Parameter(parameterName = "pubKey", parameterType = "String", parameterDes = "账户公钥"), @Parameter(parameterName = "sig", parameterType = "String", parameterDes = "签名"), @Parameter(parameterName = "data", parameterType = "String", parameterDes = "待签名数据") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.SIGNATURE, valueType = boolean.class, description = "签名是否正确") })) Response verifySignData(Map params); }
AccountCmd extends BaseCmd { @CmdAnnotation(cmd = "ac_importAccountByPriKey", version = 1.0, description = "根据私钥导入账户/Import accounts by private key") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "设置新密码"), @Parameter(parameterName = "priKey", parameterType = "String", parameterDes = "账户私钥"), @Parameter(parameterName = "overwrite", requestType = @TypeDescriptor(value = boolean.class), parameterDes = "如果账户已存在,是否覆盖") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.ADDRESS, description = "导入的账户地址") })) public Response importAccountByPriKey(Map params) { Map<String, String> map = new HashMap<>(AccountConstant.INIT_CAPACITY_2); Chain chain = null; try { Object chainIdObj = params == null ? null : params.get(RpcParameterNameConstant.CHAIN_ID); Object priKeyObj = params == null ? null : params.get(RpcParameterNameConstant.PRIKEY); Object passwordObj = params == null ? null : params.get(RpcParameterNameConstant.PASSWORD); Object overwriteObj = params == null ? null : params.get(RpcParameterNameConstant.OVERWRITE); if (params == null || chainIdObj == null || priKeyObj == null || passwordObj == null || overwriteObj == null) { throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } chain = chainManager.getChain((Integer) chainIdObj); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } String priKey = (String) priKeyObj; String password = (String) passwordObj; Boolean overwrite = (Boolean) overwriteObj; Account account = accountService.importAccountByPrikey(chain, priKey, password, overwrite); map.put(RpcConstant.ADDRESS, account.getAddress().toString()); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (NulsException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } return success(map); }  @CmdAnnotation(cmd = "ac_createAccount", version = 1.0, description = "创建指定个数的账户/create a specified number of accounts") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "count", requestType = @TypeDescriptor(value = int.class), parameterDes = "需要创建账户的数量"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.LIST, valueType = List.class, valueElement = String.class, description = "创建的账户地址集合"), })) Response createAccount(Map params); @CmdAnnotation(cmd = "ac_createOfflineAccount", version = 1.0, description = "创建离线账户, 该账户不保存到数据库, 并将直接返回账户的所有信息/" + "create an offline account, which is not saved to the database and will directly return all information to the account.") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "count", requestType = @TypeDescriptor(value = int.class), parameterDes = "需要创建账户的数量"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.LIST, valueType = List.class, valueElement = AccountOfflineDTO.class, description = "离线账户集合"), })) Response createOfflineAccount(Map params); @CmdAnnotation(cmd = "ac_createContractAccount", version = 1.0, description = "创建智能合约账户/create smart contract account") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "address", description = "智能合约地址") })) Response createContractAccount(Map params); @CmdAnnotation(cmd = "ac_getAccountByAddress", version = 1.0, description = "通过地址获取账户信息/get account info according to address") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址") }) @ResponseData(name = "返回值", responseType = @TypeDescriptor(value = SimpleAccountDTO.class)) Response getAccountByAddress(Map params); @CmdAnnotation(cmd = "ac_getAccountList", version = 1.0, description = "获取所有账户集合,并放入缓存/query all account collections and put them in cache") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.LIST, valueType = List.class, valueElement = SimpleAccountDTO.class, description = "返回账户集合"), })) Response getAccountList(Map params); @CmdAnnotation(cmd = "ac_getEncryptedAddressList", version = 1.0, description = "获取本地加密账户列表/Get a list of locally encrypted accounts") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.LIST, valueType = List.class, valueElement = String.class, description = "返回账户地址集合"), })) Response getEncryptedAddressList(Map params); @CmdAnnotation(cmd = "ac_getAddressList", version = 1.0, description = "分页查询账户地址列表/Paging query account address list") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = RpcParameterNameConstant.PAGE_NUMBER, requestType = @TypeDescriptor(value = int.class), parameterDes = "页码"), @Parameter(parameterName = RpcParameterNameConstant.PAGE_SIZE, requestType = @TypeDescriptor(value = int.class), parameterDes = "每一页记录数") }) @ResponseData(name = "返回值", description = "返回一个Page对象，账户集合", responseType = @TypeDescriptor(value = List.class, collectionElement = String.class) ) Response getAddressList(Map params); @CmdAnnotation(cmd = "ac_removeAccount", version = 1.0, description = "移除指定账户/Remove specified 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 = "账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.VALUE, valueType = boolean.class, description = "是否成功") })) Response removeAccount(Map params); @CmdAnnotation(cmd = "ac_getPubKey", version = 1.0, description = "根据账户地址和密码,查询账户公钥/Get the account's key") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map，包含一个key", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "pubKey", description = "公钥") })) Response getPubKey(Map params); @CmdAnnotation(cmd = "ac_getPriKeyByAddress", version = 1.0, description = "通过账户地址和密码,查询账户私匙/Inquire the account's private key according to the address") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map，包含二个key", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "priKey", description = "私钥"), @Key(name = "pubKey", description = "公钥") })) Response getPriKeyByAddress(Map params); @CmdAnnotation(cmd = "ac_getAllPriKey", version = 1.0, description = "获取所有本地账户账户私钥，必须保证所有账户密码一致，如果本地账户中的密码不一致，将返回错误信息/" + "Get the all local private keys. if the password in the local account is different, the error message will be returned.") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.LIST, valueType = List.class, valueElement = String.class, description = "私钥集合") })) Response getAllPriKey(Map params); @CmdAnnotation(cmd = "ac_setRemark", version = 1.0, description = "为账户设置备注/Set remark for accounts") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址"), @Parameter(parameterName = "remark", parameterType = "String", parameterDes = "备注") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "value", valueType = boolean.class, description = "是否成功") })) Response setRemark(Map params); @CmdAnnotation(cmd = "ac_importAccountByPriKey", version = 1.0, description = "根据私钥导入账户/Import accounts by private key") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "设置新密码"), @Parameter(parameterName = "priKey", parameterType = "String", parameterDes = "账户私钥"), @Parameter(parameterName = "overwrite", requestType = @TypeDescriptor(value = boolean.class), parameterDes = "如果账户已存在,是否覆盖") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.ADDRESS, description = "导入的账户地址") })) Response importAccountByPriKey(Map params); @CmdAnnotation(cmd = "ac_importAccountByKeystore", version = 1.0, description = "根据AccountKeyStore导入账户/Import accounts by AccountKeyStore") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "设置新密码"), @Parameter(parameterName = "keyStore", parameterType = "String", parameterDes = "keyStore字符串"), @Parameter(parameterName = "overwrite", requestType = @TypeDescriptor(value = boolean.class), parameterDes = "如果账户已存在,是否覆盖") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.ADDRESS, description = "导入的账户地址") })) Response importAccountByKeystore(Map params); @CmdAnnotation(cmd = "ac_exportKeyStoreJson", version = 1.0, description = "导出AccountKeyStore字符串/export account KeyStore json") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码")}) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "keyStore", description = "keyStore字符串") })) Response exportKeyStoreJson(Map params); @CmdAnnotation(cmd = "ac_exportAccountKeyStore", version = 1.0, description = "账户备份，导出AccountKeyStore字符串/export account KeyStore") @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 = "filePath", parameterType = "String", parameterDes = "备份地址", canNull = true) }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.PATH, description = "实际备份文件的地址") })) Response exportAccountKeyStore(Map params); @CmdAnnotation(cmd = "ac_updatePassword", version = 1.0, description = "根据原密码修改账户密码/Modify the account password by the original password") @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 = "newPassword", parameterType = "String", parameterDes = "账户新密码") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.VALUE, valueType = boolean.class, description = "是否设置成功") })) Response updatePassword(Map params); @CmdAnnotation(cmd = "ac_updateOfflineAccountPassword", version = 1.0, description = "离线账户修改密码/Offline account change password") @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 = "newPassword", parameterType = "String", parameterDes = "账户新密码"), @Parameter(parameterName = "priKey", parameterType = "String", parameterDes = "账户私钥") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.ENCRYPTED_PRIKEY, description = "返回修改后加密的私钥") })) Response updateOfflineAccountPassword(Map params); @CmdAnnotation(cmd = "ac_validationPassword", version = 1.0, description = "验证账户密码是否正确/Verify that the account password is correct") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "address", parameterType = "String", parameterDes = "账户地址"), @Parameter(parameterName = "password", parameterType = "String", parameterDes = "账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.VALUE, valueType = boolean.class, description = "账户密码是否正确") })) Response validationPassword(Map params); @CmdAnnotation(cmd = "ac_signDigest", version = 1.0, description = "数据摘要签名/Data digest signature") @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 = "data", parameterType = "String", parameterDes = "待签名数据") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.SIGNATURE, description = "签名后数据") })) Response signDigest(Map params); @CmdAnnotation(cmd = "ac_signBlockDigest", version = 1.0, description = "区块数据摘要签名/Block data digest signature") @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 = "data", parameterType = "String", parameterDes = "待签名数据") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.SIGNATURE, description = "签名后数据") })) Response signBlockDigest(Map params); @CmdAnnotation(cmd = "ac_verifySignData", version = 1.0, description = "验证数据签名/Verification Data Signature") @Parameters(value = { @Parameter(parameterName = "pubKey", parameterType = "String", parameterDes = "账户公钥"), @Parameter(parameterName = "sig", parameterType = "String", parameterDes = "签名"), @Parameter(parameterName = "data", parameterType = "String", parameterDes = "待签名数据") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.SIGNATURE, valueType = boolean.class, description = "签名是否正确") })) Response verifySignData(Map params);  }