@Test public void demo() throws Exception { PrivateKey person1 = TestKeys.privateKey(1); PrivateKey person2 = TestKeys.privateKey(2); PrivateKey bank = TestKeys.privateKey(3); Contract commissionAccRur = new Contract(bank); Contract commissionAccEur = new Contract(bank); commissionAccRur.getStateData().put(ACC_TYPE_FIELD, ACC_TYPE_BANK); commissionAccEur.getStateData().put(ACC_TYPE_FIELD, ACC_TYPE_BANK); commissionAccRur.getStateData().put(ACC_CURRENCY_FIELD, ACC_CURRENCY_RUR); commissionAccEur.getStateData().put(ACC_CURRENCY_FIELD, ACC_CURRENCY_EUR); commissionAccRur.getStateData().put(ACC_COMMISSION_PERCENT_FIELD, "0.0"); commissionAccEur.getStateData().put(ACC_COMMISSION_PERCENT_FIELD, "0.0"); commissionAccRur.getStateData().put(ACC_COMMISSION_ACCOUNT_FIELD, null); commissionAccEur.getStateData().put(ACC_COMMISSION_ACCOUNT_FIELD, null); commissionAccRur.seal(); commissionAccEur.seal(); Contract account1rur = new Contract(person1); Contract account2rur = new Contract(person2); Contract account2eur = new Contract(person2); account1rur.getStateData().put(ACC_TYPE_FIELD, ACC_TYPE_PERSONAL); account2rur.getStateData().put(ACC_TYPE_FIELD, ACC_TYPE_PERSONAL); account2eur.getStateData().put(ACC_TYPE_FIELD, ACC_TYPE_PERSONAL); account1rur.getStateData().put(ACC_CURRENCY_FIELD, ACC_CURRENCY_RUR); account2rur.getStateData().put(ACC_CURRENCY_FIELD, ACC_CURRENCY_RUR); account2eur.getStateData().put(ACC_CURRENCY_FIELD, ACC_CURRENCY_EUR); account1rur.getStateData().put(ACC_COMMISSION_PERCENT_FIELD, "0.1"); account2rur.getStateData().put(ACC_COMMISSION_PERCENT_FIELD, "0.0"); account2eur.getStateData().put(ACC_COMMISSION_PERCENT_FIELD, "0.2"); account1rur.getStateData().put(ACC_COMMISSION_ACCOUNT_FIELD, commissionAccRur.getId().toBase64String()); account2rur.getStateData().put(ACC_COMMISSION_ACCOUNT_FIELD, commissionAccRur.getId().toBase64String()); account2eur.getStateData().put(ACC_COMMISSION_ACCOUNT_FIELD, commissionAccEur.getId().toBase64String()); account1rur.seal(); account2rur.seal(); account2eur.seal(); Contract rurToken = new Contract(bank); SimpleRole tokenOwner = new SimpleRole("owner"); tokenOwner.addRequiredReference("canplayaccowner", Role.RequiredMode.ALL_OF); rurToken.registerRole(tokenOwner); rurToken.getStateData().put("account", account1rur.getId().toBase64String()); rurToken.getStateData().put(TOKEN_VALUE_FIELD, "100000"); RoleLink rl = new RoleLink("@owner", "owner"); rurToken.registerRole(rl); SplitJoinPermission sjp = new SplitJoinPermission(rl, Binder.of("field_name", TOKEN_VALUE_FIELD, "join_match_fields", Do.listOf("state.origin", TOKEN_ACCOUNT_PATH))); rurToken.addPermission(sjp); ModifyDataPermission mdp = new ModifyDataPermission(rl, Binder.of("fields", Binder.of(TOKEN_ACCOUNT_FIELD, null))); rurToken.addPermission(mdp); Reference canplayaccowner = new Reference(rurToken); canplayaccowner.name = "canplayaccowner"; List<String> conditions = new ArrayList<>(); conditions.add("ref.id==this." + TOKEN_ACCOUNT_PATH); conditions.add("this can_play ref.owner"); canplayaccowner.setConditions(Binder.of("all_of", conditions)); rurToken.addReference(canplayaccowner); Reference refAccount = new Reference(rurToken); refAccount.name = "refAccount"; refAccount.setConditions(Binder.of("all_of", Do.listOf("this." + TOKEN_ACCOUNT_PATH + " == ref.id"))); rurToken.addReference(refAccount); Reference refParent = new Reference(rurToken); refParent.name = "refParent"; refParent.setConditions(Binder.of("any_of", Do.listOf( "this.state.parent == ref.id", "this.state.parent undefined" ))); rurToken.addReference(refParent); Reference refParentAccount = new Reference(rurToken); refParentAccount.name = "refParentAccount"; refParentAccount.setConditions(Binder.of("any_of", Do.listOf( "refParent." + TOKEN_ACCOUNT_PATH + " == ref.id", "this.state.parent undefined" ))); rurToken.addReference(refParentAccount); Reference transferCheck = new Reference(rurToken); transferCheck.name = "transferCheck"; transferCheck.setConditions(Binder.of("any_of", Do.listOf( "this.state.parent undefined", "refParent." + TOKEN_ACCOUNT_PATH + " == this." + TOKEN_ACCOUNT_PATH, Binder.of("all_of", Do.listOf( "refAccount." + ACC_CURRENCY_PATH + " == refParentAccount." + ACC_CURRENCY_PATH, Binder.of("any_of", Do.listOf( Binder.of("all_of", Do.listOf( "this." + TOKEN_ACCOUNT_PATH + "==refParentAccount." + ACC_COMMISSION_ACCOUNT_PATH )), Binder.of("all_of", Do.listOf( "refParentAccount." + ACC_COMMISSION_PERCENT_PATH + "::number==0.0" )), Binder.of("all_of", Do.listOf( "ref." + TOKEN_VALUE_PATH + "::number == this." + TOKEN_VALUE_PATH + "::number * refParentAccount." + ACC_COMMISSION_PERCENT_PATH + "::number", "ref." + TOKEN_ACCOUNT_PATH + " == refParentAccount." + ACC_COMMISSION_ACCOUNT_PATH, "ref.transactional.data.transfer_id == this.id" )) )) )) ))); rurToken.addReference(transferCheck); rurToken.seal(); List<Main> mm = new ArrayList<>(); for (int i = 0; i < 4; i++) mm.add(createMain("node" + (i + 1), "_permanet", false)); Main main = mm.get(0); main.config.setIsFreeRegistrationsAllowedFromYaml(true); main.config.getKeysWhiteList().add(TestKeys.publicKey(20)); Client client = new Client(TestKeys.privateKey(20), main.myInfo, null); assertTrue(main.config.isPermanetMode()); for (int i = 1; i < 4; i++) assertTrue(mm.get(i).config.isPermanetMode()); assertEquals(client.register(commissionAccEur.getPackedTransaction(), 8000).state, ItemState.APPROVED); assertEquals(client.register(commissionAccRur.getPackedTransaction(), 8000).state, ItemState.APPROVED); assertEquals(client.register(account1rur.getPackedTransaction(), 8000).state, ItemState.APPROVED); assertEquals(client.register(account2rur.getPackedTransaction(), 8000).state, ItemState.APPROVED); assertEquals(client.register(account2eur.getPackedTransaction(), 8000).state, ItemState.APPROVED); rurToken.getTransactionPack().addReferencedItem(account1rur); ItemResult ir = client.register(rurToken.getPackedTransaction(), 8000); System.out.println(ir.errors); assertEquals(ir.state, ItemState.APPROVED); Contract[] result = makeTransfer(rurToken, new BigDecimal("5000"), account1rur, account2rur, commissionAccRur, new HashSet<>(Do.listOf(person1)), client); assertNotNull(result[2]); result = makeTransfer(result[1], new BigDecimal("2000"), account2rur, account1rur, commissionAccRur, new HashSet<>(Do.listOf(person2)), client); assertNull(result[2]); mm.forEach(m->m.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; }