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