@Override public boolean argsValidate(String[] args) { int length = args.length; if (length != 2) { return false; } if (!CommandHelper.checkArgsIsNull(args)) { return false; } return true; }
@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); } }
public static RpcClientResult getPassword(String address, RestFulUtils restFul) { return getPassword(address, restFul, null); }
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"))); input.put("value", CommandHelper.naToNuls(input.get("value"))); output.put("value", CommandHelper.naToNuls(output.get("value"))); output.put("status", statusExplainForOutPut((Integer) output.get("status"))); Map<String, Object> dataMap = (Map) txDataMap.get("data"); if(dataMap != null) { dataMap.put("value", CommandHelper.naToNuls(dataMap.get("value"))); dataMap.put("price", CommandHelper.naToNuls(dataMap.get("price"))); contractResultMap.put("totalFee", CommandHelper.naToNuls(contractResultMap.get("totalFee"))); contractResultMap.put("txSizeFee", CommandHelper.naToNuls(contractResultMap.get("txSizeFee"))); contractResultMap.put("actualContractFee", CommandHelper.naToNuls(contractResultMap.get("actualContractFee"))); contractResultMap.put("refundFee", CommandHelper.naToNuls(contractResultMap.get("refundFee"))); contractResultMap.put("value", CommandHelper.naToNuls(contractResultMap.get("value"))); contractResultMap.put("price", CommandHelper.naToNuls(contractResultMap.get("price"))); contractResultMap.put("balance", CommandHelper.naToNuls(contractResultMap.get("balance")));
@Override public CommandResult execute(String[] args) { String arg = args[1]; RpcClientResult result = null; if(StringUtils.isNumeric(arg)){ result = restFul.get("/block/height/" + arg, null); }else{ result = restFul.get("/block/hash/" + arg, null); } if (result.isFailed()) { return CommandResult.getFailed(result); } Map<String, Object> map = (Map) result.getData(); map.put("reward", CommandHelper.naToNuls(map.get("reward"))); map.put("fee", CommandHelper.naToNuls(map.get("fee"))); map.put("time", DateUtil.convertDate(new Date((Long) map.get("time")))); map.put("roundStartTime", DateUtil.convertDate(new Date((Long) map.get("roundStartTime")))); List<Map<String, Object>> txList = (List<Map<String, Object>>)map.get("txList"); for(Map<String, Object> tx : txList){ tx.put("type", CommandHelper.txTypeExplain((Integer)tx.get("type"))); tx.put("value", CommandHelper.naToNuls(tx.get("value"))); tx.put("status", CommandHelper.statusConfirmExplain((Integer)tx.get("status"))); tx.put("fee", CommandHelper.naToNuls(tx.get("fee"))); tx.put("time", DateUtil.convertDate(new Date((Long) tx.get("time")))); } map.put("txList", txList); result.setData(map); return CommandResult.getResult(result); }
@Override public CommandResult execute(String[] args) { String agentHash = args[1]; RpcClientResult result = restFul.get("/consensus/agent/" + agentHash, null); if (result.isFailed()) { return CommandResult.getFailed(result); } Map<String, Object> map = (Map) result.getData(); map.put("deposit", CommandHelper.naToNuls(map.get("deposit"))); map.put("totalDeposit", CommandHelper.naToNuls(map.get("totalDeposit"))); map.put("time", DateUtil.convertDate(new Date((Long) map.get("time")))); map.put("status", CommandHelper.consensusExplain((Integer) map.get("status"))); result.setData(map); return CommandResult.getResult(result); } }
@Override public CommandResult execute(String[] args) { String address = args[1]; RpcClientResult res = CommandHelper.getPassword(address, restFul, "Enter your old password:"); if(!res.isSuccess()){ return CommandResult.getFailed(res); } if(res.isSuccess() && null == res.getData()){ return CommandResult.getFailed("No password has been set up yet"); } String password = (String)res.getData(); String newPassword = CommandHelper.getNewPwd(); CommandHelper.confirmPwd(newPassword); Map<String, Object> parameters = new HashMap<>(); parameters.put("password", password); parameters.put("newPassword", newPassword); RpcClientResult result = restFul.put("/account/password/" + address, parameters); if(result.isFailed()){ return CommandResult.getFailed(result); } return CommandResult.getSuccess("Success"); } }
RpcClientResult res = CommandHelper.getPassword(sender, restFul); if(!res.isSuccess()){ return CommandResult.getFailed(res); res = getContractCallArgsJson(); if(!res.isSuccess()){ return CommandResult.getFailed(res);
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")));
@Override public CommandResult execute(String[] args) { String prikey = args[1]; String password = CommandHelper.getPwdOptional(); if(StringUtils.isNotBlank(password)){ CommandHelper.confirmPwd(password); } Map<String, Object> parameters = new HashMap<>(); parameters.put("priKey", prikey); parameters.put("password", password); parameters.put("overwrite", true); RpcClientResult result = restFul.post("/account/import/pri", parameters); if (result.isFailed()) { return CommandResult.getFailed(result); } return CommandResult.getResult(CommandResult.dataTransformValue(result)); }
public static String getPwd() { return getPwd(null); }
/** * 得到用户输入的密码,允许不输入 * 提示信息为默认 * * @return */ public static String getPwdOptional() { return getPwdOptional(null); }
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("type", CommandHelper.txTypeExplain((Integer)map.get("type"))); input.put("value", CommandHelper.naToNuls(input.get("value"))); output.put("value", CommandHelper.naToNuls(output.get("value"))); Map<String, Object> dataMap = (Map) txDataMap.get("data"); if(dataMap != null) { dataMap.put("value", CommandHelper.naToNuls(dataMap.get("value"))); dataMap.put("price", CommandHelper.naToNuls(dataMap.get("price"))); contractResultMap.put("totalFee", CommandHelper.naToNuls(contractResultMap.get("totalFee"))); contractResultMap.put("txSizeFee", CommandHelper.naToNuls(contractResultMap.get("txSizeFee"))); contractResultMap.put("actualContractFee", CommandHelper.naToNuls(contractResultMap.get("actualContractFee"))); contractResultMap.put("refundFee", CommandHelper.naToNuls(contractResultMap.get("refundFee"))); contractResultMap.put("value", CommandHelper.naToNuls(contractResultMap.get("value"))); contractResultMap.put("price", CommandHelper.naToNuls(contractResultMap.get("price"))); contractResultMap.put("balance", CommandHelper.naToNuls(contractResultMap.get("balance")));
@Override public CommandResult execute(String[] args) { int pageNumber = Integer.parseInt(args[1]); int pageSize = Integer.parseInt(args[2]); Map<String, Object> parameters = new HashMap<>(); parameters.put("pageNumber", pageNumber); parameters.put("pageSize", pageSize); RpcClientResult result = restFul.get("/consensus/agent/list", 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("deposit", CommandHelper.naToNuls(map.get("deposit"))); map.put("totalDeposit", CommandHelper.naToNuls(map.get("totalDeposit"))); map.put("time", DateUtil.convertDate(new Date((Long) map.get("time")))); map.put("status", CommandHelper.consensusExplain((Integer) map.get("status"))); } result.setData(list); return CommandResult.getResult(result); }
@Override public CommandResult execute(String[] args) { String prikey = args[1]; String password = CommandHelper.getPwdOptional(); if(StringUtils.isNotBlank(password)){ CommandHelper.confirmPwd(password); } Map<String, Object> parameters = new HashMap<>(); parameters.put("priKey", prikey); parameters.put("password", password); parameters.put("overwrite", false); RpcClientResult result = restFul.post("/account/import/pri", parameters); if (result.isFailed()) { return CommandResult.getFailed(result); } return CommandResult.getResult(CommandResult.dataTransformValue(result)); } }
@Override public CommandResult execute(String[] args) { String sender = args[1]; if (StringUtils.isBlank(sender)) { return CommandResult.getFailed(KernelErrorCode.PARAMETER_ERROR.getMsg()); } String password = CommandHelper.getPwd(); /** * assemble request body JSON */ Map<String, Object> parameters = new HashMap<>(3); parameters.put("sender", args[1]); parameters.put("contractAddress", args[2]); parameters.put("password", password); String url = "/contract/delete"; RpcClientResult result = restFulUtils.post(url, parameters); if (result.isFailed()) { return CommandResult.getFailed(result); } return CommandResult.getResult(result); } }
@Override public CommandResult execute(String[] args) { String path = args[1]; String password = CommandHelper.getPwdOptional(); Result rs = getAccountKeystoreDto(path); if(rs.isFailed()){ return CommandResult.getFailed(rs.getMsg()); } AccountKeyStoreDto accountKeyStoreDto = (AccountKeyStoreDto)rs.getData(); Map<String, Object> parameters = new HashMap<>(); parameters.put("accountKeyStoreDto", accountKeyStoreDto); parameters.put("password", password); parameters.put("overwrite", false); RpcClientResult result = restFul.post("/account/import", parameters); if(result.isFailed()){ return CommandResult.getFailed(result); } return CommandResult.getResult(CommandResult.dataTransformValue(result)); }
@Override public boolean argsValidate(String[] args) { int length = args.length; if (length != 2) { return false; } if (!CommandHelper.checkArgsIsNull(args)) { return false; } return true; }
@Override public CommandResult execute(String[] args) { String signAddress = args[2]; RpcClientResult res = CommandHelper.getPassword(signAddress, restFul); if(!res.isSuccess()){ return CommandResult.getFailed(res); } String password = (String)res.getData(); Map<String, Object> parameters = new HashMap<>(); parameters.put("address", args[1]); parameters.put("signAddress", args[2]); if(args.length == 4){ parameters.put("txdata",args[3]); }else{ String[] pubkeys = args[3].split(","); parameters.put("pubkeys", Arrays.asList(pubkeys)); parameters.put("m",Integer.parseInt(args[4])); parameters.put("txHash",Integer.parseInt(args[5])); } RpcClientResult result = restFul.post("/consensus/withdrawMutil", parameters); if (result.isFailed()) { return CommandResult.getFailed(result); } return CommandResult.getResult(CommandResult.dataTransformValue(result)); } }
@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); RpcClientResult result = restFul.get("/accountledger/utxo/lock/" + 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("value", CommandHelper.naToNuls(map.get("value"))); map.put("createTime", DateUtil.convertDate(new Date((Long)map.get("createTime")))); map.put("txType", CommandHelper.txTypeExplain((Integer)map.get("txType"))); } result.setData(list); return CommandResult.getResult(result); } }