static Contract createSimpleContract(PrivateKey key) { Contract result = new Contract(); // default expiration date result.setExpiresAt(ZonedDateTime.now().plusDays(90)); // issuer role is a key for a new contract result.setIssuerKeys(key.getPublicKey().getShortAddress()); // issuer is owner, link roles result.registerRole(new RoleLink("owner", "issuer")); result.registerRole(new RoleLink("creator", "issuer")); return result; }
privateKeys.add(privateKey); contract.setIssuerKeys(privateKeys); contract.setExpiresAt(ZonedDateTime.now().plusDays(90)); contract.registerRole(new RoleLink("owner", "issuer"));
/** * Create a batch contract, which registers all the included contracts, possibily referencing each other, * in the single transaction, saving time and reducing U cost. Note that if any of the batched contracts * fails, the whole batch is rejected. * * @param contracts to register all in one batch. Shuld be prepared and sealed. * @param keys to sign batch with. * @return batch contract that includes all contracts as new items. */ public static Contract createBatch(Collection<PrivateKey> keys, Contract... contracts) { Contract batch = new Contract(); batch.setIssuerKeys(keys); batch.registerRole(new RoleLink("creator","issuer")); batch.registerRole(new RoleLink("owner","issuer")); batch.setExpiresAt(ZonedDateTime.now().plusDays(3)); for(Contract c : contracts) { batch.addNewItems(c); } batch.addSignerKeys(keys); batch.seal(); return batch; }
public void asd() throws Exception { PrivateKey key = new PrivateKey(Do.read("/Users/romanu/Downloads/ru/roman.uskov.privateKey.unikey")); Set<PrivateKey> issuers = new HashSet<>(); issuers.add(key); Set<PublicKey> owners = new HashSet<>(); owners.add(key.getPublicKey()); TestSpace testSpace = prepareTestSpace(); testSpace.nodes.forEach(n->n.config.setIsFreeRegistrationsAllowedFromYaml(true)); for(int i = 109; i < 110; i++) { Contract c = ContractsService.createTokenContract(issuers, owners, new BigDecimal("100000.9"), new BigDecimal("0.01")); c.setIssuerKeys(key.getPublicKey().getShortAddress()); c.setCreatorKeys(key.getPublicKey().getShortAddress()); c.setExpiresAt(ZonedDateTime.now().plusDays(10)); c.seal(); new FileOutputStream("/Users/romanu/Downloads/ru/token"+i+".unicon").write(c.getPackedTransaction()); assertEquals(testSpace.client.register(Contract.fromPackedTransaction(Do.read("/Users/romanu/Downloads/ru/token"+i+".unicon")).getPackedTransaction(),10000).state,ItemState.APPROVED); } }
/** * Create a default empty new contract using a provided key as issuer and owner and sealer. Default expiration is * set to 90 days. * <p> * This constructor adds key as sealing signature so it is ready to {@link #seal()} just after construction, thought * it is necessary to put real data to it first. It is allowed to change owner, expiration and data fields after * creation (but before sealing). * <p> * Change owner permission is added by default * @param key is {@link PrivateKey} for creating roles "issuer", "owner", "creator" and sign contract */ public Contract(PrivateKey key) { this(); // default expiration date setExpiresAt(ZonedDateTime.now().plusDays(90)); // issuer role is a key for a new contract setIssuerKeys(key.getPublicKey()); // issuer is owner, link roles registerRole(new RoleLink("owner", "issuer")); registerRole(new RoleLink("creator", "issuer")); RoleLink roleLink = new RoleLink("@change_ower_role","owner"); roleLink.setContract(this); // owner can change permission addPermission(new ChangeOwnerPermission(roleLink)); // issuer should sign addSignerKey(key); }
@Test public void shouldNotSplitWithAnotherIssuerSerialize() throws Exception { Contract c = createCoin(); c.addSignerKeyFromFile(PRIVATE_KEY_PATH); sealCheckTrace(c, true); Contract c2 = c.splitValue(FIELD_NAME, new Decimal(50)); c2.setIssuerKeys(ownerKey1.getPublicKey()); sealCheckTrace(c2, false); }
Contract consent = new Contract(); consent.setExpiresAt(ZonedDateTime.now().plusDays(10)); consent.setIssuerKeys(Arrays.asList(consentKeyAddresses)); consent.registerRole(new RoleLink("creator","issuer")); consent.registerRole(new RoleLink("owner","issuer"));
@Test public void issuerTest() throws Exception { KeyAddress keyAddress1 = TestKeys.privateKey(0).getPublicKey().getShortAddress(); KeyAddress keyAddress2 = TestKeys.privateKey(1).getPublicKey().getShortAddress(); Contract contract = new Contract(TestKeys.privateKey(2)); contract.setCreatorKeys(keyAddress1); contract.setIssuerKeys(keyAddress2); contract.addSignerKey(TestKeys.privateKey(0)); contract.seal(); assertFalse(contract.check()); contract.setIssuerKeys(keyAddress1); contract.getErrors().clear(); contract.seal(); assertTrue(contract.check()); }
c.setIssuerKeys(TestKeys.publicKey(3)); c.addSignerKey(TestKeys.privateKey(3)); c.registerRole(new RoleLink("owner", "issuer"));
private Contract createNetConfigContract(List<NodeInfo> netConfig,PrivateKey issuerKey) throws IOException { Contract contract = new Contract(); contract.setIssuerKeys(issuerKey.getPublicKey()); contract.registerRole(new RoleLink("creator", "issuer")); ListRole listRole = new ListRole("owner"); for(NodeInfo ni: netConfig) { SimpleRole role = new SimpleRole(ni.getName()); contract.registerRole(role); role.addKeyRecord(new KeyRecord(ni.getPublicKey())); listRole.addRole(role); } listRole.setQuorum(netConfig.size()-1); contract.registerRole(listRole); RoleLink ownerLink = new RoleLink("ownerlink","owner"); ChangeOwnerPermission changeOwnerPermission = new ChangeOwnerPermission(ownerLink); HashMap<String,Object> fieldsMap = new HashMap<>(); fieldsMap.put("net_config",null); Binder modifyDataParams = Binder.of("fields",fieldsMap); ModifyDataPermission modifyDataPermission = new ModifyDataPermission(ownerLink,modifyDataParams); contract.addPermission(changeOwnerPermission); contract.addPermission(modifyDataPermission); contract.setExpiresAt(ZonedDateTime.now().plusYears(40)); contract.getStateData().set("net_config",netConfig); contract.addSignerKey(issuerKey); contract.seal(); return contract; }
@Test public void registerContractWithAnonymousId() throws Exception { TestSpace ts = prepareTestSpace(); PrivateKey newPrivateKey = new PrivateKey(Do.read("./src/test_contracts/keys/u_key.private.unikey")); byte[] myAnonId = newPrivateKey.createAnonymousId(); Contract contract = new Contract(); contract.setExpiresAt(ZonedDateTime.now().plusDays(90)); Role r = contract.setIssuerKeys(AnonymousId.fromBytes(myAnonId)); contract.registerRole(new RoleLink("owner", "issuer")); contract.registerRole(new RoleLink("creator", "issuer")); contract.addPermission(new ChangeOwnerPermission(r)); contract.addSignerKey(newPrivateKey); contract.seal(); assertTrue(contract.isOk()); System.out.println("contract.check(): " + contract.check()); contract.traceErrors(); ts.client.getSession().setPrivateKey(newPrivateKey); ts.client.restart(); ItemResult itemResult = ts.client.register(contract.getPackedTransaction(), 5000); assertEquals(ItemState.APPROVED, itemResult.state); ts.nodes.forEach(x -> x.shutdown()); }
payload.setIssuerKeys(TestKeys.publicKey(3)); payload.addSignerKey(TestKeys.privateKey(3)); payload.registerRole(new RoleLink("owner", "issuer")); payment.setIssuerKeys(TestKeys.publicKey(3)); payment.addSignerKey(TestKeys.privateKey(3)); payment.registerRole(new RoleLink("owner", "issuer"));