private boolean hasAllKeys(SimpleRole role1, SimpleRole role2) { if(!role1.keyRecords.keySet().stream().allMatch(k-> role2.keyRecords.containsKey(k) || role2.keyAddresses.contains(k.getShortAddress()) || role2.keyAddresses.contains(k.getLongAddress()) || role2.anonymousIds.contains(new AnonymousId(k.createAnonymousId())))) return false; if(!role1.keyAddresses.stream().allMatch(ka-> role2.keyAddresses.contains(ka) || role2.keyRecords.keySet().stream().anyMatch(key->ka.equals(key.getShortAddress()) || ka.equals(key.getLongAddress())))) return false; if(!role1.anonymousIds.stream().allMatch(anonymousId -> role2.anonymousIds.contains(anonymousId) || role2.keyRecords.keySet().stream().anyMatch(key->new AnonymousId(key.createAnonymousId()).equals(anonymousId)))) return false; return true; }
KeyAddress ownerAddress = ownerPublicKey.getLongAddress(); Set<PublicKey> ownerPublicKeys = new HashSet<>(); ownerPublicKeys.add(ownerPublicKey);
case 1: ref.type = Reference.TYPE_EXISTING_DEFINITION; ref.setConditions(Binder.of(Reference.conditionsModeType.all_of.name(),asList("ref.owner=="+keys100.get(random.nextInt(keys100.size())).getPublicKey().getLongAddress()))); break; case 2:
@Test public void getAllAddresses() throws Exception { Contract contract = new Contract(TestKeys.privateKey(0)); ListRole owner = new ListRole("owner"); owner.addRole(new SimpleRole("owner", Arrays.asList(TestKeys.publicKey(0), TestKeys.publicKey(1)))); owner.addRole(new SimpleRole("owner", Arrays.asList(TestKeys.publicKey(2).getLongAddress()))); owner.addRole(new SimpleRole("owner", Arrays.asList(TestKeys.publicKey(3).getShortAddress(), TestKeys.publicKey(4)))); contract.registerRole(owner); List<String> addresses = contract.getRole("owner").getAllAddresses(); System.out.println("owner: " + addresses); for (String addr : addresses) assertThat(addr, Matchers.anyOf( Matchers.equalTo(TestKeys.publicKey(0).getShortAddress().toString()), Matchers.equalTo(TestKeys.publicKey(1).getShortAddress().toString()), Matchers.equalTo(TestKeys.publicKey(2).getLongAddress().toString()), Matchers.equalTo(TestKeys.publicKey(3).getShortAddress().toString()), Matchers.equalTo(TestKeys.publicKey(4).getShortAddress().toString()) )); }
KeyAddress stepaAddress = stepaPublicKeys.iterator().next().getLongAddress(); Contract anonOwnerContract = c1.createRevision(key); anonOwnerContract.setOwnerKey(stepaAddress);
@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()); }
@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 testListRoleCheckAll() throws Exception { KeyAddress k0 = TestKeys.publicKey(0).getShortAddress(); KeyAddress k1 = TestKeys.publicKey(1).getLongAddress(); KeyAddress k2 = TestKeys.publicKey(2).getShortAddress(); KeyAddress k3 = TestKeys.publicKey(3).getLongAddress(); String p0 = TestKeys.publicKey(0).packToBase64String(); String p1 = TestKeys.publicKey(1).packToBase64String();
Contract consent = ContractsService.addConsent(uContract, universaAdminKey.getPublicKey().getLongAddress()); uContract.seal(); compound.addNewItems(uContract);
@Test public void testListRoleCheckAny() throws Exception { KeyAddress k0 = TestKeys.publicKey(0).getLongAddress(); KeyAddress k1 = TestKeys.publicKey(1).getShortAddress(); KeyAddress k2 = TestKeys.publicKey(2).getLongAddress(); KeyAddress k3 = TestKeys.publicKey(3).getShortAddress(); String p0 = TestKeys.publicKey(0).packToBase64String();
referencesContract.getId().getDigest(), randomPrivKey.getPublicKey().getShortAddress().toString(), randomPrivKey.getPublicKey().getLongAddress().toString()); ResultSet rs = ps.executeQuery(); assertTrue(rs.next()); referencesContract.getId().getDigest(), randomPrivKey.getPublicKey().getShortAddress().toString(), randomPrivKey.getPublicKey().getLongAddress().toString()); rs = ps.executeQuery(); assertTrue(rs.next());
KeyAddress k0 = TestKeys.publicKey(0).getShortAddress(); KeyAddress k1 = TestKeys.publicKey(1).getShortAddress(); KeyAddress k2 = TestKeys.publicKey(2).getLongAddress(); KeyAddress k3 = TestKeys.publicKey(3).getLongAddress(); String p0 = TestKeys.publicKey(0).packToBase64String(); String p1 = TestKeys.publicKey(1).packToBase64String();