@Test public void sign() throws Exception { PrivateKey key1 = new PrivateKey(2048); PrivateKey key2 = new PrivateKey(2048); Files.write(Paths.get(basePath + "signKey1.privateKey.unikey"),key1.pack(), StandardOpenOption.CREATE, StandardOpenOption.WRITE); Files.write(Paths.get(basePath + "signKey2.privateKey.unikey"),key2.pack(), StandardOpenOption.CREATE, StandardOpenOption.WRITE); HashSet<PrivateKey> issuers = new HashSet<>(); issuers.add(key1); HashSet<PublicKey> owners = new HashSet<>(); owners.add(key1.getPublicKey()); Contract contract = ContractsService.createTokenContract(issuers, owners, new BigDecimal("10000.50"), new BigDecimal("0.01")); SimpleRole issuer1 = new SimpleRole("issuer1",contract,new KeyRecord(key1.getPublicKey())); SimpleRole issuer2 = new SimpleRole("issuer2",contract,new KeyRecord(key2.getPublicKey())); ListRole issuer = new ListRole("issuer",contract,ListRole.Mode.ALL,Do.listOf(issuer1,issuer2)); contract.addRole(issuer); contract.seal(); contract.check(); assertFalse(contract.isOk()); Files.write(Paths.get(basePath + "sign.unicon"),contract.getPackedTransaction(), StandardOpenOption.CREATE, StandardOpenOption.WRITE); assertFalse(CLIMain.loadContract(basePath + "sign.unicon").check()); callMain("--sign",basePath + "sign.unicon","--keys",basePath + "signKey2.privateKey.unikey"); callMain("--sign",basePath + "sign.unicon","--keys",basePath + "signKey2.privateKey.unikey","--output", basePath + "sign_2.unicon"); assertTrue(CLIMain.loadContract(basePath + "sign_2.unicon").check()); }
public static Contract loadContract(String fileName, Boolean fromPackedTransaction) throws IOException { Contract contract = null; File pathFile = new File(fileName); if (pathFile.exists()) { Path path = Paths.get(fileName); byte[] data = Files.readAllBytes(path); try { if (fromPackedTransaction) { contract = Contract.fromPackedTransaction(data); } else { contract = new Contract(data); } } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", fileName, e.toString()); } } else { addError(Errors.NOT_FOUND.name(), fileName, "Path " + fileName + " does not exist"); } return contract; }
CLIMain { public static Contract loadContract(String fileName, Boolean fromPackedTransaction) throws IOException { Contract contract = null; File pathFile = new File(fileName); if (pathFile.exists()) { Path path = Paths.get(fileName); byte[] data = Files.readAllBytes(path); try { if (fromPackedTransaction) { contract = Contract.fromPackedTransaction(data); } else { contract = new Contract(data); } } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", fileName, e.toString()); } } else { addError(Errors.NOT_FOUND.name(), fileName, "Path " + fileName + " does not exist"); } return contract; } }
CLIMain { public static Contract loadContract(String fileName, Boolean fromPackedTransaction) throws IOException { Contract contract = null; File pathFile = new File(fileName); if (pathFile.exists()) { Path path = Paths.get(fileName); byte[] data = Files.readAllBytes(path); try { if (fromPackedTransaction) { contract = Contract.fromPackedTransaction(data); } else { contract = new Contract(data); } } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", fileName, e.toString()); } } else { addError(Errors.NOT_FOUND.name(), fileName, "Path " + fileName + " does not exist"); } return contract; }  }
CLIMain { public static Contract loadContract(String fileName, Boolean fromPackedTransaction) throws IOException { Contract contract = null; File pathFile = new File(fileName); if (pathFile.exists()) { Path path = Paths.get(fileName); byte[] data = Files.readAllBytes(path); try { if (fromPackedTransaction) { contract = Contract.fromPackedTransaction(data); } else { contract = new Contract(data); } } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", fileName, e.toString()); } } else { addError(Errors.NOT_FOUND.name(), fileName, "Path " + fileName + " does not exist"); } return contract; }  static void main(String[] args); static PrivateKey getPrivateKey(); static BasicHttpClientSession getSession(int nodeNumber); static void breakSession(int nodeNumber); static void clearSession(); static void clearSession(boolean full); static void saveSession(); static void setVerboseMode(boolean verboseMode); static Contract loadContract(String fileName, Boolean fromPackedTransaction); static Parcel loadParcel(String fileName); static Contract loadContract(String fileName); static void exportContract(Contract contract, String fileName, String format, Boolean jsonPretty); static boolean saveContract(Contract contract, String fileName, Boolean fromPackedTransaction, Boolean addSigners); static boolean saveContract(Contract contract, String fileName, Boolean fromPackedTransaction, Boolean addSigners, Set<Contract> referencedItems); static boolean saveParcel(Parcel parcel, String fileName); static void saveContract(Contract contract, String fileName); static List<Wallet> findWallets(String path); static HashMap<String, Contract> findContracts(String path); static HashMap<String, Contract> findContracts(String path, Boolean recursively); static List<File> findFiles(String path, Boolean recursively); static Contract downloadContract(String url); static Parcel revokeContract(Contract contract, Contract u, int amount, Set<PrivateKey> uKeys, boolean withTestPayment, PrivateKey... key); @Deprecated static Contract revokeContract(Contract contract, PrivateKey... key); @Deprecated static void registerContract(Contract contract, int waitTime, Boolean fromPackedTransaction); static Parcel prepareForRegisterContract(Contract contract, Contract u, int amount, Set<PrivateKey> uKeys, boolean withTestPayment); static Parcel prepareForRegisterPayingParcel(Contract contract, Contract u, int amount, int amountStorage, Set<PrivateKey> uKeys, boolean withTestPayment); static ItemResult registerParcel(Parcel parcel, int waitTime); static void registerContract(Contract contract); static void registerContract(Contract contract, int waitTime); static void setTestMode(); static void setTestRootPath(String rootPath); static void setNodeNumber(int number); static void setNodeUrl(String url); static void setTopologyFileName(String filename); static void setPrivateKey(PrivateKey key); static Reporter getReporter(); static synchronized ClientNetwork getClientNetwork(); static synchronized Map<String, PrivateKey> keysMap(); static synchronized Map<String, PrivateKey> keysMapContract(); }
CLIMain { public static Contract loadContract(String fileName, Boolean fromPackedTransaction) throws IOException { Contract contract = null; File pathFile = new File(fileName); if (pathFile.exists()) { Path path = Paths.get(fileName); byte[] data = Files.readAllBytes(path); try { if (fromPackedTransaction) { contract = Contract.fromPackedTransaction(data); } else { contract = new Contract(data); } } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", fileName, e.toString()); } } else { addError(Errors.NOT_FOUND.name(), fileName, "Path " + fileName + " does not exist"); } return contract; }  static void main(String[] args); static PrivateKey getPrivateKey(); static BasicHttpClientSession getSession(int nodeNumber); static void breakSession(int nodeNumber); static void clearSession(); static void clearSession(boolean full); static void saveSession(); static void setVerboseMode(boolean verboseMode); static Contract loadContract(String fileName, Boolean fromPackedTransaction); static Parcel loadParcel(String fileName); static Contract loadContract(String fileName); static void exportContract(Contract contract, String fileName, String format, Boolean jsonPretty); static boolean saveContract(Contract contract, String fileName, Boolean fromPackedTransaction, Boolean addSigners); static boolean saveContract(Contract contract, String fileName, Boolean fromPackedTransaction, Boolean addSigners, Set<Contract> referencedItems); static boolean saveParcel(Parcel parcel, String fileName); static void saveContract(Contract contract, String fileName); static List<Wallet> findWallets(String path); static HashMap<String, Contract> findContracts(String path); static HashMap<String, Contract> findContracts(String path, Boolean recursively); static List<File> findFiles(String path, Boolean recursively); static Contract downloadContract(String url); static Parcel revokeContract(Contract contract, Contract u, int amount, Set<PrivateKey> uKeys, boolean withTestPayment, PrivateKey... key); @Deprecated static Contract revokeContract(Contract contract, PrivateKey... key); @Deprecated static void registerContract(Contract contract, int waitTime, Boolean fromPackedTransaction); static Parcel prepareForRegisterContract(Contract contract, Contract u, int amount, Set<PrivateKey> uKeys, boolean withTestPayment); static Parcel prepareForRegisterPayingParcel(Contract contract, Contract u, int amount, int amountStorage, Set<PrivateKey> uKeys, boolean withTestPayment); static ItemResult registerParcel(Parcel parcel, int waitTime); static void registerContract(Contract contract); static void registerContract(Contract contract, int waitTime); static void setTestMode(); static void setTestRootPath(String rootPath); static void setNodeNumber(int number); static void setNodeUrl(String url); static void setTopologyFileName(String filename); static void setPrivateKey(PrivateKey key); static Reporter getReporter(); static synchronized ClientNetwork getClientNetwork(); static synchronized Map<String, PrivateKey> keysMap(); static synchronized Map<String, PrivateKey> keysMapContract(); static String DEFAULT_WALLET_PATH; static final String AMOUNT_FIELD_NAME; }