Search in sources :

Example 26 with RpcResult

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;
}
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)

Aggregations

RpcResult (io.nuls.rpc.entity.RpcResult)26 HashMap (java.util.HashMap)6 BlockDto (io.nuls.rpc.entity.BlockDto)5 Result (io.nuls.core.chain.entity.Result)4 Map (java.util.Map)4 IOException (java.io.IOException)3 Block (io.nuls.core.chain.entity.Block)2 BlockHeader (io.nuls.core.chain.entity.BlockHeader)2 Transaction (io.nuls.core.chain.entity.Transaction)2 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)2 UtxoOutputPo (io.nuls.db.entity.UtxoOutputPo)2 TransactionDto (io.nuls.rpc.entity.TransactionDto)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Page (io.nuls.core.dto.Page)1 ModuleService (io.nuls.core.module.service.ModuleService)1 AgentPo (io.nuls.db.entity.AgentPo)1