use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.
the class GetDepositedInfoProcessor method execute.
@Override
public CommandResult execute(String[] args) {
String address = args[1];
RpcClientResult result = restFul.get("/consensus/address/" + address, null);
if (result.isFailed()) {
return CommandResult.getFailed(result);
}
Map<String, Object> map = (Map) result.getData();
map.put("usableBalance", CommandHelper.naToNuls(map.get("usableBalance")));
map.put("totalDeposit", CommandHelper.naToNuls(map.get("totalDeposit")));
map.put("reward", CommandHelper.naToNuls(map.get("reward")));
map.put("rewardOfDay", CommandHelper.naToNuls(map.get("rewardOfDay")));
result.setData(map);
return CommandResult.getResult(result);
}
use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.
the class GetAccountTxListProcessor method execute.
@Override
public CommandResult execute(String[] args) {
int type = 0;
int pageNumber = 0;
int pageSize = 0;
if (args.length == 4) {
pageNumber = Integer.parseInt(args[2]);
pageSize = Integer.parseInt(args[3]);
} else {
type = Integer.parseInt(args[2]);
pageNumber = Integer.parseInt(args[3]);
pageSize = Integer.parseInt(args[4]);
}
String address = args[1];
Map<String, Object> parameters = new HashMap<>();
parameters.put("type", type);
parameters.put("pageNumber", pageNumber);
parameters.put("pageSize", pageSize);
RpcClientResult result = restFul.get("/accountledger/tx/list/" + address, parameters);
if (result.isFailed()) {
return CommandResult.getFailed(result);
}
List<Map<String, Object>> list = (List<Map<String, Object>>) ((Map) result.getData()).get("list");
for (Map<String, Object> map : list) {
map.put("time", DateUtil.convertDate(new Date((Long) map.get("time"))));
map.put("txType", CommandHelper.txTypeExplain((Integer) map.get("txType")));
}
result.setData(list);
return CommandResult.getResult(result);
}
use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.
the class TransferProcessor method execute.
@Override
public CommandResult execute(String[] args) {
TransferForm form = paramsData.get();
if (null == form) {
form = getTransferForm(args);
}
String address = form.getAddress();
RpcClientResult res = CommandHelper.getPassword(address, restFul);
if (!res.isSuccess()) {
return CommandResult.getFailed(res);
}
String password = (String) res.getData();
Map<String, Object> parameters = new HashMap<>();
parameters.put("address", form.getAddress());
parameters.put("toAddress", form.getToAddress());
parameters.put("password", password);
parameters.put("amount", form.getAmount());
parameters.put("remark", form.getRemark());
RpcClientResult result = restFul.post("/accountledger/transfer", parameters);
if (result.isFailed()) {
return CommandResult.getFailed(result);
}
return CommandResult.getResult(CommandResult.dataTransformValue(result));
}
use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.
the class ContractTxTest method loadUTXOs.
public List<InputDto> loadUTXOs() {
String address = sender;
Long limit = 100L;
String url = "/utxo/limit/" + address + "/" + limit;
RpcClientResult result = restFul.get(url, new HashMap());
List<InputDto> utxos = new ArrayList<>();
Map data = (Map) result.getData();
List<Map<String, Object>> utxoList = (List<Map<String, Object>>) data.get("utxoDtoList");
for (Map<String, Object> utxo : utxoList) {
InputDto input = new InputDto();
input.setAddress(address);
input.setFromHash(utxo.get("txHash").toString());
input.setFromIndex((int) utxo.get("txIndex"));
input.setValue(Long.parseLong(utxo.get("value").toString()));
input.setLockTime(Long.valueOf(utxo.get("lockTime").toString()));
utxos.add(input);
}
return utxos;
}
use of io.nuls.kernel.model.RpcClientResult in project nuls by nuls-io.
the class ContractTxTest method callContract.
@Test
public void callContract() {
List<InputDto> utxos = loadUTXOs();
String url = "/contract/sdk/call";
String contractAddress = "NseA4LYf5kBXjrnag4xN8BjzgWx7YrVm";
String sender = this.sender;
Long value = 100_0000_0000L;
Long gasLimit = 81325l;
Long price = 25L;
String methodName = "create";
String methodDesc = "";
Object[] args = { "test", "test desc", Arrays.asList("1", "2", "3"), "1542042000000", "1542646800000", "false", "1", "1", "false" };
String remark = "test call contract";
Map<String, Object> paramsMap = new HashMap<>();
paramsMap.put("sender", sender);
paramsMap.put("value", value);
paramsMap.put("gasLimit", gasLimit);
paramsMap.put("price", price);
paramsMap.put("contractAddress", contractAddress);
paramsMap.put("methodName", methodName);
paramsMap.put("methodDesc", methodDesc);
paramsMap.put("args", args);
paramsMap.put("remark", remark);
paramsMap.put("utxos", utxos);
try {
logger.info("{}", JSONUtils.obj2json(paramsMap));
RpcClientResult result = restFul.post(url, paramsMap);
logger.info("result {}", result);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations