private static void finish() { finish(reporter.getErrors().size()); }
private static void doProbe() throws IOException { List<String> sources = new ArrayList<String>((List) options.valuesOf("probe")); List<String> nonOptions = new ArrayList<String>((List) options.nonOptionArguments()); for (String opt : nonOptions) { sources.addAll(asList(opt.split(","))); } cleanNonOptionalArguments(sources); for (int s = 0; s < sources.size(); s++) { String source = sources.get(s); ItemResult ir = getClientNetwork().check(source); // report("Universa network has reported the state:"); // report(ir.toString()); } finish(); }
private static void doReserveUforUTN() throws IOException { String utnPath = (String) options.valueOf("u-for-utn"); List<String> names = (List) options.valuesOf("output"); int amount = (int) options.valueOf("amount"); String uPath = reserveUforUTN(utnPath,names.size() > 0 ? names.get(0) : null,amount); if(uPath != null) { System.out.println(amount + "U successfully purchased! Path to U contract is : " + uPath); } finish(); }
private static void doShowHash() throws Exception { String file = (String) options.valueOf("hash"); reporter.message(HashId.of(Files.readAllBytes(Paths.get(file))).toBase64String()); finish(); }
private static void doShowId() throws Exception { String contractFile = (String) options.valueOf("id"); Contract c = Contract.fromPackedTransaction(Files.readAllBytes(Paths.get(contractFile))); reporter.message(c.getId().toBase64String()); finish(); }
private static void doProbeFile() throws IOException { String contractFile = (String) options.valueOf("probe-file"); Contract c = Contract.fromPackedTransaction(Files.readAllBytes(Paths.get(contractFile))); if(c != null) { getClientNetwork().check(c.getId()); } finish(); }
private static void doResync() throws IOException { List<String> sources = new ArrayList<String>((List) options.valuesOf("resync")); List<String> nonOptions = new ArrayList<String>((List) options.nonOptionArguments()); for (String opt : nonOptions) { sources.addAll(asList(opt.split(","))); } cleanNonOptionalArguments(sources); for (int s = 0; s < sources.size(); s++) { String source = sources.get(s); ItemResult ir = getClientNetwork().resync(source); report("Node has reported the state:"); report(ir.toString()); } finish(); }
private static void doSign() throws IOException { String source = (String) options.valueOf("sign"); List<String> names = (List) options.valuesOf("output"); Contract c = Contract.fromPackedTransaction(Files.readAllBytes(Paths.get(source))); if(c != null) { keysMap().values().forEach( k -> c.addSignatureToSeal(k)); String name; if(names.size() > 0) { name = names.get(0); } else { String suffix = "_signedby_"+String.join("_",c.getSealedByKeys().stream().map(k->k.getShortAddress().toString()).collect(Collectors.toSet())); name = new FilenameTool(source).addSuffixToBase(suffix).toString(); } saveContract(c,name,true,false); } finish(); }
private static void doRegisterParcel() throws IOException { List<String> sources = new ArrayList<String>((List) options.valuesOf("register-parcel")); List<String> nonOptions = new ArrayList<String>((List) options.nonOptionArguments()); for (String opt : nonOptions) { sources.addAll(asList(opt.split(","))); } cleanNonOptionalArguments(sources); for (int s = 0; s < sources.size(); s++) { String source = sources.get(s); Parcel parcel = loadParcel(source); if (parcel != null) { ItemResult ir = registerParcel(parcel, (int) options.valueOf("wait")); if(ir.state != ItemState.APPROVED) { addErrors(ir.errors); } } } finish(); }
private static void doFindContracts() throws IOException { List<String> sources = new ArrayList<String>((List) options.valuesOf("f")); List<String> nonOptions = new ArrayList<String>((List) options.nonOptionArguments()); for (String opt : nonOptions) { sources.addAll(asList(opt.split(","))); } cleanNonOptionalArguments(sources); for (int s = 0; s < sources.size(); s++) { String source = sources.get(s); report("Looking for contracts at the " + source); HashMap<String, Contract> allFoundContracts = findContracts(source, options.has("r")); List<Wallet> wallets = Wallet.determineWallets(new ArrayList<>(allFoundContracts.values())); if (wallets.size() > 0) { printWallets(wallets); } else { report("No wallets found"); } if (allFoundContracts.size() > 0) { printContracts(allFoundContracts); } else { report("No contracts found"); } } finish(); }
private static void doAnonymize() throws IOException { List<String> sources = new ArrayList<String>((List) options.valuesOf("anonymize")); List<String> roles = new ArrayList<String>((List) options.valuesOf("role")); List<String> names = (List) options.valuesOf("output"); List<String> nonOptions = new ArrayList<String>((List) options.nonOptionArguments()); for (String opt : nonOptions) { sources.addAll(asList(opt.split(","))); } cleanNonOptionalArguments(sources); for (int s = 0; s < sources.size(); s++) { String source = sources.get(s); Contract contract = loadContract(source); if (contract != null) { if(roles.size() <= 0) { roles = new ArrayList<>(contract.getRoles().keySet()); } for (String roleName : roles) { report("Anonymizing role " + roleName + " in " + source + "..."); contract.anonymizeRole(roleName); contract.seal(); } if (names.size() > s) { saveContract(contract, names.get(s), true, false); } else { saveContract(contract, new FilenameTool(source).addSuffixToBase("_anonymized").toString(), true, false); } } } finish(); }
private static void doGetURate() throws IOException { BasicHttpClient httpClient = new BasicHttpClient(URS_ROOT_URL); BasicHttpClient.Answer answer = httpClient.commonRequest("uutn/info"); System.out.println("Current U per UTN rate is " + answer.data.getBinder("rates").getString("U_UTN")); System.out.println("Minimum U to reserve " + answer.data.getBinder("limits").getBinder("U").getString("min")); System.out.println("Maximum U to reserve " + answer.data.getBinder("limits").getBinder("U").getString("max")); finish(); }
private static void doCreateAddress(String keyFilePath, boolean bShort) throws IOException { report("Generate " + (bShort ? "short" : "long") + " address from key: " + keyFilePath); PublicKey key = readKeyAndGetPublic(keyFilePath); KeyAddress address = new KeyAddress(key, 0, !bShort); report("Address: " + address.toString()); finish(); }
private static void doAddressMatch(String address, String keyFilePath) throws IOException { boolean bResult = false; try { PublicKey key = readKeyAndGetPublic(keyFilePath); KeyAddress keyAddress = new KeyAddress(address); bResult = keyAddress.isMatchingKey(key); } catch (Exception e) {}; report("Matching address: " + address + " with key: "+ keyFilePath); report("Matching result: " + bResult); finish(); }
private static void doSetLogLevels() { List<String> sources = new ArrayList<String>((List) options.valuesOf("set-log-levels")); if(sources.size() != 3) { addError(Errors.COMMAND_FAILED.name(),"levels", "specify 3 log levels: node,network,udp"); } try { ItemResult ir = getClientNetwork().client.setVerboseLevel(DatagramAdapter.VerboseLevel.stringToInt(sources.get(0)), DatagramAdapter.VerboseLevel.stringToInt(sources.get(1)), DatagramAdapter.VerboseLevel.stringToInt(sources.get(2))); addErrors(ir.errors); } catch (ClientError clientError) { if (options.has("verbose")) clientError.printStackTrace(); addError(Errors.COMMAND_FAILED.name(),"levels",clientError.getMessage()); } catch (IOException e) { if (options.has("verbose")) e.printStackTrace(); addError(Errors.COMMAND_FAILED.name(),"levels",e.getMessage()); } finish(); }
private static void doExecJs() throws Exception { String contractFile = (String) options.valueOf("exec-js"); String scriptName = null; if (options.has("script-name")) scriptName = (String)options.valueOf("script-name"); Contract c = Contract.fromPackedTransaction(Files.readAllBytes(Paths.get(contractFile))); if(c != null) { ItemResult itemResult = getClientNetwork().client.getState(c.getId(), reporter); if (itemResult.state == ItemState.APPROVED) { if (scriptName != null) { c.execJSByName(scriptName); } else { List<String> scriptNames = c.extractJSNames(); if (scriptNames.size() == 1) c.execJSByName(scriptNames.get(0)); else if (scriptNames.size() > 1) report("error: contract has " + scriptNames.size() + " scripts attached, specify script filename please"); else report("error: contract has no scripts attached"); } } else { report("error: contract should be approved"); } } finish(); }
private static void doStartHttpServer(String routeFilePath) throws IOException { try { cliServices.startJsApiHttpServer( routeFilePath, hashId -> { try { return getClientNetwork().check(hashId).state == ItemState.APPROVED; } catch (IOException e) { report("error while checking contract for approve: " + e); return false; } }, (slotId, originId) -> { try { if (slotId == null) return null; return getClientNetwork().client.queryContract(slotId, originId, null); } catch (IOException e) { report("error while querying contract from slot1: " + e); return null; } }); } catch (Exception e) { report("http server error: " + e); } finish(); }