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(); }
/** * Register a paying parcel. * * @param contract must be a sealed binary. */ public static Parcel prepareForRegisterPayingParcel(Contract contract, Contract u, int amount, int amountStorage, Set<PrivateKey> uKeys, boolean withTestPayment) throws IOException { 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 { Set<PrivateKey> keys = new HashSet<>(keysMapContract().values()); if (keys != null && keys.size() > 0) contract.addSignerKeys(keys); Parcel parcel = ContractsService.createPayingParcel(contract.getTransactionPack(), u, amount, amountStorage, uKeys, withTestPayment); return parcel; } return null; }
/** * Register a specified contract. * * @param contract must be a sealed binary. */ public static Parcel prepareForRegisterContract(Contract contract, Contract u, int amount, Set<PrivateKey> uKeys, boolean withTestPayment) throws IOException { 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 { Parcel parcel = ContractsService.createParcel(contract, u, amount, uKeys, withTestPayment); return parcel; } return null; }
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(); }
report("Sealed contract has no errors"); } else addErrors(contract.getErrors()); } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", contract.toString(), e.getMessage());
/** * Save specified parcel to file. * * @param parcel - parcel to save. * @param fileName - name of file to save to. * */ public static boolean saveParcel(Parcel parcel, String fileName) throws IOException { if (fileName == null) { fileName = "Universa_" + DateTimeFormatter.ofPattern("yyyy-MM-ddTHH:mm:ss").format(parcel.getPayloadContract().getCreatedAt()) + ".uniparcel"; } byte[] data = parcel.pack(); String newFileName = FileTool.writeFileContentsWithRenaming(fileName, data); report("Parcel is saved to: " + newFileName); report("Parcel size: " + data.length); try { if (parcel.getPaymentContract().check() && parcel.getPayloadContract().check()) { report("Parcel has no errors"); } else { addErrors(parcel.getPaymentContract().getErrors()); addErrors(parcel.getPayloadContract().getErrors()); } } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", parcel.toString(), e.getMessage()); } return (newFileName!=null); }
parcel = revokeContract(contract, u, uAmount, uKeys, utest, keysMap().values().toArray(new PrivateKey[0])); } else { addErrors(contract.getErrors()); ItemResult ir = registerParcel(parcel, (int) options.valueOf("wait")); if(ir.state != ItemState.APPROVED) { addErrors(ir.errors); revokeContract(contract, keysMap().values().toArray(new PrivateKey[0])); } else { addErrors(contract.getErrors());
/** * 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()); } }
addError(Errors.FAILURE.name(), contract.toString(), e.getMessage()); addErrors(contract.getErrors()); if (contract.getErrors().size() == 0) { report("Contract is valid");
ItemResult ir = registerParcel(parcel, (int) options.valueOf("wait")); if(ir.state != ItemState.APPROVED) { addErrors(ir.errors);