use of io.nuls.rpc.entity.RpcResult in project nuls by nuls-io.
the class WalletResouce method importAccountFile.
@POST
@Path("/imports")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public RpcResult importAccountFile(@FormDataParam("file") InputStream in, @FormDataParam("file") FormDataContentDisposition disposition, @FormDataParam("password") String password) {
if (in == null || disposition == null || !StringUtils.validPassword(password)) {
return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
}
String fileName = disposition.getFileName();
if (!fileName.endsWith(".nuls")) {
return RpcResult.getFailed("File suffix name is wrong");
}
if (!StringUtils.validPassword(password)) {
return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
}
Map<String, Object> map = getFileContent(in);
if (map == null) {
return RpcResult.getFailed(ErrorCode.FILE_BROKEN);
}
List<String> keys = (List<String>) map.get("keys");
String md5 = (String) map.get("password");
if (keys == null || keys.isEmpty() || StringUtils.isBlank(md5)) {
return RpcResult.getFailed(ErrorCode.FILE_BROKEN);
}
if (!MD5Util.md5(password).equals(md5)) {
return RpcResult.getFailed(ErrorCode.PASSWORD_IS_WRONG);
}
Result result = accountService.importAccounts(keys, password);
RpcResult rpcResult = new RpcResult(result);
return rpcResult;
}
Aggregations