Search in sources :

Example 16 with Result

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);
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) RpcResult(io.nuls.rpc.entity.RpcResult) Result(io.nuls.core.chain.entity.Result)

Example 17 with 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);
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) IOException(java.io.IOException) RpcResult(io.nuls.rpc.entity.RpcResult) Result(io.nuls.core.chain.entity.Result)

Example 18 with 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;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) List(java.util.List) RpcResult(io.nuls.rpc.entity.RpcResult) Result(io.nuls.core.chain.entity.Result)

Example 19 with Result

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");
}
Also used : AccountPo(io.nuls.db.entity.AccountPo) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) Result(io.nuls.core.chain.entity.Result) DbSession(io.nuls.db.transactional.annotation.DbSession)

Aggregations

Result (io.nuls.core.chain.entity.Result)19 ValidateResult (io.nuls.core.validate.ValidateResult)12 NulsException (io.nuls.core.exception.NulsException)10 Account (io.nuls.account.entity.Account)9 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)7 IOException (java.io.IOException)7 AccountPo (io.nuls.db.entity.AccountPo)5 RpcResult (io.nuls.rpc.entity.RpcResult)4 DbSession (io.nuls.db.transactional.annotation.DbSession)3 FileOutputStream (java.io.FileOutputStream)2 Alias (io.nuls.account.entity.Alias)1 AliasTransaction (io.nuls.account.entity.tx.AliasTransaction)1 NodeDownloadingStatus (io.nuls.consensus.entity.NodeDownloadingStatus)1 Block (io.nuls.core.chain.entity.Block)1 AliasPo (io.nuls.db.entity.AliasPo)1 TransactionPo (io.nuls.db.entity.TransactionPo)1 CoinTransferData (io.nuls.ledger.entity.params.CoinTransferData)1 TransactionEvent (io.nuls.ledger.event.TransactionEvent)1 List (java.util.List)1