use of io.nuls.account.rpc.model.AccountKeyStoreDto in project nuls by nuls-io.
the class ImportByKeyStoreProcessor method getAccountKeystoreDto.
/**
* 根据文件地址获取AccountKeystoreDto对象
* Gets the AccountKeystoreDto object based on the file address
* @param path
* @return
*/
private Result<AccountKeyStoreDto> getAccountKeystoreDto(String path) {
File file = null;
try {
file = new File(URLDecoder.decode(path, "UTF-8"));
} catch (UnsupportedEncodingException e) {
Log.error(e);
}
if (null != file && file.isFile()) {
StringBuilder ks = new StringBuilder();
BufferedReader bufferedReader = null;
String str;
try {
bufferedReader = new BufferedReader(new FileReader(file));
while ((str = bufferedReader.readLine()) != null) {
if (!str.isEmpty()) {
ks.append(str);
}
}
AccountKeyStoreDto accountKeyStoreDto = JSONUtils.json2pojo(ks.toString(), AccountKeyStoreDto.class);
return Result.getSuccess().setData(accountKeyStoreDto);
} catch (FileNotFoundException e) {
return Result.getFailed(AccountErrorCode.ACCOUNTKEYSTORE_FILE_NOT_EXIST);
} catch (IOException e) {
return Result.getFailed(AccountErrorCode.ACCOUNTKEYSTORE_FILE_DAMAGED);
} catch (Exception e) {
return Result.getFailed(AccountErrorCode.ACCOUNTKEYSTORE_FILE_DAMAGED);
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
Log.error(e);
}
}
}
}
return Result.getFailed(AccountErrorCode.ACCOUNTKEYSTORE_FILE_NOT_EXIST);
}
use of io.nuls.account.rpc.model.AccountKeyStoreDto in project nuls by nuls-io.
the class ImportByKeyStoreProcessor method execute.
@Override
public CommandResult execute(String[] args) {
String path = args[1];
String password = CommandHelper.getPwdOptional();
Result rs = getAccountKeystoreDto(path);
if (rs.isFailed()) {
return CommandResult.getFailed(rs.getMsg());
}
AccountKeyStoreDto accountKeyStoreDto = (AccountKeyStoreDto) rs.getData();
Map<String, Object> parameters = new HashMap<>();
parameters.put("accountKeyStoreDto", accountKeyStoreDto);
parameters.put("password", password);
parameters.put("overwrite", false);
RpcClientResult result = restFul.post("/account/import", parameters);
if (result.isFailed()) {
return CommandResult.getFailed(result);
}
return CommandResult.getResult(CommandResult.dataTransformValue(result));
}
Aggregations