Search in sources :

Example 21 with RpcResult

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

the class BlockResource method getBlock.

@GET
@Path("/height/{height}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getBlock(@PathParam("height") Long height) {
    RpcResult result;
    if (height < 0) {
        return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
    }
    Block block = blockService.getBlock(height);
    if (block == null) {
        result = RpcResult.getFailed(ErrorCode.DATA_NOT_FOUND);
    } else {
        result = RpcResult.getSuccess();
        long reward = ledgerService.getBlockReward(block.getHeader().getHeight());
        long fee = ledgerService.getBlockFee(block.getHeader().getHeight());
        try {
            result.setData(new BlockDto(block, reward, fee));
        } catch (IOException e) {
            // todo
            e.printStackTrace();
        }
    }
    return result;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) Block(io.nuls.core.chain.entity.Block) IOException(java.io.IOException) BlockDto(io.nuls.rpc.entity.BlockDto)

Example 22 with RpcResult

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

the class NetworkMessageResource method getNode.

@GET
@Path("/nodes")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getNode() {
    Set<String> ipSet = networkService.getNodesIp();
    RpcResult result = RpcResult.getSuccess().setData(ipSet);
    return result;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 23 with RpcResult

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

the class NetworkMessageResource method getInfo.

@GET
@Path("/info")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getInfo() {
    RpcResult result = RpcResult.getSuccess();
    InfoDto info = new InfoDto(NulsContext.getInstance().getBestBlock().getHeader().getHeight(), NulsContext.getInstance().getNetBestBlockHeight(), TimeService.getNetTimeOffset());
    NodeGroup inGroup = networkService.getNodeGroup(NetworkConstant.NETWORK_NODE_IN_GROUP);
    NodeGroup outGroup = networkService.getNodeGroup(NetworkConstant.NETWORK_NODE_OUT_GROUP);
    int count = 0;
    for (Node node : inGroup.getNodes().values()) {
        if (node.getStatus() == Node.HANDSHAKE) {
            count += 1;
        }
    }
    info.setInCount(count);
    count = 0;
    for (Node node : outGroup.getNodes().values()) {
        if (node.getStatus() == Node.HANDSHAKE) {
            count += 1;
        }
    }
    info.setOutCount(count);
    result.setData(info);
    return result;
}
Also used : Node(io.nuls.network.entity.Node) RpcResult(io.nuls.rpc.entity.RpcResult) InfoDto(io.nuls.rpc.entity.InfoDto) NodeGroup(io.nuls.network.entity.NodeGroup) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 24 with RpcResult

use of io.nuls.rpc.entity.RpcResult 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 25 with RpcResult

use of io.nuls.rpc.entity.RpcResult 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)

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