static public void clearSession() { clearSession(true); }
/** * Export contract to specified xml or json file. * * @param contract - contract to export. * @param fileName - name of file to export to. * @param format - format of file to export to. Can be xml or json. */ private static void exportContract(Contract contract, String fileName, String format) throws IOException { exportContract(contract, fileName, format, false); }
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(); }
/** * Revoke specified contract and create a revocation transactional contract. * * @param contract * * @return Contract - revoking transaction contract. */ @Deprecated public static Contract revokeContract(Contract contract, PrivateKey... key) throws IOException { report("keys num: " + key.length); Contract tc = ContractsService.createRevocation(contract, key); registerContract(tc, 0, true); return tc; }
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(); }
usage(null); setNodeNumber((Integer) options.valueOf("node")); setPrivateKey(new PrivateKey(Do.read((String) options.valueOf("skey")))); setVerboseMode(true); } else { setVerboseMode(false); UUTNWallet wallet = loadWallet(walletPath,false); if (wallet == null) keyFileNames = new ArrayList<>(); printFingerprints(); finish(); ClientNetwork n = getClientNetwork(); int total = n.size(); n.checkNetworkState(reporter); finish(); doShowId(); doShowHash(); doProbeFile(); doSign();
cleanNonOptionalArguments(sources); Contract contract = loadContract(source); uSource = getUFromWallet(uAmount+uAmountStorage,utest); u = loadContract(uSource, true); report("load payment revision: " + u.getState().getRevision() + " id: " + u.getId()); Set<PrivateKey> uKeys = new HashSet<>(keysMap().values()); if(contract != null) { if(u != null && uKeys != null && uKeys.size() > 0) { Contract newUContract; if(uAmountStorage == 0) { report("registering the paid contract " + contract.getId() + " from " + source + " for " + uAmount + " U"); report("contractId: "+contract.getId().toBase64String()); parcel = prepareForRegisterContract(contract, u, uAmount, uKeys, utest); newUContract = parcel.getPaymentContract(); } else { // if storage payment report("registering the paid contract " + contract.getId() + " from " + source + " for " + uAmount + " U (and " + uAmountStorage + " U for storage)"); report("contractId: "+contract.getId().toBase64String()); parcel = prepareForRegisterPayingParcel(contract, u, uAmount, uAmountStorage, uKeys, utest); newUContract = parcel.getPayloadContract().getNew().get(0); saveParcel(parcel,new FilenameTool(source).setExtension("uniparcel").toString()); report("save payment revision: " + newUContract.getState().getRevision() + " id: " + newUContract.getId());
cleanNonOptionalArguments(sources); report("doRevoke"); Contract contract = loadContract(source); report("doRevoke " + contract); Contract u = null; if(uSource != null) { u = loadContract(uSource, true); report("load payment revision: " + u.getState().getRevision() + " id: " + u.getId()); Set<PrivateKey> uKeys = new HashSet<>(keysMap().values()); report("uKeys num: " + uKeys.size()); if (contract != null) { if(u != null && uKeys != null && uKeys.size() > 0) { report("registering the paid contract " + contract.getId() + " from " + source + " for " + uAmount + " U"); Parcel parcel = null; try { if (contract.check()) { report("revoke contract from " + source); parcel = revokeContract(contract, u, uAmount, uKeys, utest, keysMap().values().toArray(new PrivateKey[0])); } else { addErrors(contract.getErrors()); addError("QUANTIZER_COST_LIMIT", contract.toString(), e.getMessage()); report("save payment revision: " + newUContract.getState().getRevision() + " id: " + newUContract.getId()); if (uDest != null) {
CLIMain.setVerboseMode(true); CLIMain.clearSession(); CLIMain.registerContract(c); CLIMain.setNodeUrl("http://localhost:8080"); CLIMain.registerContract(c); CLIMain.saveSession(); CLIMain.clearSession(false); CLIMain.setNodeUrl("http://localhost:8080"); CLIMain.registerContract(c); CLIMain.saveSession(); CLIMain.breakSession(-1); CLIMain.clearSession(false); CLIMain.setNodeUrl("http://localhost:8080"); CLIMain.registerContract(c);
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(); }
cleanNonOptionalArguments(sources); Contract contract = loadContract(source); if (contract != null) { for (int i = 0; i < updateFields.size(); i++) { updateFieldsHashMap.put((String) updateFields.get(i), (String) updateValues.get(i)); } catch (Exception e) { addError(Errors.FAILURE.name(), (String) updateFields.get(i), "failed to set value " + (String) updateValues.get(i) + ": " + e.getMessage()); updateFields(contract, updateFieldsHashMap); name = new FilenameTool(source).setExtension("pub").toString(); exportPublicKeys(contract, extractKeyRole, name, options.has("base64")); name = new FilenameTool(source).setExtension(format).addSuffixToBase("_fields").toString(); exportFields(contract, extractFields, name, format, options.has("pretty")); } else { if (name == null) { name = new FilenameTool(source).setExtension(format).toString(); exportContract(contract, name, format, options.has("pretty")); finish();
cleanNonOptionalArguments(sources); ContractFileTypes fileType = getFileType(source); report(""); report("Calculating cost of " + source + ", type is " + fileType + "..."); contract = loadContract(source); } else { addError(Errors.COMMAND_FAILED.name(), source, "Contract should be sealed binary"); contract.check(); } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", contract.toString(), e.getMessage()); printProcessingCost(contract); finish();
cleanNonOptionalArguments(sources); Object x = Boss.load(data); if(x == null) { addError(Errors.NOT_SUPPORTED.name(), source, "Unknown packed object. Should be either unicapsule or transaction pack or parcel"); saveContractSubitems(source,"_payment", ((Parcel) x).getPaymentContract()); saveContractSubitems(source,"_payload", ((Parcel) x).getPayloadContract()); saveContract(((Parcel) x).getPaymentContract(),new FilenameTool(source).addSuffixToBase("_payment").setExtension("unicon").toString()); saveContract(((Parcel) x).getPayloadContract(),new FilenameTool(source).addSuffixToBase("_payload").setExtension("unicon").toString()); } else { Contract contract = loadContract(source); saveContractSubitems(source,"", contract); addError(Errors.NOT_FOUND.name(), source, "Path " + source + " does not exist"); finish();
/** * Save specified contract to file. * * @param contract - contract for update. * @param fileName - name of file to save to. */ public static void saveContract(Contract contract, String fileName) throws IOException { saveContract(contract, fileName, false, true); }
cleanNonOptionalArguments(sources); if (names.size() > s) name = names.get(s); Contract contract = importContract(source); if (contract != null) { HashMap<String, String> updateFieldsHashMap = new HashMap<>(); updateFields(contract, updateFieldsHashMap); Contract parent = loadContract((String) parentItems.get(s)); if(parent != null) { contract.getState().setParent(parent.getId()); saveContract(contract, name,true,true); finish();
Files.createDirectories(Paths.get(walletPath)); } catch (FileAlreadyExistsException e) { addError(Errors.FAILURE.name(), e.getFile(), "File can not be a part of the path"); finish(); wallet = loadWallet(walletDir.getPath(),false); Map<String, PrivateKey> map = keysMap(); for(String keyPath : map.keySet()) { PrivateKey pk = map.get(keyPath); if(publicKeys.contains(pk.getPublicKey())) { addError(Errors.FORBIDDEN.name(),pk.getPublicKey().toString(),"Key is already in wallet"); int utncontractsAdded = 0; for(String contractPath : contracts) { Contract contract = loadContract(contractPath); if(contract != null) { List<String> targetList; addError(Errors.NOT_SIGNED.name(),contractPath,"contract is not operational for given keys (including the one in the wallet already)"); continue; addError(Errors.FORBIDDEN.name(),contractPath,"contract with the same ID is already in wallet"); 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"; } }
cleanNonOptionalArguments(sources); updateFields(contract, updateFieldsHashMap); keysMap().values().forEach(k -> contract.addSignerKey(k)); saveContract(contract, name); checkContract(contract); finish();
finish(); Contract contract = loadContract(source, true); if (contract != null) { try { contract = contract.createRevision(keysMap().values()); Contract contractToJoin = loadContract(filename,true); if(contractToJoin != null) { value = value.add(new Decimal(contractToJoin.getStateData().getStringOrThrow(fieldName))); SimpleRole role = new SimpleRole("owner", asList(new KeyAddress((String) owners.get(i)))); partContracts[i].registerRole(role); partContracts[i].setCreatorKeys(keysMap().values()); } catch (KeyAddress.IllegalAddressException e) { System.out.println("Not a valid address: " + owners.get(i)); finish(); contract.setCreatorKeys(keysMap().values()); saveContract(partContracts[i], nameTool.toString(), true, true); saveContract(contract, nameTool.toString(), true, true); addError("QUANTIZER_COST_LIMIT", contract.toString(), e.getMessage()); finish();
Contract contract = loadContract(walletPath + File.separator + contractPath); Contract contract = loadContract(walletPath + File.separator + contractPath); 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); String newUContract = reserveUforUTN(walletPath + File.separator + utn, null, amount); if (newUContract != null) { System.out.println("Auto purchase completed. New U contract is: " + newUContract); config.put("ucontracts",uContracts); Files.write(Paths.get(walletConfig.getPath()),yaml.dumpAsMap(config).getBytes(), StandardOpenOption.CREATE,StandardOpenOption.TRUNCATE_EXISTING); return loadWallet(walletPath,reserveMoreIfNeeded); } else { return wallet;