/** * Set "owner" role to given keys * @param keys keys to set "owner" role to * @return owner role */ @NonNull public Role setOwnerKeys(Object... keys) { return setOwnerKeys(asList(keys)); }
public void setOwner(List<String> addresses) throws KeyAddress.IllegalAddressException { List<KeyAddress> addressesList = new ArrayList<>(); for (String s : addresses) addressesList.add(new KeyAddress(s)); this.currentContract.setOwnerKeys(addressesList); }
/** * Transfers payment contract to new owner on the result of escrow. * Use payment contract that was added to external escrow contract by * {@link ContractsService#addPaymentToEscrowContract(Contract, Contract, Collection, Collection, Collection)} or * was modified by {@link ContractsService#modifyPaymentForEscrowContract(Contract, Contract, Collection, Collection, Collection)}. * Executor can take the payment contract, if internal escrow contract are completed. * Customer can take the payment contract, if internal escrow contract are canceled. * For registration payment contract (returned by this method) need to add result internal escrow contract by * {@link TransactionPack#addReferencedItem(Contract)}. * * @param newOwnerKeys are private keys of new owner of payment * @param payment contract to take by new owner. Must be registered for creation new revision * * @return new revision of payment contract with new owner */ public static Contract takeEscrowPayment(Collection<PrivateKey> newOwnerKeys, Contract payment) { Contract revisionPayment = payment.createRevision(newOwnerKeys); // set new owner revisionPayment.setOwnerKeys(newOwnerKeys); // remove escrow references from Contract.references (from transactional section references removed automatically) revisionPayment.getReferences().remove("return_payment_to_customer"); revisionPayment.getReferences().remove("send_payment_to_executor"); revisionPayment.seal(); return revisionPayment; }
PrivateKey goodKey = c.getKeysToSignWith().iterator().next(); c.setOwnerKeys(goodKey); c.seal(); String contractFileName = basePath + "with_role_for_revoke.unicon";
PrivateKey goodKey = c.getKeysToSignWith().iterator().next(); c.setOwnerKeys(goodKey); c.seal();
twoSignContract.getTransactional().addReference(reference); twoSignContract.setOwnerKeys(toKeys); twoSignContract.seal();
@Test public void goodRevoke() throws Exception { Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml"); c.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey"); PrivateKey goodKey = c.getKeysToSignWith().iterator().next(); c.setOwnerKeys(new KeyRecord(goodKey.getPublicKey())); c.seal(); Contract revokeContract = c.createRevocation(goodKey); revokeContract.check(); assertTrue(revokeContract.isOk()); // tc.traceErrors(); }
jobCertificate.setOwnerKeys(stepaPublicKeys); jobCertificate.getDefinition().getData().set("issuer", "Roga & Kopita"); jobCertificate.getDefinition().getData().set("type", "chief accountant assignment");
jobCertificate.setOwnerKeys(stepaPublicKeys); jobCertificate.getDefinition().getData().set("issuer", "Roga & Kopita"); jobCertificate.getDefinition().getData().set("type", "chief accountant assignment"); llcProperty2.setOwnerKeys(thirdPartyPublicKeys); llcProperty2.seal(); llcProperty2.check();
jobCertificate.setOwnerKeys(stepaPublicKeys); jobCertificate.getDefinition().getData().set("issuer", "Roga & Kopita"); jobCertificate.getDefinition().getData().set("type", "chief accountant assignment");
anonSignedContract.setOwnerKeys(martyPublicKeys); anonSignedContract.setCreatorKeys(stepaAddress); anonSignedContract.addSignerKey(stepaPrivateKeys.iterator().next());
jobCertificate.setOwnerKeys(stepaPublicKeys); jobCertificate.getDefinition().getData().set("issuer", "Roga & Kopita"); jobCertificate.getDefinition().getData().set("type", "chief accountant assignment");
anonSignedContract.setOwnerKeys(martyPublicKeys); anonSignedContract.seal(); anonSignedContract.check();
anonSignedContract.setOwnerKeys(martyPublicKeys); anonSignedContract.setCreatorKeys(stepaAnonId); anonSignedContract.addSignerKey(stepaPrivateKeys.iterator().next());
anonSignedContract.setOwnerKeys(martyPublicKeys); anonSignedContract.seal(); anonSignedContract.check();
@Test public void goodRevokeAnother() throws Exception { Contract c1 = new Contract(ownerKey1); RoleLink rl = new RoleLink("@revoke", "owner"); rl.setContract(c1); c1.addPermission(new RevokePermission(rl)); c1.seal(); Contract c2 = new Contract(ownerKey2); c2.seal(); Assert.assertTrue(c2.check()); Contract c3 = c2.createRevision(ownerKey2); //to prevent "state is identical" c3.setOwnerKeys(ownerKey3); c3.addSignerKey(ownerKey1); c3.addRevokingItems(c1); c3.seal(); assertTrue(c3.check()); }
@Test public void jsInStateAndDefinition() throws Exception { Contract contract = new Contract(TestKeys.privateKey(0)); contract.setOwnerKeys(TestKeys.publicKey(1), TestKeys.publicKey(2), TestKeys.publicKey(3)); contract.setCreatorKeys(TestKeys.publicKey(4), TestKeys.publicKey(5).getLongAddress()); String jsDefinitionA = "print('hello world from definition A'); result = 'dA';"; String jsDefinitionB = "print('hello world from definition B'); result = 'dB';"; String jsStateA = "print('hello world from state A'); result = 'sA';"; String jsStateB = "print('hello world from state B'); result = 'sB';"; contract.getDefinition().setJS(jsDefinitionA.getBytes(), "script1.js", new JSApiScriptParameters(), true); contract.getDefinition().setJS(jsDefinitionB.getBytes(), "script2.js", new JSApiScriptParameters(), true); contract.getState().setJS(jsStateA.getBytes(), "script3.js", new JSApiScriptParameters(), true); contract.getState().setJS(jsStateB.getBytes(), "script4.js", new JSApiScriptParameters(), true); contract.seal(); String res1 = (String)contract.execJSByName("script1.js"); String res2 = (String)contract.execJSByName("script2.js"); String res3 = (String)contract.execJSByName("script3.js"); String res4 = (String)contract.execJSByName("script4.js"); assertEquals("dA", res1); assertEquals("dB", res2); assertEquals("sA", res3); assertEquals("sB", res4); }
@Test public void jsInContract() throws Exception { Contract contract = new Contract(TestKeys.privateKey(0)); contract.setOwnerKeys(TestKeys.publicKey(1), TestKeys.publicKey(2), TestKeys.publicKey(3)); contract.setCreatorKeys(TestKeys.publicKey(4), TestKeys.publicKey(5).getLongAddress()); System.out.println("testKey[10].getShortAddress: " + TestKeys.publicKey(10).getShortAddress().toString()); System.out.println("testKey[11].getShortAddress: " + TestKeys.publicKey(11).getShortAddress().toString()); contract.getStateData().set("some_value", HashId.createRandom().toBase64String()); contract.getStateData().set("some_hash_id", HashId.createRandom()); String js = ""; js += "print('hello world');"; js += "var currentContract = jsApi.getCurrentContract();"; js += "print('currentContract.getId(): ' + currentContract.getId());"; js += "print('currentContract.getRevision(): ' + currentContract.getRevision());"; js += "print('currentContract.getCreatedAt(): ' + currentContract.getCreatedAt());"; js += "print('currentContract.getOrigin(): ' + currentContract.getOrigin());"; js += "print('currentContract.getParent(): ' + currentContract.getParent());"; js += "print('currentContract.getStateDataField(some_value): ' + currentContract.getStateDataField('some_value'));"; js += "print('currentContract.getStateDataField(some_hash_id): ' + currentContract.getStateDataField('some_hash_id'));"; js += "print('currentContract.getDefinitionDataField(scripts): ' + currentContract.getDefinitionDataField('scripts'));"; js += "print('currentContract.getIssuer(): ' + currentContract.getIssuer());"; js += "print('currentContract.getOwner(): ' + currentContract.getOwner());"; js += "print('currentContract.getCreator(): ' + currentContract.getCreator());"; js += "print('call currentContract.setOwner()...');"; js += "currentContract.setOwner(['ZastWpWNPMqvVJAMocsMUTJg45i8LoC5Msmr7Lt9EaJJRwV2xV', 'a1sxhjdtGhNeji8SWJNPkwV5m6dgWfrQBnhiAxbQwZT6Y5FsXD']);"; js += "print('currentContract.getOwner(): ' + currentContract.getOwner());"; contract.getDefinition().setJS(js.getBytes(), "client script.js", new JSApiScriptParameters()); contract.seal(); contract.execJS(js.getBytes()); }
c3.addSignerKey(ownerKey1); c3.setOwnerKeys(ownerKey2); c2.seal(); c3.seal(); c4.setOwnerKeys(ownerKey3); c4.addSignerKey(ownerKey1);
@Test public void badRevokeAnother() throws Exception { Contract c1 = new Contract(ownerKey1); RoleLink rl = new RoleLink("@revoke", "owner"); rl.setContract(c1); c1.addPermission(new RevokePermission(rl)); c1.seal(); Contract c2 = new Contract(ownerKey2); c2.seal(); Assert.assertTrue(c2.check()); Contract c3 = c2.createRevision(ownerKey2); //to prevent "state is identical" c3.setOwnerKeys(ownerKey3); c3.addRevokingItems(c1); c3.seal(); assertFalse(c3.check()); }