use of io.nuls.core.chain.entity.Result in project nuls by nuls-io.
the class WalletResouce method unlock.
@POST
@Path("/unlock")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult unlock(@FormParam("password") String password, @FormParam("unlockTime") Integer unlockTime) {
AssertUtil.canNotEmpty(password, ErrorCode.NULL_PARAMETER);
AssertUtil.canNotEmpty(unlockTime);
if (unlockTime > MAX_UNLOCK_TIME) {
return RpcResult.getFailed("Unlock time should in a minute!");
}
Result result = accountService.unlockAccounts(password, unlockTime);
return new RpcResult(result);
}
use of io.nuls.core.chain.entity.Result in project nuls by nuls-io.
the class WalletResouce method importAccount.
@POST
@Path("/import")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult importAccount(AccountParamForm form) {
if (!StringUtils.validPassword(form.getPassword()) || StringUtils.isBlank(form.getPrikey()) || form.getPrikey().length() > 100) {
return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
}
NulsContext.CACHED_PASSWORD_OF_WALLET = form.getPassword();
Result result = null;
try {
result = accountService.importAccount(form.getPrikey(), form.getPassword());
} catch (Exception e) {
return RpcResult.getFailed(result.getErrorCode());
}
return new RpcResult(result);
}
use of io.nuls.core.chain.entity.Result 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;
}
use of io.nuls.core.chain.entity.Result in project nuls by nuls-io.
the class AccountTxDaoImpl method saveAlias.
@DbSession
@Override
public Result saveAlias(AliasPo alias) {
try {
aliasDao.save(alias);
AccountPo po = new AccountPo();
po.setAddress(alias.getAddress());
po.setAlias(alias.getAlias());
accountDao.updateAlias(po);
} catch (Exception e) {
throw new NulsRuntimeException(ErrorCode.DB_SAVE_ERROR);
}
return new Result(true, "OK");
}
Aggregations