@Test public void exportPublicKeys() throws Exception { String role = "owner"; callMain( "-e", basePath + "contract_to_export.unicon", "--extract-key", role); System.out.println(output); assertTrue (output.indexOf(role + " export public keys ok") >= 0); assertEquals(0, errors.size()); }
private static void exportPublicKeys(Contract contract, String roleName, String fileName, boolean base64) throws IOException { if (fileName == null) { if (testMode && testRootPath != null) { fileName = testRootPath + "Universa_" + roleName + "_public_key"; } else { fileName = "Universa_" + roleName + "_public_key.pub"; } } Role role = contract.getRole(roleName); if (role != null) { Set<PublicKey> keys = role.getKeys(); int index = 0; byte[] data; for (PublicKey key : keys) { index++; data = key.pack(); String name = fileName.replaceAll("\\.(pub)$", "_key_" + roleName + "_" + index + ".public.unikey"); if (base64) { name += ".txt"; } try (FileOutputStream fs = new FileOutputStream(name)) { if (base64) fs.write(Base64.encodeLines(data).getBytes()); else fs.write(data); fs.close(); } } report(roleName + " export public keys ok"); } else { addError(Errors.NOT_FOUND.name(), roleName, "role doesn't exist"); } }
CLIMain { private static void exportPublicKeys(Contract contract, String roleName, String fileName, boolean base64) throws IOException { if (fileName == null) { if (testMode && testRootPath != null) { fileName = testRootPath + "Universa_" + roleName + "_public_key"; } else { fileName = "Universa_" + roleName + "_public_key.pub"; } } Role role = contract.getRole(roleName); if (role != null) { Set<PublicKey> keys = role.getKeys(); int index = 0; byte[] data; for (PublicKey key : keys) { index++; data = key.pack(); String name = fileName.replaceAll("\\.(pub)$", "_key_" + roleName + "_" + index + ".public.unikey"); if (base64) { name += ".txt"; } try (FileOutputStream fs = new FileOutputStream(name)) { if (base64) fs.write(Base64.encodeLines(data).getBytes()); else fs.write(data); fs.close(); } } report(roleName + " export public keys ok"); } else { addError(Errors.NOT_FOUND.name(), roleName, "role doesn't exist"); } } }
CLIMain { private static void exportPublicKeys(Contract contract, String roleName, String fileName, boolean base64) throws IOException { if (fileName == null) { if (testMode && testRootPath != null) { fileName = testRootPath + "Universa_" + roleName + "_public_key"; } else { fileName = "Universa_" + roleName + "_public_key.pub"; } } Role role = contract.getRole(roleName); if (role != null) { Set<PublicKey> keys = role.getKeys(); int index = 0; byte[] data; for (PublicKey key : keys) { index++; data = key.pack(); String name = fileName.replaceAll("\\.(pub)$", "_key_" + roleName + "_" + index + ".public.unikey"); if (base64) { name += ".txt"; } try (FileOutputStream fs = new FileOutputStream(name)) { if (base64) fs.write(Base64.encodeLines(data).getBytes()); else fs.write(data); fs.close(); } } report(roleName + " export public keys ok"); } else { addError(Errors.NOT_FOUND.name(), roleName, "role doesn't exist"); } }  }
CLIMain { private static void exportPublicKeys(Contract contract, String roleName, String fileName, boolean base64) throws IOException { if (fileName == null) { if (testMode && testRootPath != null) { fileName = testRootPath + "Universa_" + roleName + "_public_key"; } else { fileName = "Universa_" + roleName + "_public_key.pub"; } } Role role = contract.getRole(roleName); if (role != null) { Set<PublicKey> keys = role.getKeys(); int index = 0; byte[] data; for (PublicKey key : keys) { index++; data = key.pack(); String name = fileName.replaceAll("\\.(pub)$", "_key_" + roleName + "_" + index + ".public.unikey"); if (base64) { name += ".txt"; } try (FileOutputStream fs = new FileOutputStream(name)) { if (base64) fs.write(Base64.encodeLines(data).getBytes()); else fs.write(data); fs.close(); } } report(roleName + " export public keys ok"); } else { addError(Errors.NOT_FOUND.name(), roleName, "role doesn't exist"); } }  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 { private static void exportPublicKeys(Contract contract, String roleName, String fileName, boolean base64) throws IOException { if (fileName == null) { if (testMode && testRootPath != null) { fileName = testRootPath + "Universa_" + roleName + "_public_key"; } else { fileName = "Universa_" + roleName + "_public_key.pub"; } } Role role = contract.getRole(roleName); if (role != null) { Set<PublicKey> keys = role.getKeys(); int index = 0; byte[] data; for (PublicKey key : keys) { index++; data = key.pack(); String name = fileName.replaceAll("\\.(pub)$", "_key_" + roleName + "_" + index + ".public.unikey"); if (base64) { name += ".txt"; } try (FileOutputStream fs = new FileOutputStream(name)) { if (base64) fs.write(Base64.encodeLines(data).getBytes()); else fs.write(data); fs.close(); } } report(roleName + " export public keys ok"); } else { addError(Errors.NOT_FOUND.name(), roleName, "role doesn't exist"); } }  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; }