@Test public void checkContract() throws Exception { callMain("-ch", basePath + "contract1.unicon"); System.out.println(output); assertEquals(0, errors.size()); }
private static void checkContract(Contract contract) { if (!contract.isOk()) { reporter.message("The capsule is not sealed properly:"); contract.getErrors().forEach(e -> reporter.error(e.getError().toString(), e.getObjectName(), e.getMessage())); } Yaml yaml = new Yaml(); if (reporter.isVerboseMode()) { report("api level: " + contract.getApiLevel()); report("contract id: " + contract.getId().toBase64String()); report("issued: " + contract.getIssuedAt()); report("revision: " + contract.getRevision()); report("created: " + contract.getCreatedAt()); report("expires: " + contract.getExpiresAt()); System.out.println(); Set<PublicKey> keys = contract.getSealedByKeys(); contract.getRevoking().forEach(r -> { try { ClientNetwork n = getClientNetwork(); System.out.println(); report("revoking item exists: " + r.getId().toBase64String()); report("\tstate: " + n.check(r.getId())); HashId origin = r.getOrigin(); boolean m = origin.equals(contract.getOrigin()); report("\tOrigin: " + origin); report("\t" + (m ? "matches main contract origin" : "does not match main contract origin")); if( r.canBeRevoked(keys) ) { report("\trevocation is allowed"); } else reporter.error(Errors.BAD_REVOKE.name(), r.getId().toString(), "revocation not allowed"); } catch (Exception clientError) { clientError.printStackTrace(); } }); contract.getNewItems().forEach(n -> { System.out.println(); report("New item exists: " + n.getId().toBase64String()); Contract nc = (Contract) n; boolean m = nc.getOrigin().equals(contract.getOrigin()); report("\tOrigin: " + ((Contract) n).getOrigin()); report("\t" + (m ? "matches main contract origin" : "does not match main contract origin")); }); if (keys.size() > 0) { report("\nSignature contains " + keys.size() + " valid key(s):\n"); keys.forEach(k -> { KeyInfo i = k.info(); report("\t✔︎ " + i.getAlgorythm() + ":" + i.getKeyLength() * 8 + ":" + i.getBase64Tag()); }); report("\nWhich can play roles:\n"); contract.getRoles().forEach((name, role) -> { String canPlay = role.isAllowedForKeys(keys) ? "✔" : "✘"; report("\t" + canPlay + " " + role.getName()); }); report("\nAnd have permissions:\n"); contract.getPermissions().values().forEach(perm -> { String canPlay = perm.isAllowedForKeys(keys) ? "✔" : "✘"; report("\t" + canPlay + " " + perm.getName()); Binder x = DefaultBiMapper.serialize(perm.getParams()); BufferedReader br = new BufferedReader( new StringReader(yaml.dumpAsMap(x) )); try { for (String line; (line = br.readLine()) != null; ) { report("\t " + line); } } catch (IOException e) { e.printStackTrace(); } }); reporter.newLine(); } } Multimap<String, Permission> permissions = contract.getPermissions(); Collection<Permission> sjs = permissions.get("split_join"); if (sjs != null) { sjs.forEach(sj -> checkSj(contract, sj)); } try { contract.check(); } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", contract.toString(), e.getMessage()); } catch (Exception e) { addError(Errors.FAILURE.name(), contract.toString(), e.getMessage()); } addErrors(contract.getErrors()); if (contract.getErrors().size() == 0) { report("Contract is valid"); } }
CLIMain { private static void checkContract(Contract contract) { if (!contract.isOk()) { reporter.message("The capsule is not sealed properly:"); contract.getErrors().forEach(e -> reporter.error(e.getError().toString(), e.getObjectName(), e.getMessage())); } Yaml yaml = new Yaml(); if (reporter.isVerboseMode()) { report("api level: " + contract.getApiLevel()); report("contract id: " + contract.getId().toBase64String()); report("issued: " + contract.getIssuedAt()); report("revision: " + contract.getRevision()); report("created: " + contract.getCreatedAt()); report("expires: " + contract.getExpiresAt()); System.out.println(); Set<PublicKey> keys = contract.getSealedByKeys(); contract.getRevoking().forEach(r -> { try { ClientNetwork n = getClientNetwork(); System.out.println(); report("revoking item exists: " + r.getId().toBase64String()); report("\tstate: " + n.check(r.getId())); HashId origin = r.getOrigin(); boolean m = origin.equals(contract.getOrigin()); report("\tOrigin: " + origin); report("\t" + (m ? "matches main contract origin" : "does not match main contract origin")); if( r.canBeRevoked(keys) ) { report("\trevocation is allowed"); } else reporter.error(Errors.BAD_REVOKE.name(), r.getId().toString(), "revocation not allowed"); } catch (Exception clientError) { clientError.printStackTrace(); } }); contract.getNewItems().forEach(n -> { System.out.println(); report("New item exists: " + n.getId().toBase64String()); Contract nc = (Contract) n; boolean m = nc.getOrigin().equals(contract.getOrigin()); report("\tOrigin: " + ((Contract) n).getOrigin()); report("\t" + (m ? "matches main contract origin" : "does not match main contract origin")); }); if (keys.size() > 0) { report("\nSignature contains " + keys.size() + " valid key(s):\n"); keys.forEach(k -> { KeyInfo i = k.info(); report("\t✔︎ " + i.getAlgorythm() + ":" + i.getKeyLength() * 8 + ":" + i.getBase64Tag()); }); report("\nWhich can play roles:\n"); contract.getRoles().forEach((name, role) -> { String canPlay = role.isAllowedForKeys(keys) ? "✔" : "✘"; report("\t" + canPlay + " " + role.getName()); }); report("\nAnd have permissions:\n"); contract.getPermissions().values().forEach(perm -> { String canPlay = perm.isAllowedForKeys(keys) ? "✔" : "✘"; report("\t" + canPlay + " " + perm.getName()); Binder x = DefaultBiMapper.serialize(perm.getParams()); BufferedReader br = new BufferedReader( new StringReader(yaml.dumpAsMap(x) )); try { for (String line; (line = br.readLine()) != null; ) { report("\t " + line); } } catch (IOException e) { e.printStackTrace(); } }); reporter.newLine(); } } Multimap<String, Permission> permissions = contract.getPermissions(); Collection<Permission> sjs = permissions.get("split_join"); if (sjs != null) { sjs.forEach(sj -> checkSj(contract, sj)); } try { contract.check(); } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", contract.toString(), e.getMessage()); } catch (Exception e) { addError(Errors.FAILURE.name(), contract.toString(), e.getMessage()); } addErrors(contract.getErrors()); if (contract.getErrors().size() == 0) { report("Contract is valid"); } } }
CLIMain { private static void checkContract(Contract contract) { if (!contract.isOk()) { reporter.message("The capsule is not sealed properly:"); contract.getErrors().forEach(e -> reporter.error(e.getError().toString(), e.getObjectName(), e.getMessage())); } Yaml yaml = new Yaml(); if (reporter.isVerboseMode()) { report("api level: " + contract.getApiLevel()); report("contract id: " + contract.getId().toBase64String()); report("issued: " + contract.getIssuedAt()); report("revision: " + contract.getRevision()); report("created: " + contract.getCreatedAt()); report("expires: " + contract.getExpiresAt()); System.out.println(); Set<PublicKey> keys = contract.getSealedByKeys(); contract.getRevoking().forEach(r -> { try { ClientNetwork n = getClientNetwork(); System.out.println(); report("revoking item exists: " + r.getId().toBase64String()); report("\tstate: " + n.check(r.getId())); HashId origin = r.getOrigin(); boolean m = origin.equals(contract.getOrigin()); report("\tOrigin: " + origin); report("\t" + (m ? "matches main contract origin" : "does not match main contract origin")); if( r.canBeRevoked(keys) ) { report("\trevocation is allowed"); } else reporter.error(Errors.BAD_REVOKE.name(), r.getId().toString(), "revocation not allowed"); } catch (Exception clientError) { clientError.printStackTrace(); } }); contract.getNewItems().forEach(n -> { System.out.println(); report("New item exists: " + n.getId().toBase64String()); Contract nc = (Contract) n; boolean m = nc.getOrigin().equals(contract.getOrigin()); report("\tOrigin: " + ((Contract) n).getOrigin()); report("\t" + (m ? "matches main contract origin" : "does not match main contract origin")); }); if (keys.size() > 0) { report("\nSignature contains " + keys.size() + " valid key(s):\n"); keys.forEach(k -> { KeyInfo i = k.info(); report("\t✔︎ " + i.getAlgorythm() + ":" + i.getKeyLength() * 8 + ":" + i.getBase64Tag()); }); report("\nWhich can play roles:\n"); contract.getRoles().forEach((name, role) -> { String canPlay = role.isAllowedForKeys(keys) ? "✔" : "✘"; report("\t" + canPlay + " " + role.getName()); }); report("\nAnd have permissions:\n"); contract.getPermissions().values().forEach(perm -> { String canPlay = perm.isAllowedForKeys(keys) ? "✔" : "✘"; report("\t" + canPlay + " " + perm.getName()); Binder x = DefaultBiMapper.serialize(perm.getParams()); BufferedReader br = new BufferedReader( new StringReader(yaml.dumpAsMap(x) )); try { for (String line; (line = br.readLine()) != null; ) { report("\t " + line); } } catch (IOException e) { e.printStackTrace(); } }); reporter.newLine(); } } Multimap<String, Permission> permissions = contract.getPermissions(); Collection<Permission> sjs = permissions.get("split_join"); if (sjs != null) { sjs.forEach(sj -> checkSj(contract, sj)); } try { contract.check(); } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", contract.toString(), e.getMessage()); } catch (Exception e) { addError(Errors.FAILURE.name(), contract.toString(), e.getMessage()); } addErrors(contract.getErrors()); if (contract.getErrors().size() == 0) { report("Contract is valid"); } }  }
CLIMain { private static void checkContract(Contract contract) { if (!contract.isOk()) { reporter.message("The capsule is not sealed properly:"); contract.getErrors().forEach(e -> reporter.error(e.getError().toString(), e.getObjectName(), e.getMessage())); } Yaml yaml = new Yaml(); if (reporter.isVerboseMode()) { report("api level: " + contract.getApiLevel()); report("contract id: " + contract.getId().toBase64String()); report("issued: " + contract.getIssuedAt()); report("revision: " + contract.getRevision()); report("created: " + contract.getCreatedAt()); report("expires: " + contract.getExpiresAt()); System.out.println(); Set<PublicKey> keys = contract.getSealedByKeys(); contract.getRevoking().forEach(r -> { try { ClientNetwork n = getClientNetwork(); System.out.println(); report("revoking item exists: " + r.getId().toBase64String()); report("\tstate: " + n.check(r.getId())); HashId origin = r.getOrigin(); boolean m = origin.equals(contract.getOrigin()); report("\tOrigin: " + origin); report("\t" + (m ? "matches main contract origin" : "does not match main contract origin")); if( r.canBeRevoked(keys) ) { report("\trevocation is allowed"); } else reporter.error(Errors.BAD_REVOKE.name(), r.getId().toString(), "revocation not allowed"); } catch (Exception clientError) { clientError.printStackTrace(); } }); contract.getNewItems().forEach(n -> { System.out.println(); report("New item exists: " + n.getId().toBase64String()); Contract nc = (Contract) n; boolean m = nc.getOrigin().equals(contract.getOrigin()); report("\tOrigin: " + ((Contract) n).getOrigin()); report("\t" + (m ? "matches main contract origin" : "does not match main contract origin")); }); if (keys.size() > 0) { report("\nSignature contains " + keys.size() + " valid key(s):\n"); keys.forEach(k -> { KeyInfo i = k.info(); report("\t✔︎ " + i.getAlgorythm() + ":" + i.getKeyLength() * 8 + ":" + i.getBase64Tag()); }); report("\nWhich can play roles:\n"); contract.getRoles().forEach((name, role) -> { String canPlay = role.isAllowedForKeys(keys) ? "✔" : "✘"; report("\t" + canPlay + " " + role.getName()); }); report("\nAnd have permissions:\n"); contract.getPermissions().values().forEach(perm -> { String canPlay = perm.isAllowedForKeys(keys) ? "✔" : "✘"; report("\t" + canPlay + " " + perm.getName()); Binder x = DefaultBiMapper.serialize(perm.getParams()); BufferedReader br = new BufferedReader( new StringReader(yaml.dumpAsMap(x) )); try { for (String line; (line = br.readLine()) != null; ) { report("\t " + line); } } catch (IOException e) { e.printStackTrace(); } }); reporter.newLine(); } } Multimap<String, Permission> permissions = contract.getPermissions(); Collection<Permission> sjs = permissions.get("split_join"); if (sjs != null) { sjs.forEach(sj -> checkSj(contract, sj)); } try { contract.check(); } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", contract.toString(), e.getMessage()); } catch (Exception e) { addError(Errors.FAILURE.name(), contract.toString(), e.getMessage()); } addErrors(contract.getErrors()); if (contract.getErrors().size() == 0) { report("Contract is valid"); } }  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 checkContract(Contract contract) { if (!contract.isOk()) { reporter.message("The capsule is not sealed properly:"); contract.getErrors().forEach(e -> reporter.error(e.getError().toString(), e.getObjectName(), e.getMessage())); } Yaml yaml = new Yaml(); if (reporter.isVerboseMode()) { report("api level: " + contract.getApiLevel()); report("contract id: " + contract.getId().toBase64String()); report("issued: " + contract.getIssuedAt()); report("revision: " + contract.getRevision()); report("created: " + contract.getCreatedAt()); report("expires: " + contract.getExpiresAt()); System.out.println(); Set<PublicKey> keys = contract.getSealedByKeys(); contract.getRevoking().forEach(r -> { try { ClientNetwork n = getClientNetwork(); System.out.println(); report("revoking item exists: " + r.getId().toBase64String()); report("\tstate: " + n.check(r.getId())); HashId origin = r.getOrigin(); boolean m = origin.equals(contract.getOrigin()); report("\tOrigin: " + origin); report("\t" + (m ? "matches main contract origin" : "does not match main contract origin")); if( r.canBeRevoked(keys) ) { report("\trevocation is allowed"); } else reporter.error(Errors.BAD_REVOKE.name(), r.getId().toString(), "revocation not allowed"); } catch (Exception clientError) { clientError.printStackTrace(); } }); contract.getNewItems().forEach(n -> { System.out.println(); report("New item exists: " + n.getId().toBase64String()); Contract nc = (Contract) n; boolean m = nc.getOrigin().equals(contract.getOrigin()); report("\tOrigin: " + ((Contract) n).getOrigin()); report("\t" + (m ? "matches main contract origin" : "does not match main contract origin")); }); if (keys.size() > 0) { report("\nSignature contains " + keys.size() + " valid key(s):\n"); keys.forEach(k -> { KeyInfo i = k.info(); report("\t✔︎ " + i.getAlgorythm() + ":" + i.getKeyLength() * 8 + ":" + i.getBase64Tag()); }); report("\nWhich can play roles:\n"); contract.getRoles().forEach((name, role) -> { String canPlay = role.isAllowedForKeys(keys) ? "✔" : "✘"; report("\t" + canPlay + " " + role.getName()); }); report("\nAnd have permissions:\n"); contract.getPermissions().values().forEach(perm -> { String canPlay = perm.isAllowedForKeys(keys) ? "✔" : "✘"; report("\t" + canPlay + " " + perm.getName()); Binder x = DefaultBiMapper.serialize(perm.getParams()); BufferedReader br = new BufferedReader( new StringReader(yaml.dumpAsMap(x) )); try { for (String line; (line = br.readLine()) != null; ) { report("\t " + line); } } catch (IOException e) { e.printStackTrace(); } }); reporter.newLine(); } } Multimap<String, Permission> permissions = contract.getPermissions(); Collection<Permission> sjs = permissions.get("split_join"); if (sjs != null) { sjs.forEach(sj -> checkSj(contract, sj)); } try { contract.check(); } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", contract.toString(), e.getMessage()); } catch (Exception e) { addError(Errors.FAILURE.name(), contract.toString(), e.getMessage()); } addErrors(contract.getErrors()); if (contract.getErrors().size() == 0) { report("Contract is valid"); } }  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; }