private Contract joinAndRemoveFromContracts(List<Contract> selectedContracts) throws Exception { Contract result = selectedContracts.get(0).copy(); result.getRevokingItems().addAll(selectedContracts); this.contracts.removeAll(selectedContracts); result.setKeysToSignWith(selectedContracts.get(0).getKeysToSignWith()); return result; }
/** * Add contract that already includes all its subItems, referenced items and keys. It will be added as a contract * per transaction, while its subItems will be added to subItems if not already included and refrenced items and keys too. * <p> * This is extremely important that the contract is properly sealed as well as its possibly new items, revoking * items and referenced items have binary image attached. <b>Do not ever seal the approved contract</b>: * it will break it's id and cancel the approval blockchain, so the new state will not be approved. * If it was done by mistake, reload the packed contract to continue. * * @param c is a contract to append to the list of transactions. */ public void setContract(Contract c) { if (contract != null) throw new IllegalArgumentException("the contract is already added"); contract = c; packedBinary = null; extractAllSubItemsAndReferenced(c); c.setTransactionPack(this); for (PrivateKey key : c.getKeysToSignWith()) addKeys(key.getPublicKey()); }
c.setKeysToSignWith(new HashSet<>(getKeysToSignWith()));
Contract createComplexConctract(PrivateKey key,int subcontracts) { Contract root = new Contract(key); for(int i = 0; i < subcontracts; i++) { Contract c = new Contract(key); c.getKeysToSignWith().clear(); root.addNewItems(c); } root.seal(); return root; }
data = contract.getLastSealedBinary(); int count = contract.getKeysToSignWith().size(); if (count > 0) report("Contract is sealed with " + count + " key(s)");
@Test public void probeFile() throws Exception { Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml"); c.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey"); c.addSignerKeyFromFile(rootPath + "keys/u_key.private.unikey"); PrivateKey goodKey = c.getKeysToSignWith().iterator().next(); // let's make this key among owners ((SimpleRole)c.getRole("owner")).addKeyRecord(new KeyRecord(goodKey.getPublicKey())); c.seal(); Files.write(Paths.get(basePath + "probeFile.unicon"),c.getPackedTransaction(), StandardOpenOption.CREATE, StandardOpenOption.WRITE); System.out.println("---"); System.out.println("register contract"); System.out.println("---"); CLIMain.registerContract(c); Thread.sleep(1500); System.out.println("---"); System.out.println("check contract"); System.out.println("---"); callMain("--probe-file", basePath + "probeFile.unicon"); System.out.println(output); assertTrue (output.indexOf(ItemState.APPROVED.name()) >= 0); }
PrivateKey goodKey = c.getKeysToSignWith().iterator().next();
Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml"); c.addSignerKeyFromFile(rootPath + "_xer0yfe2nn1xthc.private.unikey"); PrivateKey goodKey = c.getKeysToSignWith().iterator().next();
PrivateKey goodKey = c.getKeysToSignWith().iterator().next();
c.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey"); c.addSignerKeyFromFile(rootPath + "keys/u_key.private.unikey"); PrivateKey goodKey = c.getKeysToSignWith().iterator().next();
twoSignContract.getKeysToSignWith().clear();
@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(); }
PrivateKey goodKey = c.getKeysToSignWith().iterator().next();
PrivateKey goodKey1 = c1.getKeysToSignWith().iterator().next(); PrivateKey goodKey2 = c2.getKeysToSignWith().iterator().next(); PrivateKey goodKey3 = c3.getKeysToSignWith().iterator().next();
@Test public void newRevision() throws Exception { Contract c = Contract.fromDslFile(ROOT_CONTRACT); c.addSignerKeyFromFile(PRIVATE_KEY_PATH); byte[] sealed = c.seal(); assertTrue(c.check()); Contract c2 = c.createRevision(TestKeys.privateKey(0), TestKeys.privateKey(3)); assertEquals(1, c2.getRevokingItems().size()); assertEquals(c, c2.getRevokingItems().iterator().next()); assertEquals(2, c2.getKeysToSignWith().size()); assertEquals(2, c2.getRevision()); assertEquals(c.getId(), c2.getParent()); assertEquals(c.getId(), c2.getRawOrigin()); c2.seal(); Contract c3 = c2.createRevision(TestKeys.privateKey(0), TestKeys.privateKey(3)); assertEquals(1, c3.getRevokingItems().size()); assertEquals(c2, c3.getRevokingItems().iterator().next()); assertEquals(2, c3.getKeysToSignWith().size()); assertEquals(3, c3.getRevision()); assertEquals(c2.getId(), c3.getParent()); assertEquals(c.getId(), c3.getRawOrigin()); // c2.check(); // c2.traceErrors(); }
martyCoinsSplit.getKeysToSignWith().clear(); martyCoinsSplit.removeAllSignatures(); martyCoinsSplit.seal();