Search in sources :

Example 16 with RpcResult

use of io.nuls.rpc.entity.RpcResult in project nuls by nuls-io.

the class SystemResource method startModule.

@POST
@Path("/module/load")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult startModule(@FormParam("moduleName") String moduleName, @FormParam("moduleClass") String moduleClass) {
    // todo change the params to a form entity
    RpcResult result = null;
    do {
        ModuleService service = ModuleService.getInstance();
        AssertUtil.canNotEmpty(service, "System module service error!");
        try {
            service.startModule(moduleName, moduleClass);
        } catch (IllegalAccessException e) {
            Log.error(e);
            break;
        } catch (InstantiationException e) {
            Log.error(e);
            break;
        } catch (ClassNotFoundException e) {
            Log.error(e);
            break;
        }
        result = RpcResult.getSuccess();
    } while (false);
    return result;
}
Also used : ModuleService(io.nuls.core.module.service.ModuleService) RpcResult(io.nuls.rpc.entity.RpcResult)

Example 17 with RpcResult

use of io.nuls.rpc.entity.RpcResult in project nuls by nuls-io.

the class TransactionResource method list.

@GET
@Path("/locked")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult list(@QueryParam("address") String address, @QueryParam("pageNumber") int pageNumber, @QueryParam("pageSize") int pageSize) {
    if (!Address.validAddress(address)) {
        return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
    }
    if (pageNumber < 0 || pageSize < 0) {
        return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
    }
    if (pageNumber == 0) {
        pageNumber = 1;
    }
    if (pageSize == 0) {
        pageSize = 10;
    }
    // todo        ledgerService.getLockUtxo
    List<UtxoOutputPo> poList = outputDataService.getLockUtxo(address, TimeService.currentTimeMillis(), pageNumber, pageSize);
    List<OutputDto> dtoList = new ArrayList<>();
    for (UtxoOutputPo po : poList) {
        dtoList.add(new OutputDto(po));
    }
    RpcResult result = RpcResult.getSuccess();
    result.setData(dtoList);
    return result;
}
Also used : OutputDto(io.nuls.rpc.entity.OutputDto) ArrayList(java.util.ArrayList) RpcResult(io.nuls.rpc.entity.RpcResult) UtxoOutputPo(io.nuls.db.entity.UtxoOutputPo)

Example 18 with RpcResult

use of io.nuls.rpc.entity.RpcResult in project nuls by nuls-io.

the class TransactionResource method load.

@GET
@Path("/hash/{hash}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult load(@PathParam("hash") String hash) {
    RpcResult result = null;
    if (StringUtils.isBlank(hash)) {
        return RpcResult.getFailed(ErrorCode.NULL_PARAMETER);
    }
    try {
        Transaction tx = ledgerService.getTx(NulsDigestData.fromDigestHex(hash));
        if (tx == null) {
            result = RpcResult.getFailed("not found");
        } else {
            result = RpcResult.getSuccess();
            result.setData(new TransactionDto(tx));
        }
    } catch (NulsRuntimeException re) {
        Log.error(re);
        result = new RpcResult(false, re.getCode(), re.getMessage());
    } catch (Exception e) {
        Log.error(e);
        result = RpcResult.getFailed(ErrorCode.SYS_UNKOWN_EXCEPTION);
    }
    return result;
}
Also used : TransactionDto(io.nuls.rpc.entity.TransactionDto) Transaction(io.nuls.core.chain.entity.Transaction) RpcResult(io.nuls.rpc.entity.RpcResult) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 19 with RpcResult

use of io.nuls.rpc.entity.RpcResult in project nuls by nuls-io.

the class BlockResource method getHeader.

@GET
@Path("/header/hash/{hash}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getHeader(@PathParam("hash") String hash) throws NulsException, IOException {
    RpcResult result = RpcResult.getSuccess();
    BlockHeader blockHeader = blockService.getBlockHeader(hash);
    if (blockHeader == null) {
        return RpcResult.getFailed(ErrorCode.DATA_NOT_FOUND);
    }
    long reward = ledgerService.getBlockReward(blockHeader.getHeight());
    long fee = ledgerService.getBlockFee(blockHeader.getHeight());
    result.setData(new BlockDto(blockHeader, reward, fee));
    return result;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) BlockHeader(io.nuls.core.chain.entity.BlockHeader) BlockDto(io.nuls.rpc.entity.BlockDto)

Example 20 with RpcResult

use of io.nuls.rpc.entity.RpcResult in project nuls by nuls-io.

the class BlockResource method getHeaderByHeight.

@GET
@Path("/header/height/{height}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getHeaderByHeight(@PathParam("height") Integer height) throws NulsException, IOException {
    RpcResult result = RpcResult.getSuccess();
    BlockHeader blockHeader = blockService.getBlockHeader(height);
    if (blockHeader == null) {
        return RpcResult.getFailed(ErrorCode.DATA_NOT_FOUND);
    }
    long reward = ledgerService.getBlockReward(blockHeader.getHeight());
    long fee = ledgerService.getBlockFee(blockHeader.getHeight());
    result.setData(new BlockDto(blockHeader, reward, fee));
    return result;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) BlockHeader(io.nuls.core.chain.entity.BlockHeader) BlockDto(io.nuls.rpc.entity.BlockDto)

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