Search in sources :

Example 71 with RpcClientResult

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();
}
Also used : RpcClientResult(io.nuls.kernel.model.RpcClientResult) RandomSeedDTO(io.nuls.consensus.poc.rpc.model.RandomSeedDTO)

Example 72 with RpcClientResult

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();
    }
}
Also used : Coin(io.nuls.kernel.model.Coin) NulsException(io.nuls.kernel.exception.NulsException) RpcClientResult(io.nuls.kernel.model.RpcClientResult) Result(io.nuls.kernel.model.Result) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 73 with RpcClientResult

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);
}
Also used : RpcClientResult(io.nuls.kernel.model.RpcClientResult) List(java.util.List) Map(java.util.Map) Date(java.util.Date)

Example 74 with RpcClientResult

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);
}
Also used : RpcClientResult(io.nuls.kernel.model.RpcClientResult) Map(java.util.Map) Date(java.util.Date)

Example 75 with RpcClientResult

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);
}
Also used : RpcClientResult(io.nuls.kernel.model.RpcClientResult) Map(java.util.Map) Date(java.util.Date)

Aggregations

RpcClientResult (io.nuls.kernel.model.RpcClientResult)88 HashMap (java.util.HashMap)49 Map (java.util.Map)24 Date (java.util.Date)14 List (java.util.List)14 Result (io.nuls.kernel.model.Result)7 InputDto (io.nuls.accout.ledger.rpc.dto.InputDto)5 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 NulsException (io.nuls.kernel.exception.NulsException)3 Na (io.nuls.kernel.model.Na)3 Node (io.nuls.network.model.Node)3 Test (org.junit.Test)3 RandomSeedDTO (io.nuls.consensus.poc.rpc.model.RandomSeedDTO)2 Coin (io.nuls.kernel.model.Coin)2 IOException (java.io.IOException)2 AccountKeyStoreDto (io.nuls.account.rpc.model.AccountKeyStoreDto)1