private Binder queryNameContract(Binder params, Session session) throws IOException { checkNode(session, true); Binder b = new Binder(); String nameContract = params.getStringOrThrow("name"); NNameRecord nr = node.getLedger().getNameRecord(nameContract); if (nr != null) { NImmutableEnvironment env = node.getLedger().getEnvironment(nr.getEnvironmentId()); if (env != null) { byte[] packedContract = env.getContract().getPackedTransaction(); b.put("packedContract", packedContract); } } return b; }
protected synchronized void destroyCurrentFromAllNodesIfExists(Contract finalC) { for (Node nodeS : nodesMap.values()) { StateRecord r = nodeS.getLedger().getRecord(finalC.getId()); if (r != null) { r.destroy(); } } }
@AfterClass public static void afterClass() throws Exception { Thread.sleep(200); networks_s.forEach(n->n.shutDown()); nodesMap_s.forEach((i,n)-> { n.shutdown(); n.getLedger().close(); }); network_s = null; networks_s = null; node_s = null; nodes_s = null; nodesMap_s = null; ledger_s = null; nc_s = null; config_s = null; Thread.sleep(200); }
@AfterClass public static void afterClass() throws Exception { Thread.sleep(200); networks_s.forEach(n->n.shutDown()); nodesMap_s.forEach((i,n)-> { n.shutdown(); n.getLedger().close(); }); network_s = null; networks_s = null; node_s = null; nodes_s = null; nodesMap_s = null; ledger_s = null; nc_s = null; config_s = null; Thread.sleep(200); }
private Binder queryNameRecord(Binder params, Session session) throws IOException { checkNode(session, true); Binder b = new Binder(); NNameRecord loadedNameRecord; String address = params.getString("address",null); byte[] origin = params.getBinary("origin"); if (((address == null) && (origin == null)) || ((address != null) && (origin != null))) throw new IOException("invalid arguments"); if (address != null) loadedNameRecord = node.getLedger().getNameByAddress(address); else loadedNameRecord = node.getLedger().getNameByOrigin(origin); if (loadedNameRecord != null) { b.put("name", loadedNameRecord.getName()); b.put("description", loadedNameRecord.getDescription()); b.put("url", loadedNameRecord.getUrl()); } return b; }
private synchronized void addToAllLedgers(Contract c, ItemState state, Node exceptNode) { for( Node n: nodesMap_s.values() ) { if(n != exceptNode) { n.getLedger().findOrCreate(c.getId()).setState(state).save(); } } }
@AfterClass public static void afterClass() throws Exception { node_s.shutdown(); node_s.getLedger().close(); network_s = null; node_s = null; nodes_s = null; nodesMap_s = null; ledger_s = null; config_s = null; }
protected synchronized void destroyFromAllNodesExistingNew(Contract c50_1) { StateRecord orCreate; for (Approvable c : c50_1.getNewItems()) { for (Node nodeS : nodesMap.values()) { orCreate = nodeS.getLedger().getRecord(c.getId()); if (orCreate != null) orCreate.destroy(); } } }
private synchronized void addToAllLedgers(Contract c, ItemState state, Node exceptNode) { for( Node n: nodesMap_s.values() ) { if(n != exceptNode) { n.getLedger().findOrCreate(c.getId()).setState(state).save(); } } }
@AfterClass public static void afterClass() throws Exception { network_s.shutdown(); nodes_s.forEach((n)-> { n.getLedger().close(); n.shutdown(); }); network_s = null; node_s = null; nodes_s = null; nodesMap_s = null; ledger_s = null; nc_s = null; config_s = null; }
private void addToAllLedgers(Contract c, ItemState state, Node exceptNode) { for( Node n: nodes ) { if(n != exceptNode) { n.getLedger().findOrCreate(c.getId()).setState(state).save(); } } }
private Binder queryFollowerInfo(Binder params, Session session) throws IOException { checkNode(session, true); Binder res = new Binder(); res.set("follower_state", null); byte[] follower_id = params.getBinary("follower_id"); byte[] followerBin = node.getLedger().getSmartContractById(HashId.withDigest(follower_id)); if (followerBin != null) { FollowerContract followerContract = (FollowerContract) Contract.fromPackedTransaction(followerBin); res.set("follower_state", followerContract.getStateData()); } return res; }
private Binder querySlotInfo(Binder params, Session session) throws IOException { checkNode(session, true); Binder res = new Binder(); res.set("slot_state", null); byte[] slot_id = params.getBinary("slot_id"); byte[] slotBin = node.getLedger().getSmartContractById(HashId.withDigest(slot_id)); if (slotBin != null) { SlotContract slotContract = (SlotContract) Contract.fromPackedTransaction(slotBin); res.set("slot_state", slotContract.getStateData()); } return res; }
protected synchronized void addDetailsToAllLedgers(Contract contract) { HashId id; StateRecord orCreate; for (Approvable c : contract.getRevokingItems()) { id = c.getId(); for (Node nodeS : nodesMap.values()) { orCreate = nodeS.getLedger().findOrCreate(id); orCreate.setState(ItemState.APPROVED).save(); } } destroyFromAllNodesExistingNew(contract); destroyCurrentFromAllNodesIfExists(contract); }
private Binder getContract(Binder params, Session session) throws IOException { checkNode(session, true); Binder res = new Binder(); if (!node.getConfig().isPermanetMode()) return res; HashId origin = (HashId) params.get("origin"); int limit = params.getInt("limit", 100); if (limit > node.getConfig().getQueryContractsLimit()) limit = node.getConfig().getQueryContractsLimit(); if (limit < 1) limit = 1; Object keeping = node.getLedger().getKeepingByOrigin(origin, limit); if (keeping == null) return res; if (keeping instanceof byte[]) res.put("packedContract", keeping); else if (keeping instanceof List) res.put("contractIds", keeping); return res; }
@Test(timeout = 15000) public void resyncWithTimeout() throws Exception { Contract c = new Contract(TestKeys.privateKey(0)); c.seal(); addToAllLedgers(c, ItemState.APPROVED); Duration wasDuration = config.getMaxResyncTime(); config.setMaxResyncTime(Duration.ofMillis(2000)); for (int i = 0; i < NODES/2; i++) { ((TestEmulatedNetwork)network).switchOffNodeTestMode(nodes.get(NODES-i-1)); } 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(), 15000).state); config.setMaxResyncTime(wasDuration); ((TestEmulatedNetwork)network).switchOnAllNodesTestMode(); }
@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); }
@Test(timeout = 15000) public void resyncRevoked() throws Exception { Contract c = new Contract(TestKeys.privateKey(0)); c.seal(); addToAllLedgers(c, ItemState.REVOKED); node.getLedger().getRecord(c.getId()).destroy(); assertEquals(ItemState.UNDEFINED, node.checkItem(c.getId()).state); node.resync(c.getId()); assertEquals(ItemState.REVOKED, node.waitItem(c.getId(), 13000).state); }
@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); }