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