/** * Get contracts current contract creates upon registration * @return contracts to be created */ public List<? extends Contract> getNew() { return new ArrayList<Contract>((Collection) getNewItems()); }
/** * Trace the tree of contracts subItems on the stdout. */ public void trace() { System.out.println("Transaction pack"); System.out.println("\tContract:"); System.out.println("\t\t" + contract.getId()); contract.getNewItems().forEach(x -> System.out.println("\t\t\tnew: " + x.getId())); contract.getRevokingItems().forEach(x -> System.out.println("\t\t\trevoke: " + x.getId())); System.out.println("\tSubItems:"); subItems.forEach((hashId, contract) -> System.out.println("\t\t" + hashId + " -> " + contract.getId())); }
public void checkSimplePack(TransactionPack tp) { assertEquals(3, tp.getSubItems().size()); assertEquals(c.getId(), tp.getContract().getId()); Set<HashId> rids = c.getRevokingItems().stream().map(x->x.getId()).collect(Collectors.toSet()); Set<HashId> nids = c.getNewItems().stream().map(x->x.getId()).collect(Collectors.toSet()); assertTrue(rids.contains(r0.getId())); assertTrue(nids.contains(n0.getId())); assertTrue(nids.contains(n1.getId())); }
private static void saveContractSubitems(String source, String suffix, Contract contract) throws IOException { try { report("unpack contract from " + source); int i = 1; if (contract.getNewItems() != null) { for (Approvable newItem : contract.getNewItems()) { String newItemFileName = new FilenameTool(source).addSuffixToBase(suffix+"_new_item_" + i).toString(); report("save newItem to " + newItemFileName); // ((Contract) newItem).seal(); saveContract((Contract) newItem, newItemFileName); i++; } } i = 1; if (contract.getRevokingItems() != null) { for (Approvable revokeItem : contract.getRevokingItems()) { String revokeItemFileName = new FilenameTool(source).addSuffixToBase(suffix+"_revoke_" + i).setExtension("unicon").toString(); report("save revokeItem to " + revokeItemFileName); saveContract((Contract) revokeItem, revokeItemFileName); i++; } } } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", contract.toString(), e.getMessage()); } }
protected synchronized void destroyFromAllNodesExistingNew(Contract c50_1) { StateRecord orCreate; for (Approvable c : c50_1.getNewItems()) { for (Node nodeS : nodesMap.values()) { orCreate = nodeS.getLedger().getRecord(c.getId()); if (orCreate != null) orCreate.destroy(); } } }
@Test public void packedContractNotContainsOtherItems() throws Exception { // if we seal and load a contract without a pack, it should have empty // containers for new and revoking items - these should be fill separately. Contract c2 = new Contract(c.seal()); assertEquals(0, c2.getRevokingItems().size()); assertEquals(0, c2.getNewItems().size()); }
}); tp.getContract().getNewItems().forEach(a -> { resultsNew.put(a.getId(),new HashMap<>()); });
@Ignore @Test public void registerFromFile() throws Exception { TestSpace testSpace = prepareTestSpace(TestKeys.privateKey(0)); testSpace.nodes.forEach(m -> m.config.setIsFreeRegistrationsAllowedFromYaml(true)); Path path = Paths.get("/tmp/not3.unicon"); byte[] testTransactionPackBytes = Files.readAllBytes(path); Contract contract = Contract.fromPackedTransaction(testTransactionPackBytes); System.out.println("======================"); System.out.println("check(): " + contract.check()); System.out.println("------- errors -------"); contract.traceErrors(); int i = 0; for (Approvable a : contract.getNewItems()) { Contract nc = (Contract) a; System.out.println("------- errors n"+i+" ----"); System.out.println(" check: " + nc.check()); nc.traceErrors(); ++i; } System.out.println("======================"); System.out.println("hashId: " + contract.getId().toBase64String()); testSpace.node.setVerboseLevel(DatagramAdapter.VerboseLevel.BASE); ItemResult itemResult = testSpace.client.register(testTransactionPackBytes, 5000); ItemResult itemResult2 = testSpace.client.getState(contract.getId()); System.out.println("itemResult: " + itemResult); System.out.println("itemResult2: " + itemResult2); testSpace.nodes.forEach(m -> m.shutdown()); }
List<Approvable> n1 = new ArrayList<>(c.getNewItems()); List<Approvable> n2 = new ArrayList<>(c1.getNewItems());
System.out.println("Transaction contract for swapping is valid: " + swapContract.isOk() + " num new contracts: " + swapContract.getNewItems().size());
System.out.println("Transaction contract for swapping is valid: " + swapContract.isOk() + " num new contracts: " + swapContract.getNewItems().size()); registerAndCheckApproved(swapContract); for(Approvable a : swapContract.getNewItems()) { assertEquals(ItemState.APPROVED, node.waitItem(a.getId(), 5000).state); System.out.println("new is " + node.waitItem(a.getId(), 5000).state);
@Test public void dupesWrongTest() throws Exception { PrivateKey key = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey")); Set<PrivateKey> keys = new HashSet<>(); keys.add(key); Contract c_1 = Contract.fromDslFile(rootPath + "coin100.yml"); c_1.addSignerKey(key); c_1.seal(); assertTrue(c_1.check()); c_1.traceErrors(); Contract c_2_1 = ContractsService.createSplit(c_1, new BigDecimal("20"), "amount", keys); Contract c_2_2 = c_2_1.getNew().get(0); if(c_2_2 != null) { Contract c_2_3 = c_2_2.copy(); c_2_3.addSignerKey(key); c_2_3.seal(); c_2_1.addNewItems(c_2_3); } assertEquals(2, c_2_1.getNewItems().size()); c_2_1.check(); c_2_1.traceErrors(); assertFalse(c_2_1.isOk()); // should be BAD_VALUE duplicated revision id assertEquals(2, c_2_1.getErrors().size()); }
assertTrue(c3.isOk()); c2.getNewItems().clear(); c2.addNewItems(c3); assertEquals(1, c2.getNewItems().size());
swapContract.getNewItems().clear(); swapContract.addNewItems(martyCoinsSplit, stepaCoinsSplit); swapContract.seal();
ContractsService.finishSwap(swapContract, martyPrivateKeys); swapContract.getNewItems().clear(); swapContract.addNewItems(martyCoinsSplit, stepaCoinsSplit); swapContract.seal();
for (Approvable ni : getNewItems()) { if (ni.getExpiresAt().isAfter(expirationLimit)) { isSuitableForTestnet = false;
swapContract.getNewItems().clear(); swapContract.addNewItems(user1CoinsSplit, user2CoinsSplit); swapContract.seal();
for (Contract c: baseContract.getNew()) if (!c.equals(slotContract)) { baseContract.getNewItems().remove(c); slotContract.addNewItems(c); slotContract.seal();
for (Contract c : baseContract.getNew()) if (!c.equals(followerContract)) { baseContract.getNewItems().remove(c); followerContract.addNewItems(c); followerContract.seal();
for (Contract c : baseContract.getNew()) if (!c.equals(followerContract)) { baseContract.getNewItems().remove(c); followerContract.addNewItems(c); followerContract.seal(); for (Contract c : baseContract2.getNew()) if (!c.equals(refilledFollowerContract)) { baseContract2.getNewItems().remove(c); refilledFollowerContract.addNewItems(c); refilledFollowerContract.seal();