Search in sources :

Example 11 with RpcClientResult

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

the class GetWalletContractsProcessor method execute.

@Override
public CommandResult execute(String[] args) {
    int pageNumber = Integer.parseInt(args[2]);
    int pageSize = Integer.parseInt(args[3]);
    String address = args[1];
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("pageNumber", pageNumber);
    parameters.put("pageSize", pageSize);
    String url = "/contract/wallet/list/" + address;
    RpcClientResult result = restFulUtils.get(url, parameters);
    if (result.isFailed()) {
        return CommandResult.getFailed(result);
    }
    return CommandResult.getResult(result);
}
Also used : HashMap(java.util.HashMap) RpcClientResult(io.nuls.kernel.model.RpcClientResult)

Example 12 with RpcClientResult

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

the class TransferToContractProcessor method execute.

/**
 * {
 * "address": "Nsdv1Hbu4TokdgbXreypXmVttYKdPT1g",
 * "toAddress": "NseDqffhWEB52a9cWfiyEhiP3wPGcjcJ",
 * "gasLimit": 800000,
 * "price": 27,
 * "password": "nuls123456",
 * "amount": 10000000,
 * "remark": ""
 * }
 *
 * @param args
 * @return
 */
@Override
public CommandResult execute(String[] args) {
    String address = args[1];
    if (StringUtils.isBlank(address)) {
        return CommandResult.getFailed(KernelErrorCode.PARAMETER_ERROR.getMsg());
    }
    RpcClientResult res = CommandHelper.getPassword(address, restFul);
    if (!res.isSuccess()) {
        return CommandResult.getFailed(res);
    }
    String password = (String) res.getData();
    /**
     * assemble request body JSON
     */
    Map<String, Object> parameters = new HashMap<>(7);
    parameters.put("address", address);
    parameters.put("toAddress", args[2]);
    parameters.put("gasLimit", args[3]);
    parameters.put("price", args[4]);
    parameters.put("amount", args[5]);
    if (args.length == 7) {
        parameters.put("remark", args[6]);
    }
    // password
    parameters.put("password", password);
    String url = "/contract/transfer";
    RpcClientResult result = restFul.post(url, parameters);
    if (result.isFailed()) {
        return CommandResult.getFailed(result);
    }
    return CommandResult.getResult(result);
}
Also used : HashMap(java.util.HashMap) RpcClientResult(io.nuls.kernel.model.RpcClientResult)

Example 13 with RpcClientResult

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

the class ViewContractProcessor method execute.

@Override
public CommandResult execute(String[] args) {
    ContractViewCall form = paramsData.get();
    if (null == form) {
        form = getContractViewCall(args);
    }
    if (null == form) {
        return CommandResult.getFailed("parameter error.");
    }
    RpcClientResult res = getContractCallArgsJson();
    if (!res.isSuccess()) {
        return CommandResult.getFailed(res);
    }
    Object[] contractArgs = (Object[]) res.getData();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("contractAddress", form.getContractAddress());
    parameters.put("methodName", form.getMethodName());
    parameters.put("methodDesc", form.getMethodDesc());
    parameters.put("args", contractArgs);
    RpcClientResult result = restFul.post("/contract/view", parameters);
    if (result.isFailed()) {
        return CommandResult.getFailed(result);
    }
    return CommandResult.getResult(result);
}
Also used : ContractViewCall(io.nuls.contract.rpc.form.ContractViewCall) HashMap(java.util.HashMap) RpcClientResult(io.nuls.kernel.model.RpcClientResult)

Example 14 with RpcClientResult

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

the class NetworkResource method getNetworkInfo.

// private NodeCacheManager nodeCacheManager = NodeCacheManager.getInstance();
@GET
@Path("/info/")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "查询网络最新信息")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = NetworkInfoDto.class) })
public RpcClientResult getNetworkInfo() {
    NetworkInfoDto info = new NetworkInfoDto(NulsContext.getInstance().getBestBlock().getHeader().getHeight(), NulsContext.getInstance().getNetBestBlockHeight(), TimeService.getNetTimeOffset());
    Collection<Node> collections = networkService.getAvailableNodes();
    int inCount = 0;
    int outCount = 0;
    for (Node node : collections) {
        if (node.getType() == Node.IN) {
            inCount++;
        } else {
            outCount++;
        }
    }
    info.setInCount(inCount);
    info.setOutCount(outCount);
    info.setMastUpGrade(NulsContext.mastUpGrade);
    Result result = Result.getSuccess();
    result.setData(info);
    return result.toRpcClientResult();
}
Also used : Node(io.nuls.network.model.Node) NetworkInfoDto(io.nuls.network.rpc.model.NetworkInfoDto) 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) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 15 with RpcClientResult

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

the class NetworkResource method getPeers.

@GET
@Path("/peers")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("查询节点[3.7.2]")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = NodeDto.class) })
public RpcClientResult getPeers() {
    List<Node> nodeList = networkService.getCanConnectNodes();
    Result result = Result.getSuccess();
    List<NodeDto> dtoList = new ArrayList<>();
    for (Node node : nodeList) {
        NodeDto dto = new NodeDto();
        dto.setIp(node.getIp());
        dto.setPort(node.getPort());
        dtoList.add(dto);
    }
    Map<String, List<NodeDto>> map = new HashMap<>();
    map.put("list", dtoList);
    result.setData(map);
    return result.toRpcClientResult();
}
Also used : Node(io.nuls.network.model.Node) NodeDto(io.nuls.network.rpc.model.NodeDto) 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) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

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