private void addOriginReference(HashId origin) { Reference ref = new Reference(this); ref.type = Reference.TYPE_EXISTING_STATE; ref.setName(origin.toString()); List<Object> conditionsList = new ArrayList<>(); conditionsList.add(REFERENCE_CONDITION_PREFIX+origin.toBase64String()); Binder conditions = Binder.of(Reference.conditionsModeType.all_of.name(),conditionsList); ref.setConditions(conditions); if(originContracts.containsKey(origin)) ref.addMatchingItem(originContracts.get(origin)); addReference(ref); }
isOriginCondition(cond, origin))).collect(Collectors.toList()).get(0); if(reference.matchingItems.isEmpty() && originContracts.containsKey(origin)) reference.addMatchingItem(originContracts.get(origin));
public void addReferencedItems(Approvable... items) { Stream.of(items).forEach(i -> { Reference refModel = new Reference(); refModel.name = i.getId().toBase64String(); refModel.type = Reference.TYPE_EXISTING_DEFINITION; refModel.addMatchingItem(i); references.put(refModel.name, refModel); }); }
(rm.getConditions().size() > 0)) // new format of reference with conditions, transactional_id - optional if (rm.isMatchingWith(neighbour, neighbours)) { rm.addMatchingItem(neighbour); rm_check = true; break; rm.addMatchingItem(neighbour);
/** * Add to base {@link Contract} reference and referenced contract. * When the returned {@link Contract} is unpacking referenced contract verifies * the compliance with the conditions of reference in base contract. * <br><br> * Also reference to base contract may be added by {@link Contract#addReference(Reference)}. * <br><br> * * @param baseContract is base contract fro adding reference. * @param refContract is referenced contract (which must satisfy the conditions of the reference). * @param refName is name of reference. * @param refType is type of reference (section, may be {@link Reference#TYPE_TRANSACTIONAL}, {@link Reference#TYPE_EXISTING_DEFINITION}, or {@link Reference#TYPE_EXISTING_STATE}). * @param conditions is conditions of the reference. * @return ready {@link Contract} */ public synchronized static Contract addReferenceToContract( Contract baseContract, Contract refContract, String refName, int refType, Binder conditions) { Reference reference = new Reference(baseContract); reference.name = refName; reference.type = refType; reference.setConditions(conditions); reference.addMatchingItem(refContract); baseContract.addReference(reference); baseContract.seal(); return baseContract; }
Contract c = Contract.fromDslFile(rootPath + "NotaryWithReferenceDSLTemplate.yml"); c.addSignerKeyFromFile(PRIVATE_KEY_PATH); c.findReferenceByName("certification_contract").addMatchingItem(referencedItem); c1.findReferenceByName("certification_contract").addMatchingItem(referencedItem); assertNotEquals(c.getOwner(), c1.getOwner()); c1.seal(); ref.name = "certification_contract"; ref.type = Reference.TYPE_EXISTING_DEFINITION; ref.addMatchingItem(new Contract()); c3.getRevoking().get(0).getReferences().put(ref.name, ref);
conditionsRefDef.set("all_of", listConditionsRefDef); referenceDef.setConditions(conditionsRefDef); referenceDef.addMatchingItem(contractCertificate); conditionsRefState.set("all_of", listConditionsRefState); referenceState.setConditions(conditionsRefState); referenceState.addMatchingItem(contractCertificate);
@Test public void modifyReferencesDeclined() throws Exception { Contract contract = new Contract(TestKeys.privateKey(0)); ModifyDataPermission modifyDataPermission = new ModifyDataPermission(contract.getRole("owner"),new Binder()); modifyDataPermission.addField("references", null); contract.addPermission(modifyDataPermission); contract.seal(); Contract referencedContract = new Contract(TestKeys.privateKey(1)); referencedContract.seal(); Contract changed = contract.createRevision(); changed.addSignerKey(TestKeys.privateKey(0)); Reference ref = new Reference(referencedContract); ref.addMatchingItem(referencedContract); ref.type = Reference.TYPE_EXISTING_STATE; changed.addReference(ref); changed.seal(); changed.check(); assertTrue(!changed.isOk()); }
@Test public void modifyReferencesAllowed() throws Exception { Contract contract = new Contract(TestKeys.privateKey(0)); ModifyDataPermission modifyDataPermission = new ModifyDataPermission(contract.getRole("owner"),new Binder()); modifyDataPermission.addField("/references", null); contract.addPermission(modifyDataPermission); contract.seal(); Contract referencedContract = new Contract(TestKeys.privateKey(1)); referencedContract.seal(); Contract changed = contract.createRevision(); changed.addSignerKey(TestKeys.privateKey(0)); Reference ref = new Reference(referencedContract); ref.type = Reference.TYPE_EXISTING_STATE; ref.addMatchingItem(referencedContract); changed.addReference(ref); changed.seal(); changed.check(); changed.traceErrors(); assertTrue(changed.isOk()); }
ref.type = Reference.TYPE_EXISTING_STATE; ref.setConditions(conditionsForDefinition); ref.addMatchingItem(referencedContract);