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