@Test public void testSwapContractsApi() 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> martyPrivateKeys = new HashSet<>(asList(TestKeys.privateKey(1))); Set<PrivateKey> stepaPrivateKeys = new HashSet<>(asList(TestKeys.privateKey(2))); Set<PublicKey> martyPublicKeys = new HashSet<>(asList(TestKeys.publicKey(1))); Set<PublicKey> stepaPublicKeys = new HashSet<>(asList(TestKeys.publicKey(2))); Contract delorean = ContractsService.createTokenContract(martyPrivateKeys, martyPublicKeys, new BigDecimal("100"), new BigDecimal("0.0001")); delorean.seal(); delorean.check(); delorean.traceErrors(); ItemResult itemResult = client.register(delorean.getPackedTransaction(), 5000); assertEquals(ItemState.APPROVED, itemResult.state); Contract lamborghini = ContractsService.createTokenContract(stepaPrivateKeys, stepaPublicKeys, new BigDecimal("100"), new BigDecimal("0.0001")); lamborghini.seal(); lamborghini.check(); lamborghini.traceErrors(); itemResult = client.register(lamborghini.getPackedTransaction(), 5000); assertEquals(ItemState.APPROVED, itemResult.state); System.out.println("--- register swapped contracts using ContractsService ---"); Contract swapContract; swapContract = ContractsService.startSwap(delorean, lamborghini, martyPrivateKeys, stepaPublicKeys); swapContract = Contract.fromPackedTransaction(swapContract.getPackedTransaction()); ContractsService.signPresentedSwap(swapContract, stepaPrivateKeys); swapContract = Contract.fromPackedTransaction(swapContract.getPackedTransaction()); ContractsService.finishSwap(swapContract, martyPrivateKeys); swapContract.check(); swapContract.traceErrors(); System.out.println("Transaction contract for swapping is valid: " + swapContract.isOk()); itemResult = client.register(swapContract.getPackedTransaction(), 10000); assertEquals(ItemState.APPROVED, itemResult.state); System.out.println("--- check old revisions for ownership contracts ---"); ItemResult deloreanResult = main.node.waitItem(delorean.getId(), 5000); System.out.println("DeLorean revoked ownership contract revision " + delorean.getRevision() + " is " + deloreanResult + " by Network"); System.out.println("DeLorean revoked ownership was belongs to Marty: " + delorean.getOwner().isAllowedForKeys(martyPublicKeys)); assertEquals(ItemState.REVOKED, deloreanResult.state); ItemResult lamborghiniResult = main.node.waitItem(lamborghini.getId(), 5000); System.out.println("Lamborghini revoked ownership contract revision " + lamborghini.getRevision() + " is " + lamborghiniResult + " by Network"); System.out.println("Lamborghini revoked ownership was belongs to Stepa: " + lamborghini.getOwner().isAllowedForKeys(stepaPublicKeys)); assertEquals(ItemState.REVOKED, lamborghiniResult.state); System.out.println("--- check new revisions for ownership contracts ---"); Contract newDelorean = null; Contract newLamborghini = null; for (Contract c : swapContract.getNew()) { if (c.getParent().equals(delorean.getId())) { newDelorean = c; } if (c.getParent().equals(lamborghini.getId())) { newLamborghini = c; } } deloreanResult = main.node.waitItem(newDelorean.getId(), 5000); System.out.println("DeLorean ownership contract revision " + newDelorean.getRevision() + " is " + deloreanResult + " by Network"); System.out.println("DeLorean ownership is now belongs to Stepa: " + newDelorean.getOwner().isAllowedForKeys(stepaPublicKeys)); assertEquals(ItemState.APPROVED, deloreanResult.state); assertTrue(newDelorean.getOwner().isAllowedForKeys(stepaPublicKeys)); lamborghiniResult = main.node.waitItem(newLamborghini.getId(), 5000); System.out.println("Lamborghini ownership contract revision " + newLamborghini.getRevision() + " is " + lamborghiniResult + " by Network"); System.out.println("Lamborghini ownership is now belongs to Marty: " + newLamborghini.getOwner().isAllowedForKeys(martyPublicKeys)); assertEquals(ItemState.APPROVED, lamborghiniResult.state); assertTrue(newLamborghini.getOwner().isAllowedForKeys(martyPublicKeys)); 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; }