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; }
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()); normalClient.registerParcelWithState(parcel.pack(),8000); synchronized (uContractLock) { uContract = parcel.getPaymentContract(); } return parcel; }
Instant end = Instant.now().plusMillis(millisToWait); try { Parcel parcel = Parcel.unpack(packed); Node.ParcelProcessingState pState = getParcelProcessingState(parcel.getId()); int interval = 1000; while (Instant.now().isBefore(end) && pState.isProcessing()) { interval -= 350; interval = Math.max(interval, 300); pState = getParcelProcessingState(parcel.getId()); ItemResult lastResult = getState(parcel.getPayloadContract().getId()); while (Instant.now().isBefore(end) && lastResult.state.isPending()) { Thread.currentThread().sleep(interval); interval -= 350; interval = Math.max(interval, 300); lastResult = getState(parcel.getPayloadContract().getId()); System.out.println("test: " + lastResult);
/** * Register a specified parcel. * @param parcel must be ready for register * @param waitTime wait time for responce. * @return ItemResult for parcel's payload * @throws IOException */ public static ItemResult registerParcel(Parcel parcel, int waitTime) throws IOException { getClientNetwork().registerParcel(parcel.pack(), waitTime); ItemResult r = getClientNetwork().check(parcel.getPayloadContract().getId()); report("paid contract " + parcel.getPayloadContract().getId() + " submitted with result: " + r.toString()); report("payment became " + parcel.getPaymentContract().getId()); report("payment rev 1 " + parcel.getPaymentContract().getRevoking().get(0).getId()); return r; }
@Override synchronized public Parcel getParcel(HashId itemId, NodeInfo nodeInfo, Duration maxTimeout) throws InterruptedException { synchronized (mutex) { Node node = nodes.get(nodeInfo); Parcel parcel = node.getParcel(itemId); byte[] array = parcel.pack(); //unpack Parcel des_parcel = null; try { des_parcel = Parcel.unpack(array); } catch (Exception e) { System.out.println("error parcel "); e.printStackTrace(); } return des_parcel; // return parcel; } }
parcel.getPayment().getContract().check(); parcel.getPayment().getContract().traceErrors(); parcel.getPayload().getContract().check(); parcel.getPayload().getContract().traceErrors(); assertTrue(parcel.getPaymentContract().isOk()); assertTrue(parcel.getPayloadContract().isOk()); System.out.println("Parcel: " + parcel.getId()); System.out.println("Payment contract: " + parcel.getPaymentContract().getId() + " is U: " + parcel.getPaymentContract().isU(config.getUIssuerKeys(), config.getUIssuerName())); System.out.println("Payload contract: " + parcel.getPayloadContract().getId() + " is U: " + parcel.getPayloadContract().isU(config.getUIssuerKeys(), config.getUIssuerName())); node.waitParcel(parcel.getId(), 8000); assertEquals(ItemState.APPROVED, node.waitItem(parcel.getPayment().getContract().getId(), 8000).state); assertEquals(ItemState.APPROVED, node.waitItem(parcel.getPayload().getContract().getId(), 8000).state);
assertTrue(testContract.isOk()); Parcel parcel = createParcelWithFreshU(client, testContract,Do.listOf(myKey)); client.registerParcelWithState(parcel.pack(), 5000); System.out.println(">> before shutdown state: " + client.getState(parcel.getPayloadContract().getId())); System.out.println(">> before shutdown state: " + client.getState(parcel.getPayloadContract().getNew().get(0).getId())); ItemResult itemResult = client.getState(parcel.getPayloadContract().getId()); ItemResult itemResult2 = client.getState(parcel.getPayloadContract().getNew().get(0).getId()); System.out.println(">> after shutdown state: " + itemResult + " and new " + itemResult2); itemResult = client.getState(parcel.getPayloadContract().getId()); System.out.println(">> wait result: " + itemResult); itemResult2 = client.getState(parcel.getPayloadContract().getNew().get(0).getId());
uContract = parcel.getPaymentContract(); node.waitParcel(parcel.getId(), 8000); assertEquals(ItemState.APPROVED, node.waitItem(referencesContract1.getId(), 8000).state); uContract = payingParcel.getPayloadContract().getNew().get(0); node.waitParcel(payingParcel.getId(), 8000); assertEquals(ItemState.APPROVED, node.waitItem(payingParcel.getPayload().getContract().getId(), 8000).state); assertEquals(ItemState.REVOKED, node.waitItem(payingParcel.getPayment().getContract().getId(), 8000).state); assertEquals(ItemState.APPROVED, node.waitItem(uns.getNew().get(0).getId(), 8000).state); uContract = parcel.getPaymentContract(); node.waitParcel(parcel.getId(), 8000); assertEquals(ItemState.APPROVED, node.waitItem(referencesContract2.getId(), 8000).state); uContract = payingParcel.getPayloadContract().getNew().get(0); node.waitParcel(payingParcel.getId(), 8000); assertEquals(ItemState.DECLINED, node.waitItem(payingParcel.getPayload().getContract().getId(), 8000).state); assertEquals(ItemState.APPROVED, node.waitItem(payingParcel.getPayment().getContract().getId(), 8000).state); assertEquals(ItemState.UNDEFINED, node.waitItem(uns.getNew().get(0).getId(), 8000).state); payingParcel = Parcel.unpack(payingParcel.pack()); uContract = payingParcel.getPayloadContract().getNew().get(0);
protected synchronized Parcel registerWithNewParcel(TransactionPack tp) throws Exception { Set<PrivateKey> stepaPrivateKeys = new HashSet<>(); stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey"))); Contract tu = getApprovedUContract(); // stepaPrivateKeys - is also U keys Parcel parcel = ContractsService.createParcel(tp, tu, 150, stepaPrivateKeys); System.out.println("-------------"); normalClient.registerParcelWithState(parcel.pack(),8000); synchronized (uContractLock) { uContract = parcel.getPaymentContract(); } return parcel; }
this.parcel = parcel; if(parcel != null) { payment = parcel.getPaymentContract(); payload = parcel.getPayloadContract();
paymentDecreased.traceErrors(); Parcel parcel = new Parcel(stepaCoins.getTransactionPack(), paymentDecreased.getTransactionPack()); assertFalse(parcel.getPaymentContract().isOk()); assertTrue(parcel.getPayloadContract().isOk()); node.waitParcel(parcel.getId(), 8000); assertEquals(ItemState.DECLINED, node.waitItem(parcel.getPaymentContract().getId(), 8000).state); assertEquals(ItemState.UNDEFINED, node.waitItem(parcel.getPayloadContract().getId(), 8000).state);
Client client = clients.get(finalI); System.out.println("Register item " + contract.getId().toBase64String() + " @ node #" + clientNodes.get(finalI)); client.registerParcelWithState(parcels.get(finalI).pack(), 15000); ItemResult rr; while (true) {
@Test public void packUnpack() throws Exception { //pack byte[] array = parcel.pack(); byte[] array1 = parcelFromFile.pack(); //unpack des_parcel = Parcel.unpack(array); des_parcelFromFile = Parcel.unpack(array1); parcelAssertions(parcel, des_parcel); parcelAssertions(parcelFromFile, des_parcelFromFile); assertEquals(1, des_parcel.getPayload().getSubItems().size()); assertEquals(1, des_parcel.getPayload().getContract().getNew().size()); } }
uContract = parcel.getPaymentContract(); System.out.println("-------------- register parcel " + parcel.getId() + " (iteration " + i + ") ------------"); node.registerParcel(parcel); n.waitParcel(parcel.getId(), 15000); ItemResult itemResult = n.waitItem(stepaCoins.getId(), 15000); ItemState itemState1 = node.waitItem(parcel.getPaymentContract().getRevoking().get(0).getId(), 15000).state; ItemState itemState2 = node.getLedger().getRecord(parcel.getPaymentContract().getRevoking().get(0).getId()).getState(); System.out.println("--- check item " + parcel.getPaymentContract().getRevoking().get(0).getId() + " --- iteration " + i); System.out.println("state from node: " + itemState1); System.out.println("state from ledger: " + itemState2);
node.waitParcel(parcel.getId(), 8000); ItemResult itemResult = node.waitItem(parcel.getPayloadContract().getId(), 3000); if (ItemState.APPROVED != itemResult.state) fail("Wrong state on repetition " + i + ": " + itemResult + ", " + itemResult.errors +
protected synchronized Parcel registerWithNewParcel(TransactionPack tp) throws Exception { Set<PrivateKey> stepaPrivateKeys = new HashSet<>(); stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey"))); Contract tu = getApprovedUContract(); // stepaPrivateKeys - is also U keys Parcel parcel = ContractsService.createParcel(tp, tu, 150, stepaPrivateKeys); System.out.println("-------------"); node.registerParcel(parcel); synchronized (uContractLock) { uContract = parcel.getPaymentContract(); } return parcel; }
@Test(timeout = 90000) public void declinePaymentAndPaymentWithChangedData2() throws Exception { Set<PrivateKey> stepaPrivateKeys = new HashSet<>(); stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey"))); Contract uContract = getApprovedUContract(); // stepaPrivateKeys - is also U keys Contract paymentDecreased = uContract.createRevision(stepaPrivateKeys); paymentDecreased.getStateData().set("transaction_units", uContract.getStateData().getIntOrThrow("transaction_units") - 5); paymentDecreased.seal(); Contract modifiedU = paymentDecreased.createRevision(stepaPrivateKeys); modifiedU.getStateData().set("transaction_units", modifiedU.getStateData().getIntOrThrow("transaction_units") - 1); modifiedU.seal(); Parcel parcel = new Parcel(modifiedU.getTransactionPack(), paymentDecreased.getTransactionPack()); System.out.println("-------------"); node.registerParcel(parcel); synchronized (uContractLock) { uContract = parcel.getPaymentContract(); } waitAndCheckState(parcel, ItemState.UNDEFINED); }
private void checkExpiration(Instant now) { if( expiresAt.isBefore(now) ) { //System.out.println("cache expired "+parcel.getId()); records.remove(parcel.getId()); } } }
/** * Load parcel from specified path. * * @param fileName * * @return loaded Parcel. */ public static Parcel loadParcel(String fileName) throws IOException { Parcel parcel = null; File pathFile = new File(fileName); if (pathFile.exists()) { Path path = Paths.get(fileName); byte[] data = Files.readAllBytes(path); parcel = Parcel.unpack(data); } else { addError(Errors.NOT_FOUND.name(), fileName, "Path " + fileName + " does not exist"); } return parcel; }
public Parcel deserialize(Binder binder) throws Exception { return new Parcel(binder); }