/** * Direct add the subItem. Not recommended as {@link #setContract(Contract)} already does it for all subItems. * Use it to add subItems not mentioned in the added contracts. * * @param subItem is {@link Contract} for adding */ public void addSubItem(Contract subItem) { if (!subItems.containsKey(subItem.getId())) { packedBinary = null; subItems.put(subItem.getId(), subItem); } }
/** * Direct add the referenced items. Use it to add references not mentioned in the added contracts. * * @param referencedItem is {@link Contract} for adding */ public void addReferencedItem(Contract referencedItem) { if (!referencedItems.containsKey(referencedItem.getId())) { packedBinary = null; referencedItems.put(referencedItem.getId(), referencedItem); } }
final void cleanUp() { // we should avoid creating an object for each check: Instant now = Instant.now(); environmetsExpiration.keySet().forEach(envId -> { if(environmetsExpiration.get(envId).isBefore(now)) { environmetsExpiration.remove(envId); environemtsByContract.remove(environemtsById.remove(envId).getContract().getId()); } }); }
/** * If {@link UnsName} references to origin contract, this contract should be placed into UnsContract with this method. * @param contract */ public void addOriginContract(Contract contract) { originContracts.put(contract.getOrigin() != null ? contract.getOrigin() : contract.getId(),contract); }
private static void doShowId() throws Exception { String contractFile = (String) options.valueOf("id"); Contract c = Contract.fromPackedTransaction(Files.readAllBytes(Paths.get(contractFile))); reporter.message(c.getId().toBase64String()); finish(); }
public JSApiRevisionStorage getRevisionStorage() { if (scriptParameters.checkPermission(JSApiScriptParameters.ScriptPermissions.PERM_REVISION_STORAGE)) return new JSApiRevisionStorage(this.currentContract.getId(), this.currentContract.getParent()); throw new IllegalArgumentException("access denied: missing permission " + JSApiScriptParameters.ScriptPermissions.PERM_REVISION_STORAGE.toString()); }
@Override public void run() { System.out.println("-----------nodes state--------------"); for (Node n : nodesMap_s.values()) { ItemResult r = n.checkItem(contract.getId()); System.out.println("Node: " + n.toString() + " state: " + r.state); } } }, 0, 1000);
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())); }
@Override public void run() { ItemResult r = node.checkItem(contract.getId()); System.out.println("Complex contract state: " + r.state); if(r.state == ItemState.DECLINED) ae.fire(); } }, 0, 500);
@Override public void run() { ItemResult r = node.checkItem(contract.getId()); System.out.println("Complex contract state: " + r.state); if(r.state == ItemState.APPROVED) ae.fire(); } }, 0, 500);
@Override public void run() { if( ItemState.UNDEFINED == node.checkItem(c.getId()).state) ae.fire(); } }, 100, 500);
@Override public void run() { if( ItemState.UNDEFINED == node.checkItem(c.getId()).state) ae.fire(); } }, 100, 500);
protected synchronized void destroyCurrentFromAllNodesIfExists(Contract finalC) { for (Node nodeS : nodesMap.values()) { StateRecord r = nodeS.getLedger().getRecord(finalC.getId()); if (r != null) { r.destroy(); } } }
@Override public void run() { ItemResult r = node.checkItem(parcel.getPayloadContract().getId()); System.out.println("Complex contract state: " + r.state); if(r.state == ItemState.DECLINED) ae.fire(); } }, 0, 500);
protected synchronized Parcel registerWithNewParcel(Contract c) throws Exception { Set<PrivateKey> stepaPrivateKeys = new HashSet<>(); stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey"))); Parcel parcel = createParcelWithClassU(c, stepaPrivateKeys); System.out.println("register parcel: " + parcel.getId() + " " + parcel.getPaymentContract().getId() + " " + parcel.getPayloadContract().getId()); node.registerParcel(parcel); synchronized (uContractLock) { uContract = parcel.getPaymentContract(); } return parcel; }
@Test(timeout = 15000) public void resyncOther() throws Exception { Contract c = new Contract(TestKeys.privateKey(0)); c.seal(); addToAllLedgers(c, ItemState.PENDING_POSITIVE); node.getLedger().getRecord(c.getId()).destroy(); assertEquals(ItemState.UNDEFINED, node.checkItem(c.getId()).state); node.resync(c.getId()); assertEquals(ItemState.PENDING, node.checkItem(c.getId()).state); assertEquals(ItemState.UNDEFINED, node.waitItem(c.getId(), 12000).state); }
@Test(timeout = 15000) public void resyncApproved() throws Exception { Contract c = new Contract(TestKeys.privateKey(0)); c.seal(); addToAllLedgers(c, ItemState.APPROVED); node.getLedger().getRecord(c.getId()).destroy(); assertEquals(ItemState.UNDEFINED, node.checkItem(c.getId()).state); node.resync(c.getId()); assertEquals(ItemState.APPROVED, node.waitItem(c.getId(), 15000).state); }
@Test(timeout = 15000) public void resyncDeclined() throws Exception { Contract c = new Contract(TestKeys.privateKey(0)); c.seal(); addToAllLedgers(c, ItemState.DECLINED); node.getLedger().getRecord(c.getId()).destroy(); assertEquals(ItemState.UNDEFINED, node.checkItem(c.getId()).state); node.resync(c.getId()); assertEquals(ItemState.DECLINED, node.waitItem(c.getId(), 12000).state); }
public synchronized Parcel createParcelWithFreshU(Contract c, Set<PrivateKey> keys) throws Exception { Set<PublicKey> ownerKeys = new HashSet(); keys.stream().forEach(key -> ownerKeys.add(key.getPublicKey())); Contract stepaU = InnerContractsService.createFreshU(100000000, ownerKeys); stepaU.check(); //stepaU.setIsU(true); stepaU.traceErrors(); node.registerItem(stepaU); ItemResult itemResult = node.waitItem(stepaU.getId(), 18000); assertEquals(ItemState.APPROVED, itemResult.state); return ContractsService.createParcel(c, stepaU, 150, keys); }
@Test(timeout = 90000) public void checkPayment_originMismatch() throws Exception { Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys()); final Field field2 = payment.getRevoking().get(0).getState().getClass().getDeclaredField("origin"); field2.setAccessible(true); field2.set(payment.getRevoking().get(0).getState(), payment.getId()); boolean res = payment.paymentCheck(config.getUIssuerKeys()); payment.traceErrors(); assertFalse(res); }