Search in sources :

Example 21 with RpcClientResult

use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.

the class GetTxProcessor method execute.

@Override
public CommandResult execute(String[] args) {
    String hash = args[1];
    if (StringUtils.isBlank(hash)) {
        return CommandResult.getFailed(KernelErrorCode.PARAMETER_ERROR.getMsg());
    }
    RpcClientResult result = restFul.get("/accountledger/tx/" + hash, null);
    if (result.isFailed()) {
        return CommandResult.getFailed(result);
    }
    Map<String, Object> map = (Map) result.getData();
    map.put("fee", CommandHelper.naToNuls(map.get("fee")));
    map.put("value", CommandHelper.naToNuls(map.get("value")));
    map.put("time", DateUtil.convertDate(new Date((Long) map.get("time"))));
    map.put("status", statusExplain((Integer) map.get("status")));
    map.put("type", CommandHelper.txTypeExplain((Integer) map.get("type")));
    List<Map<String, Object>> inputs = (List<Map<String, Object>>) map.get("inputs");
    for (Map<String, Object> input : inputs) {
        input.put("value", CommandHelper.naToNuls(input.get("value")));
    }
    map.put("inputs", inputs);
    List<Map<String, Object>> outputs = (List<Map<String, Object>>) map.get("outputs");
    for (Map<String, Object> output : outputs) {
        output.put("value", CommandHelper.naToNuls(output.get("value")));
        output.put("status", statusExplainForOutPut((Integer) output.get("status")));
    }
    map.put("outputs", outputs);
    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 22 with RpcClientResult

use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.

the class UtxoResource method getUtxoByAddressAndAmount.

@GET
@Path("/amount/{address}/{amount}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "根据address和amount查询UTXO")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = AccountUtxoDto.class) })
public RpcClientResult getUtxoByAddressAndAmount(@ApiParam(name = "address", value = "地址", required = true) @PathParam("address") String address, @ApiParam(name = "amount", value = "金额", required = true) @PathParam("amount") Long amount) {
    if (StringUtils.isBlank(address) || amount == 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);
        Na amountNa = Na.valueOf(amount.longValue());
        AccountUtxoDto accountUtxoDto = new AccountUtxoDto();
        List<UtxoDto> list = new LinkedList<>();
        Na values = Na.ZERO;
        for (Coin coin : coinList) {
            if (!coin.usable()) {
                continue;
            }
            if (coin.getNa().equals(Na.ZERO)) {
                continue;
            }
            list.add(new UtxoDto(coin));
            values = values.add(coin.getNa());
            if (values.isGreaterOrEquals(amountNa)) {
                break;
            }
        }
        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) Na(io.nuls.kernel.model.Na) 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 23 with RpcClientResult

use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.

the class CommandHelper method getPassword.

// /**
// * 根据账户获取密码
// * 1.如果账户有密码, 则让用户输入密码
// * 2.如果账户没有设置密码, 直接返回
// *
// * @param address
// * @param restFul
// * @param prompt 自定义提示
// * @return RpcClientResult
// */
public static RpcClientResult getPassword(String address, RestFulUtils restFul, String prompt) {
    if (StringUtils.isBlank(address)) {
        return RpcClientResult.getFailed("address is wrong");
    }
    RpcClientResult result = restFul.get("/account/encrypted/" + address, null);
    if (result.isSuccess()) {
        RpcClientResult rpcClientResult = new RpcClientResult();
        rpcClientResult.setSuccess(true);
        if (result.dataToBooleanValue()) {
            String pwd = getPwd(prompt);
            rpcClientResult.setData(pwd);
        }
        return rpcClientResult;
    }
    return result;
}
Also used : RpcClientResult(io.nuls.kernel.model.RpcClientResult)

Example 24 with RpcClientResult

use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.

the class CommandHelper method getContractCallArgsJson.

public static RpcClientResult getContractCallArgsJson() {
    RpcClientResult rpcClientResult = new RpcClientResult();
    rpcClientResult.setSuccess(true);
    try {
        Object[] argsObj;
        // 再次交互输入构造参数
        String argsJson = getArgsJson();
        argsObj = parseArgsJson(argsJson);
        rpcClientResult.setData(argsObj);
    } catch (Exception e) {
        e.printStackTrace();
        rpcClientResult.setSuccess(false);
    }
    return rpcClientResult;
}
Also used : RpcClientResult(io.nuls.kernel.model.RpcClientResult) IOException(java.io.IOException)

Example 25 with RpcClientResult

use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.

the class CreateProcessor method execute.

@Override
public CommandResult execute(String[] args) {
    String password = CommandHelper.getPwdOptional();
    if (StringUtils.isNotBlank(password)) {
        CommandHelper.confirmPwd(password);
    }
    int count = 1;
    if (args.length == 2) {
        count = Integer.parseInt(args[1]);
    }
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("password", password);
    parameters.put("count", count);
    RpcClientResult result = restFul.post("/account", parameters);
    if (result.isFailed()) {
        return CommandResult.getFailed(result);
    }
    return CommandResult.getResult(CommandResult.dataTransformList(result));
}
Also used : HashMap(java.util.HashMap) RpcClientResult(io.nuls.kernel.model.RpcClientResult)

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