/** * Create revocation contract. To revoke the contract it is necessary that it has "revoke" permission, and one need * the keys to be able to play the role assigned to it. * <p> * So, to revoke some contract: * <p> * - call {@link #createRevocation(PrivateKey...)} with key or keys that can play the role for "revoke" permission * <p> * - register it in the Universa network, see {@link com.icodici.universa.node2.network.Client#register(byte[], long)}. * Upon the successful registration the source contract will be revoked. Use transaction contract's {@link * #getPackedTransaction()} to obtain a binary to submit to the client. * * @param keys one or more keys that together can play the role assigned to the revoke permission. * * @return ready sealed contract that revokes this contract on registration */ public Contract createRevocation(PrivateKey... keys) { return ContractsService.createRevocation(this, keys); }
/** * Creates a simple notary contract for given keys and attach the data to notary contract. * <br><br> * The service creates a notary contract with issuer, creator and owner roles * with change_owner permission for owner and revoke permissions for owner and issuer. * The service attach the data to notary contract. * By default expires at time is set to 60 months from now. * <br><br> * * @param issuerKeys is issuer private keys. * @param ownerKeys is owner public keys. * @param filePaths is path to data file. * @return signed and sealed contract, ready for register. */ public synchronized static Contract createNotaryContract(Set<PrivateKey> issuerKeys, Set<PublicKey> ownerKeys, List<String> filePaths) { return createNotaryContract(issuerKeys, ownerKeys, filePaths, null); }
/** * Create paid transaction, which consist from contract you want to register and payment contract that will be * spend to process transaction. * <br><br> * * @param payload is prepared contract you want to register in the Universa. * @param payment is approved contract with "U" belongs to you. * @param amount is number of "U" you want to spend to register payload contract. * @param keys is own private keys, which are set as owner of payment contract * @return parcel, it ready to send to the Universa. */ public synchronized static Parcel createParcel(Contract payload, Contract payment, int amount, Set<PrivateKey> keys) { return createParcel(payload, payment, amount, keys, false); }
Contract escrow = ContractsService.createEscrowContract(issuerPrivateKeys, customerPublicKeys, executorPublicKeys, arbitratorPublicKeys); boolean result = ContractsService.addPaymentToEscrowContract(escrow, payment, customerPrivateKeys, customerPublicKeys, executorPublicKeys); assertTrue(result); Contract completedEscrow = ContractsService.completeEscrowContract(escrow); Contract newPayment = ContractsService.takeEscrowPayment(executorPrivateKeys, payment);
Contract escrow = ContractsService.createEscrowContract(issuerPrivateKeys, customerPublicKeys, executorPublicKeys, arbitratorPublicKeys); boolean result = ContractsService.addPaymentToEscrowContract(escrow, payment, customerPrivateKeys, customerPublicKeys, executorPublicKeys); assertTrue(result); Contract canceledEscrow = ContractsService.cancelEscrowContract(escrow); Contract newPayment = ContractsService.takeEscrowPayment(customerPrivateKeys, payment);
Contract utnContract = ContractsService.createTokenContract(utnIssuer, ownerKeys, new BigDecimal("100000")); @NonNull ItemResult ir = testSpace.client.register(utnContract.getPackedTransaction()); Contract compound = ContractsService.createSplit(utnContract, new BigDecimal("150"), "amount", new HashSet<>(),true); Contract paymentInUTNs = (Contract) compound.getNewItems().iterator().next(); paymentInUTNs.setOwnerKeys(universaAdminKey); Contract consent = ContractsService.addConsent(uContract, universaAdminKey.getPublicKey().getLongAddress()); uContract.seal(); compound.addNewItems(uContract); compound.addSignatureToSeal(userKeys); Contract batch = ContractsService.createBatch(userKeys, compound, consent); Parcel parcel = ContractsService.createParcel(sampleContract,uContract,1,userKeys); testSpace.client.registerParcelWithState(parcel.pack(),5000); do { Contract revocation = ContractsService.createRevocation(consent, universaAdminKey); ir = testSpace.client.register(revocation.getPackedTransaction()); while(ir.state.isPending()) { parcel = ContractsService.createParcel(sampleContract,uContract,1,userKeys); testSpace.client.registerParcelWithState(parcel.pack(),5000); do {
swapContract = ContractsService.startSwap(delorean, lamborghini, martyPrivateKeys, stepaPublicKeys); ContractsService.signPresentedSwap(swapContract, stepaPrivateKeys); ContractsService.finishSwap(swapContract, martyPrivateKeys);
Contract oldAccountCertificate = ContractsService.createNotaryContract(llcPrivateKeys, stepaPublicKeys); oldAccountCertificate.getDefinition().getData().set("type", "Good Bank"); oldAccountCertificate.getDefinition().getData().set("is_really_good", true); Contract llcProperty = ContractsService.createTokenContract(llcPrivateKeys, stepaPublicKeys, new BigDecimal("100")); ContractsService.addReferenceToContract(llcProperty, oldAccountCertificate, "bank_certificate", Reference.TYPE_EXISTING_DEFINITION, listConditionsForDefinition, true); Contract llcProperty2 = ContractsService.createSplit(llcProperty, new BigDecimal("80"), "amount", stepaPrivateKeys, true); llcProperty2 = ContractsService.createSplit(llcProperty, new BigDecimal("80"), "amount", stepaPrivateKeys, true);
Contract llcProperty = ContractsService.createNotaryContract(llcPrivateKeys, stepaPublicKeys); listConditions.add("ref.definition.data.type == \"chief accountant assignment\""); ContractsService.addReferenceToContract(llcProperty, jobCertificate, "certification_contract", Reference.TYPE_EXISTING_DEFINITION, listConditions, true); Contract llcProperty2 = ContractsService.createRevocation(llcProperty, stepaPrivateKeys.iterator().next()); llcProperty2.check(); llcProperty2.traceErrors();
Contract escrow = ContractsService.createInternalEscrowContract(issuerPrivateKeys, customerPublicKeys, executorPublicKeys, arbitratorPublicKeys); payment = ContractsService.modifyPaymentForEscrowContract(escrow, payment, customerPrivateKeys, customerPublicKeys, executorPublicKeys); Contract canceledEscrow = ContractsService.cancelEscrowContract(escrow); Contract newPayment = ContractsService.takeEscrowPayment(customerPrivateKeys, payment);
Contract escrow = ContractsService.createInternalEscrowContract(issuerPrivateKeys, customerPublicKeys, executorPublicKeys, arbitratorPublicKeys); payment = ContractsService.modifyPaymentForEscrowContract(escrow, payment, customerPrivateKeys, customerPublicKeys, executorPublicKeys); Contract completedEscrow = ContractsService.completeEscrowContract(escrow); Contract newPayment = ContractsService.takeEscrowPayment(executorPrivateKeys, payment);
Contract llcProperty = ContractsService.createTokenContract(llcPrivateKeys, stepaPublicKeys, new BigDecimal("100")); ContractsService.addReferenceToContract(llcProperty, oldAccountCertificate, "bank_certificate", Reference.TYPE_EXISTING_DEFINITION, listConditionsForDefinition, true); Contract llcProperty3 = ContractsService.createSplit(llcProperty2, new BigDecimal("80"), "amount", stepaPrivateKeys, true); llcProperty3.check(); llcProperty3.traceErrors(); Contract llcProperty4 = ContractsService.createJoin(llcProperty3, llcProperty3.getNew().get(0), "amount", stepaPrivateKeys); llcProperty4.check(); llcProperty4.traceErrors();
/** * @see #createTokenContract(Set, Set, BigDecimal, BigDecimal, String, String, String) */ public synchronized static Contract createTokenContract(Set<PrivateKey> issuerKeys, Set<PublicKey> ownerKeys, BigDecimal amount, BigDecimal minValue) { return createTokenContract(issuerKeys, ownerKeys, amount, minValue, "DT", "Default token name", "Default token description"); }
Contract llcProperty = ContractsService.createTokenContract(llcPrivateKeys, stepaPublicKeys, new BigDecimal("100000000000")); listConditions.add("ref.definition.data.type == \"chief accountant assignment\""); ContractsService.addReferenceToContract(llcProperty, jobCertificate, "certification_contract", Reference.TYPE_EXISTING_DEFINITION, listConditions, true); Contract llcProperty2 = ContractsService.createSplit(llcProperty, new BigDecimal("100"), "amount", stepaPrivateKeys, true); llcProperty2.check(); llcProperty2.traceErrors();
assertEquals(ItemState.APPROVED, client.getState(jobCertificate.getId()).state); Contract llcProperty = ContractsService.createNotaryContract(llcPrivateKeys, stepaPublicKeys); listConditions.add("ref.definition.data.type == \"chief accountant assignment\""); ContractsService.addReferenceToContract(llcProperty, jobCertificate, "certification_contract", Reference.TYPE_EXISTING_DEFINITION, listConditions, true);
/** * Implementing split procedure for token-type contracts. * <br><br> * Service create new revision of given contract, split it to a pair of contracts with split amount. * <br><br> * Given contract should have splitjoin permission for given keys. * <br><br> * * @param c is contract should split be * @param amount is value that should be split from given contract * @param fieldName is name of field that should be split * @param keys is keys from owner of c * @return working contract that should be register in the Universa to finish procedure. */ public synchronized static Contract createSplit(Contract c, BigDecimal amount, String fieldName, Set<PrivateKey> keys) { return createSplit(c, amount, fieldName, keys, false); }
Contract escrow = ContractsService.createEscrowContract(issuerPrivateKeys, customerPublicKeys, executorPublicKeys, arbitratorPublicKeys); boolean result = ContractsService.addPaymentToEscrowContract(escrow, payment, customerPrivateKeys, customerPublicKeys, executorPublicKeys); assertTrue(result); Contract newPayment = ContractsService.takeEscrowPayment(issuerPrivateKeys, payment); newPayment = ContractsService.takeEscrowPayment(customerPrivateKeys, payment); newPayment = ContractsService.takeEscrowPayment(executorPrivateKeys, payment);
@Test public void testRevocationContractsApi() throws Exception { List<Main> mm = new ArrayList<>(); for (int i = 0; i < 4; i++) mm.add(createMain("node" + (i + 1), false)); Main main = mm.get(0); main.config.setIsFreeRegistrationsAllowedFromYaml(true); Client client = new Client(TestKeys.privateKey(20), main.myInfo, null); Set<PrivateKey> issuerPrivateKeys = new HashSet<>(Arrays.asList(TestKeys.privateKey(1))); Set<PublicKey> ownerPublicKeys = new HashSet<>(Arrays.asList(TestKeys.publicKey(2))); Contract sourceContract = ContractsService.createShareContract(issuerPrivateKeys, ownerPublicKeys, new BigDecimal("100")); sourceContract.check(); sourceContract.traceErrors(); ItemResult itemResult = client.register(sourceContract.getPackedTransaction(), 5000); System.out.println("sourceContract : " + itemResult); assertEquals(ItemState.APPROVED, client.getState(sourceContract.getId()).state); Contract revokeContract = ContractsService.createRevocation(sourceContract, TestKeys.privateKey(1)); revokeContract.check(); revokeContract.traceErrors(); itemResult = client.register(revokeContract.getPackedTransaction(), 5000); System.out.println("revokeContract : " + itemResult); assertEquals(ItemState.APPROVED, client.getState(revokeContract.getId()).state); assertEquals(ItemState.REVOKED, client.getState(sourceContract.getId()).state); mm.forEach(x -> x.shutdown()); }
swapContract = ContractsService.startSwap(delorean, lamborghini, martyPrivateKeys, stepaPublicKeys); ContractsService.signPresentedSwap(swapContract, stepaPrivateKeys);
swapContract = ContractsService.startSwap(delorean, lamborghini, martyPrivateKeys, stepaPublicKeys); ContractsService.finishSwap(swapContract, martyPrivateKeys);