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 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(); }
static public void saveSession() throws IOException { if( clientNetwork != null) { int nodeNumber = getClientNetwork().getNodeNumber(); reporter.verbose("Session from ClientNetwork is exist: " + (session != null)); if (session != null) { Path keysDir = Paths.get(System.getProperty("user.home") + "/.universa"); if (!Files.exists(keysDir)) { reporter.verbose("creating new keys directory: " + keysDir.toString()); final Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwx------"); final FileAttribute<Set<PosixFilePermission>> ownerOnly = PosixFilePermissions.asFileAttribute(perms); Files.createDirectory(keysDir, ownerOnly); } Path sessionFile = keysDir.resolve("node_" + nodeNumber + ".session"); try (OutputStream out = Files.newOutputStream(sessionFile)) { out.write(Boss.pack(session.asBinder())); } final Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rw-------"); try { Files.setPosixFilePermissions(sessionFile, perms); } catch (UnsupportedOperationException x) { // fucking windows :( have no idea what to do with it } prefs.put("session_" + nodeNumber, sessionFile.toString()); // report("Session has been stored to the " + keysDir + "/" + sessionFile); } } }
ItemState state = getClientNetwork().check(utn.getId()).state; System.out.println("Checking " + wallet.utnPathes.get(id)); if(state == ItemState.APPROVED) { List<Contract> candidates = contractsInPath.values().stream().filter(c -> c.getId().equals(utn.getParent())).collect(Collectors.toList()); for(Contract candidate : candidates) { if (getClientNetwork().check(candidate.getId()).state == ItemState.APPROVED) { Files.write(Paths.get(walletPath + File.separator + wallet.utnPathes.get(id)), candidate.getLastSealedBinary(), StandardOpenOption.TRUNCATE_EXISTING); utnsToAdd.put(candidate.getId(), candidate); System.out.println("Checking " + wallet.uPathes.get(id)); Contract ucontract = wallet.us.get(id); ItemState state = getClientNetwork().check(ucontract.getId()).state; if(state == ItemState.APPROVED) { continue; List<Contract> candidates = contractsInPath.values().stream().filter(c -> c.getOrigin().equals(ucontract.getOrigin())).collect(Collectors.toList()); for(Contract candidate : candidates) { if (getClientNetwork().check(candidate.getId()).state == ItemState.APPROVED) { Files.write(Paths.get(walletPath + File.separator + wallet.uPathes.get(id)), candidate.getLastSealedBinary(), StandardOpenOption.TRUNCATE_EXISTING); usToAdd.put(candidate.getId(), candidate);
private static String getUFromWallet(UUTNWallet wallet, int amount,boolean isTest) throws IOException { if(wallet == null) { System.out.println("UUTN wallet not found"); return null; } String fieldName = isTest ? "test_transaction_units" : "transaction_units"; int minAcceptableBalance = 0; HashId acceptableContractId = null; for(HashId uIds : wallet.us.keySet()) { Contract ucontract = wallet.us.get(uIds); int unitsCount = ucontract.getStateData().getIntOrThrow(fieldName); if(unitsCount >= amount && (minAcceptableBalance > unitsCount || acceptableContractId == null)) { minAcceptableBalance = unitsCount; acceptableContractId =uIds; } } String acceptableContract = acceptableContractId == null ? null : wallet.uPathes.get(acceptableContractId); if(acceptableContract == null) { addError(Errors.NOT_FOUND.name(),"U contract", "U contract is not found in UUTN wallet."); return null; } else { System.out.println("U contract is found in UUTN wallet: " + acceptableContract); System.out.println("Checking status..."); if(getClientNetwork().check(wallet.us.get(acceptableContractId).getId()).state != ItemState.APPROVED) { return getUFromWallet(fixUUTNWallet(wallet.path),amount,isTest); } } return wallet.path + File.separator + acceptableContract; } private static String getUFromWallet(int amount,boolean isTest) throws IOException {
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(); }
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(); }
utn = wallet.utnPathes.get(id); System.out.println("Found UTN contract with required amount. Checking status..."); if(getClientNetwork().check(id).state != ItemState.APPROVED) { System.out.println("Wallet needs to recover. Skipping auto purchase for now."); return fixUUTNWallet(walletPath);
/** * Register a specified contract. * * @param contract must be a sealed binary. * @param waitTime - wait time for responce. * @param fromPackedTransaction - register contract with Contract.getPackedTransaction() */ @Deprecated public static void registerContract(Contract contract, int waitTime, Boolean fromPackedTransaction) throws IOException { // checkContract(contract); List<ErrorRecord> errors = contract.getErrors(); if (errors.size() > 0) { report("contract has errors and can't be submitted for registration"); report("contract id: " + contract.getId().toBase64String()); addErrors(errors); } else { // contract.seal(); ItemResult r; if (fromPackedTransaction) { r = getClientNetwork().register(contract.getPackedTransaction(), waitTime); } else { r = getClientNetwork().register(contract.getLastSealedBinary(), waitTime); } report("submitted with result:"); report(r.toString()); } }
/** * Register a specified parcel. * @param parcel must be ready for register * @param waitTime wait time for responce. * @return ItemResult for parcel's payload * @throws IOException */ public static ItemResult registerParcel(Parcel parcel, int waitTime) throws IOException { getClientNetwork().registerParcel(parcel.pack(), waitTime); ItemResult r = getClientNetwork().check(parcel.getPayloadContract().getId()); report("paid contract " + parcel.getPayloadContract().getId() + " submitted with result: " + r.toString()); report("payment became " + parcel.getPaymentContract().getId()); report("payment rev 1 " + parcel.getPaymentContract().getRevoking().get(0).getId()); return r; }
if(getClientNetwork().check(contract.getId()).state != ItemState.APPROVED) { addError(Errors.FORBIDDEN.name(),contractPath,"contract is not approved"); continue; if(getClientNetwork().check(contract.getId()).state != ItemState.APPROVED) { addError(Errors.FORBIDDEN.name(),contractPath,"contract is not approved"); continue;
protected static String getApprovedUContract() throws Exception { synchronized (uContractLock) { if (uContract == null) { PrivateKey manufacturePrivateKey = new PrivateKey(Do.read(rootPath + "keys/u_key.private.unikey")); Contract stepaU = Contract.fromDslFile(rootPath + "StepaU.yml"); stepaU.addSignerKey(manufacturePrivateKey); stepaU.seal(); stepaU.check(); //stepaU.setIsU(true); stepaU.traceErrors(); Files.deleteIfExists(Paths.get(basePath + "stepaU.unicon")); CLIMain.saveContract(stepaU, basePath + "stepaU.unicon"); System.out.println("--- register new u --- " + stepaU.getId()); Client client = CLIMain.getClientNetwork().client; client.register(stepaU.getPackedTransaction(), 5000); //callMain2("--register", basePath + "stepaU.unicon", "-v", "-wait", "5000"); uContract = stepaU; } return basePath + "stepaU.unicon"; } }
ClientNetwork n = getClientNetwork(); System.out.println(); report("revoking item exists: " + r.getId().toBase64String());
contract_for_payment.traceErrors(); CLIMain.getClientNetwork().client.register(contract_for_payment.getPackedTransaction(), 5000); ItemResult itemResult = CLIMain.getClientNetwork().client.getState(contract_for_payment); System.out.println("contract_for_payment: " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); "-wait", "80000", "-v"); itemResult = CLIMain.getClientNetwork().client.getState(escrow); System.out.println("escrow: " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); itemResult = CLIMain.getClientNetwork().client.getState(contract_for_payment); System.out.println("contract_for_payment: " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); "-wait", "80000", "-v"); itemResult = CLIMain.getClientNetwork().client.getState(completedEscrow); System.out.println("completedEscrow: " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); itemResult = CLIMain.getClientNetwork().client.getState(newPayment); System.out.println("newPayment: " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state);
contract_for_payment.traceErrors(); CLIMain.getClientNetwork().client.register(contract_for_payment.getPackedTransaction(), 5000); "-wait", "80000", "-v"); ItemResult itemResult = CLIMain.getClientNetwork().client.getState(escrow); System.out.println("escrow: " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); itemResult = CLIMain.getClientNetwork().client.getState(contract_for_payment); System.out.println("contract_for_payment: " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); "-wait", "80000", "-v"); itemResult = CLIMain.getClientNetwork().client.getState(canceledEscrow); System.out.println("canceledEscrow: " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); "-wait", "80000", "-v"); itemResult = CLIMain.getClientNetwork().client.getState(newPayment); System.out.println("newPayment: " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state);
"-wait", "80000", "-v"); ItemResult itemResult = CLIMain.getClientNetwork().client.getState(notaryContract); System.out.println("notaryContractWithFile: " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state);
ClientNetwork n = getClientNetwork(); int total = n.size(); n.checkNetworkState(reporter);