@Test public void testSwapSplitJoin_Api2() 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> user1PrivateKeySet = new HashSet<>(asList(TestKeys.privateKey(1))); Set<PrivateKey> user2PrivateKeySet = new HashSet<>(asList(TestKeys.privateKey(2))); Set<PublicKey> user1PublicKeySet = user1PrivateKeySet.stream().map(prv -> prv.getPublicKey()).collect(Collectors.toSet()); Set<PublicKey> user2PublicKeySet = user2PrivateKeySet.stream().map(prv -> prv.getPublicKey()).collect(Collectors.toSet()); Contract contractTOK92 = ContractsService.createTokenContract(user1PrivateKeySet, user1PublicKeySet, new BigDecimal("100"), new BigDecimal("0.0001")); Contract contractTOK93 = ContractsService.createTokenContract(user2PrivateKeySet, user2PublicKeySet, new BigDecimal("100"), new BigDecimal("0.001")); contractTOK92.seal(); contractTOK92.check(); contractTOK92.traceErrors(); ItemResult itemResult = client.register(contractTOK92.getPackedTransaction(), 5000); assertEquals(ItemState.APPROVED, itemResult.state); contractTOK93.seal(); contractTOK93.check(); contractTOK93.traceErrors(); itemResult = client.register(contractTOK93.getPackedTransaction(), 5000); assertEquals(ItemState.APPROVED, itemResult.state); System.out.println("--- tokens created ---"); Contract user1CoinsSplit = ContractsService.createSplit(contractTOK92, new BigDecimal("8.02"), "amount", user1PrivateKeySet); Contract user1CoinsSplitToUser2 = user1CoinsSplit.getNew().get(0); Contract user2CoinsSplit = ContractsService.createSplit(contractTOK93, new BigDecimal("10.01"), "amount", user2PrivateKeySet); Contract user2CoinsSplitToUser1 = user2CoinsSplit.getNew().get(0); user1CoinsSplitToUser2.check(); user1CoinsSplitToUser2.traceErrors(); user2CoinsSplitToUser1.check(); user2CoinsSplitToUser1.traceErrors(); System.out.println("--- procedure for exchange of contracts ---"); Contract swapContract; swapContract = ContractsService.startSwap(user1CoinsSplitToUser2, user2CoinsSplitToUser1, user1PrivateKeySet, user2PublicKeySet, false); ContractsService.signPresentedSwap(swapContract, user2PrivateKeySet); ContractsService.finishSwap(swapContract, user1PrivateKeySet); user1CoinsSplit.seal(); user2CoinsSplit.seal(); swapContract.getNewItems().clear(); swapContract.addNewItems(user1CoinsSplit, user2CoinsSplit); swapContract.seal(); swapContract.check(); swapContract.traceErrors(); System.out.println("Transaction contract for swapping is valid: " + swapContract.isOk()); swapContract = Contract.fromPackedTransaction(swapContract.getPackedTransaction()); main.node.registerItem(swapContract); assertEquals(ItemState.APPROVED, main.node.waitItem(swapContract.getId(), 5000).state); assertEquals(ItemState.APPROVED, main.node.waitItem(user1CoinsSplit.getId(), 5000).state); assertEquals(ItemState.APPROVED, main.node.waitItem(user2CoinsSplit.getId(), 5000).state); assertEquals(ItemState.APPROVED, main.node.waitItem(user1CoinsSplitToUser2.getId(), 5000).state); assertEquals(ItemState.APPROVED, main.node.waitItem(user2CoinsSplitToUser1.getId(), 5000).state); assertEquals(ItemState.REVOKED, main.node.waitItem(contractTOK92.getId(), 5000).state); assertEquals(ItemState.REVOKED, main.node.waitItem(contractTOK93.getId(), 5000).state); assertEquals("8.02", user1CoinsSplitToUser2.getStateData().getStringOrThrow("amount")); assertEquals("10.01", user2CoinsSplitToUser1.getStateData().getStringOrThrow("amount")); assertFalse(user1CoinsSplitToUser2.getOwner().isAllowedForKeys(user1PublicKeySet)); assertTrue(user1CoinsSplitToUser2.getOwner().isAllowedForKeys(user2PublicKeySet)); assertTrue(user2CoinsSplitToUser1.getOwner().isAllowedForKeys(user1PublicKeySet)); assertFalse(user2CoinsSplitToUser1.getOwner().isAllowedForKeys(user2PublicKeySet)); mm.forEach(x -> x.shutdown()); }
public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } Main(String[] args); }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } Main(String[] args); static void main(String[] args); void waitReady(); void shutdown(); void setVerboseLevel(int level); void setUDPVerboseLevel(int level); void restartUDPAdapter(); PublicKey getNodePublicKey(); }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } Main(String[] args); static void main(String[] args); void waitReady(); void shutdown(); void setVerboseLevel(int level); void setUDPVerboseLevel(int level); void restartUDPAdapter(); PublicKey getNodePublicKey(); static final String NODE_VERSION; final Reporter reporter; final BufferedLogger logger; public NetConfig netConfig; public NetworkV2 network; final Config config; public NodeInfo myInfo; public Node node; public ItemCache cache; public ParcelCache parcelCache; public PaidOperationCache paidOperationCache; }