use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.
the class VMContext method getRandomSeed.
public String getRandomSeed(long endHeight, int count, String algorithm) {
RpcClientResult seedByCount = randomSeedResource.getSeedByCount(endHeight, count, algorithm);
if (seedByCount.isFailed()) {
Log.error(seedByCount.toString());
return null;
}
RandomSeedDTO dto = (RandomSeedDTO) seedByCount.getData();
return dto.getSeed();
}
use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.
the class UtxoResource method getUtxoByAddressAndLimit.
@GET
@Path("/limit/{address}/{limit}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "根据address和limit查询UTXO")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = AccountUtxoDto.class) })
public RpcClientResult getUtxoByAddressAndLimit(@ApiParam(name = "address", value = "地址", required = true) @PathParam("address") String address, @ApiParam(name = "limit", value = "数量", required = true) @PathParam("limit") Integer limit) {
if (StringUtils.isBlank(address) || limit == null) {
return Result.getFailed(LedgerErrorCode.NULL_PARAMETER).toRpcClientResult();
}
if (!AddressTool.validAddress(address)) {
return Result.getFailed(LedgerErrorCode.PARAMETER_ERROR).toRpcClientResult();
}
Result result = null;
try {
List<Coin> coinList = getAllUtxoByAddress(address);
int limitValue = limit.intValue();
boolean isLoadAll = (limitValue == 0);
AccountUtxoDto accountUtxoDto = new AccountUtxoDto();
List<UtxoDto> list = new LinkedList<>();
int i = 0;
for (Coin coin : coinList) {
if (!coin.usable()) {
continue;
}
if (coin.getNa().equals(Na.ZERO)) {
continue;
}
if (!isLoadAll) {
if (i >= limitValue) {
break;
}
i++;
}
list.add(new UtxoDto(coin));
}
accountUtxoDto.setUtxoDtoList(list);
result = Result.getSuccess().setData(accountUtxoDto);
return result.toRpcClientResult();
} catch (Exception e) {
Log.error(e);
result = Result.getFailed(LedgerErrorCode.SYS_UNKOWN_EXCEPTION);
return result.toRpcClientResult();
}
}
use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.
the class GetBlockProcessor method execute.
@Override
public CommandResult execute(String[] args) {
String arg = args[1];
RpcClientResult result = null;
if (StringUtils.isNumeric(arg)) {
result = restFul.get("/block/height/" + arg, null);
} else {
result = restFul.get("/block/hash/" + arg, null);
}
if (result.isFailed()) {
return CommandResult.getFailed(result);
}
Map<String, Object> map = (Map) result.getData();
map.put("reward", CommandHelper.naToNuls(map.get("reward")));
map.put("fee", CommandHelper.naToNuls(map.get("fee")));
map.put("time", DateUtil.convertDate(new Date((Long) map.get("time"))));
map.put("roundStartTime", DateUtil.convertDate(new Date((Long) map.get("roundStartTime"))));
List<Map<String, Object>> txList = (List<Map<String, Object>>) map.get("txList");
for (Map<String, Object> tx : txList) {
tx.put("type", CommandHelper.txTypeExplain((Integer) tx.get("type")));
tx.put("value", CommandHelper.naToNuls(tx.get("value")));
tx.put("status", CommandHelper.statusConfirmExplain((Integer) tx.get("status")));
tx.put("fee", CommandHelper.naToNuls(tx.get("fee")));
tx.put("time", DateUtil.convertDate(new Date((Long) tx.get("time"))));
}
map.put("txList", txList);
result.setData(map);
return CommandResult.getResult(result);
}
use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.
the class GetBestBlockHeaderProcessor method execute.
@Override
public CommandResult execute(String[] args) {
RpcClientResult result = restFul.get("/block/newest/", null);
if (result.isFailed()) {
return CommandResult.getFailed(result);
}
Map<String, Object> map = (Map) result.getData();
map.put("reward", CommandHelper.naToNuls(map.get("reward")));
map.put("fee", CommandHelper.naToNuls(map.get("fee")));
map.put("time", DateUtil.convertDate(new Date((Long) map.get("time"))));
map.put("roundStartTime", DateUtil.convertDate(new Date((Long) map.get("roundStartTime"))));
result.setData(map);
return CommandResult.getResult(result);
}
use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.
the class GetBlockHeaderProcessor method execute.
@Override
public CommandResult execute(String[] args) {
String hash = null;
long height = 0;
if (StringUtils.isBlank(args[1])) {
return CommandResult.getFailed(KernelErrorCode.PARAMETER_ERROR.getMsg());
}
try {
height = Long.parseLong(args[1]);
} catch (Exception e) {
hash = args[1];
}
RpcClientResult result = null;
if (hash != null) {
result = restFul.get("/block/header/hash/" + hash, null);
} else {
result = restFul.get("/block/header/height/" + height, null);
}
if (result.isFailed()) {
return CommandResult.getFailed(result);
}
Map<String, Object> map = (Map) result.getData();
map.put("reward", CommandHelper.naToNuls(map.get("reward")));
map.put("fee", CommandHelper.naToNuls(map.get("fee")));
map.put("time", DateUtil.convertDate(new Date((Long) map.get("time"))));
map.put("roundStartTime", DateUtil.convertDate(new Date((Long) map.get("roundStartTime"))));
result.setData(map);
return CommandResult.getResult(result);
}
Aggregations