/** * Gets complex "id" of current revision * @return revision "id" in format ORIGIN/PARENT/REVISION/BRANCH */ public String getRevisionId() { String parentId = getParent() == null ? "" : (getParent().toBase64String() + "/"); StringBuilder sb = new StringBuilder(getOrigin().toBase64String() + "/" + parentId + state.revision); if (state.branchId != null) sb.append("/" + state.branchId.toString()); return sb.toString(); }
private boolean searchNewItemWithParent(Approvable item, HashId id) { if(item instanceof Contract && ((Contract) item).getParent() != null && ((Contract) item).getParent().equals(id)) { return true; } for(Approvable newItem : item.getNewItems()) { if(searchNewItemWithParent(newItem,id)) { return true; } } return false; }
public JSApiRevisionStorage getRevisionStorage() { if (scriptParameters.checkPermission(JSApiScriptParameters.ScriptPermissions.PERM_REVISION_STORAGE)) return new JSApiRevisionStorage(this.currentContract.getId(), this.currentContract.getParent()); throw new IllegalArgumentException("access denied: missing permission " + JSApiScriptParameters.ScriptPermissions.PERM_REVISION_STORAGE.toString()); }
private void checkRevokePermissions(Set<Contract> revokes) throws Quantiser.QuantiserException { for (Contract rc : revokes) { //check if revoking parent => no permission is needed if(getParent() != null && rc.getId().equals(getParent())) continue; if (!rc.isPermitted("revoke", getEffectiveKeys())) addError(FORBIDDEN, "revokingItem", "revocation not permitted for item " + rc.getId()); } }
@SuppressWarnings("deprecation") //outdated method. will be replaced with new one soon private void checkForNetConfig(Contract contract) { if (contract.getIssuer().getKeys().stream().anyMatch(key -> config.getNetworkReconfigKeyAddress().isMatchingKey(key))) { if(contract.getParent() == null) return; if(contract.getRevoking().size() == 0 || !contract.getRevoking().get(0).getId().equals(contract.getParent())) return; Contract parent = contract.getRevoking().get(0); if(!checkContractCorrespondsToConfig(parent,network.allNodes())) { return; } if(!checkIfContractContainsNetConfig(contract)) { return; } List<NodeInfo> networkNodes = network.allNodes(); List contractNodes = (List)DefaultBiMapper.getInstance().deserializeObject(contract.getStateData().get("net_config")); contractNodes.stream().forEach(nodeInfo -> { if(!networkNodes.contains(nodeInfo)) { addNode((NodeInfo) nodeInfo); } networkNodes.remove(nodeInfo); }); networkNodes.stream().forEach( nodeInfo -> removeNode(nodeInfo)); } }
private void checkChangedContract() throws Quantiser.QuantiserException { // get context if not got yet getContext(); Contract parent; // if exist siblings for contract (more then itself) if(getSiblings().size() > 1) { parent = getContext().base; } else { parent = getRevokingItem(getParent()); } if (parent == null) { addError(BAD_REF, "parent", "parent contract must be included"); } else { // checking parent: // proper origin HashId rootId = parent.getRootId(); if (!rootId.equals(getRawOrigin())) { addError(BAD_VALUE, "state.origin", "wrong origin, should be root"); } if (!getParent().equals(parent.getId())) addError(BAD_VALUE, "state.parent", "illegal parent references"); ContractDelta delta = new ContractDelta(parent, this); delta.check(); checkRevokePermissions(delta.getRevokingItems()); } }
if(c.getParent().equals(delorean.getId())) { newDelorean = c;
if(c.getParent().equals(delorean.getId())) { newDelorean = c;
if(c.getParent().equals(lamborghini.getId())) { newLamborghini = c;
@Test public void newRevision() throws Exception { Contract c = Contract.fromDslFile(ROOT_CONTRACT); c.addSignerKeyFromFile(PRIVATE_KEY_PATH); byte[] sealed = c.seal(); assertTrue(c.check()); Contract c2 = c.createRevision(TestKeys.privateKey(0), TestKeys.privateKey(3)); assertEquals(1, c2.getRevokingItems().size()); assertEquals(c, c2.getRevokingItems().iterator().next()); assertEquals(2, c2.getKeysToSignWith().size()); assertEquals(2, c2.getRevision()); assertEquals(c.getId(), c2.getParent()); assertEquals(c.getId(), c2.getRawOrigin()); c2.seal(); Contract c3 = c2.createRevision(TestKeys.privateKey(0), TestKeys.privateKey(3)); assertEquals(1, c3.getRevokingItems().size()); assertEquals(c2, c3.getRevokingItems().iterator().next()); assertEquals(2, c3.getKeysToSignWith().size()); assertEquals(3, c3.getRevision()); assertEquals(c2.getId(), c3.getParent()); assertEquals(c.getId(), c3.getRawOrigin()); // c2.check(); // c2.traceErrors(); }
Contract newDelorean = null; for (Contract c : swapContract.getNew()) { if(c.getParent().equals(delorean.getId())) { newDelorean = c;
if(c.getParent().equals(lamborghini.getId())) { newLamborghini = c;
Contract parent = null; for (Contract nrc : nc.getRevoking()) { if (nrc.getId().equals(nc.getParent())) { parent = nrc; break;
if(c.getId().equals(payment.getContract().getParent())) { parent = c; break;