@Test public void testAddBlock() { TransactionsPool transactionsProcessed = new TransactionsPool(); Block block = new Block(); for (int i = 0; i < 10; i++) { BlockUtil.addTransactionInBlock(block, new byte[]{(byte) i}); } transactionsProcessed.addBlock(block); TestCase.assertEquals(10, transactionsProcessed.lastTransactions.size()); TestCase.assertTrue(transactionsProcessed.checkExists(Util.getDataEncoded64(new byte[]{(byte) 3}))); TestCase.assertFalse(transactionsProcessed.checkExists(Util.getDataEncoded64(new byte[]{(byte) 11}))); }
public void addBlock(Block block) { Util.check(block != null, "block != null"); if (BlockUtil.isEmptyBlock(block)) { return; } Object dummyObject = new Object(); synchronized (locker) { Collection<String> hashes = BlockUtil.getTransactionsHashesAsString(block); for (String hash : hashes) { lastTransactions.put(hash, dummyObject); } transactions.removeAll(hashes); } }
TransactionsPool { public void addBlock(Block block) { Util.check(block != null, "block != null"); if (BlockUtil.isEmptyBlock(block)) { return; } Object dummyObject = new Object(); synchronized (locker) { Collection<String> hashes = BlockUtil.getTransactionsHashesAsString(block); for (String hash : hashes) { lastTransactions.put(hash, dummyObject); } transactions.removeAll(hashes); } } }
TransactionsPool { public void addBlock(Block block) { Util.check(block != null, "block != null"); if (BlockUtil.isEmptyBlock(block)) { return; } Object dummyObject = new Object(); synchronized (locker) { Collection<String> hashes = BlockUtil.getTransactionsHashesAsString(block); for (String hash : hashes) { lastTransactions.put(hash, dummyObject); } transactions.removeAll(hashes); } }  }
TransactionsPool { public void addBlock(Block block) { Util.check(block != null, "block != null"); if (BlockUtil.isEmptyBlock(block)) { return; } Object dummyObject = new Object(); synchronized (locker) { Collection<String> hashes = BlockUtil.getTransactionsHashesAsString(block); for (String hash : hashes) { lastTransactions.put(hash, dummyObject); } transactions.removeAll(hashes); } }  List<String> getTransactions(); boolean addTransaction(String transactionHash); boolean checkExists(String transactionHash); void addBlock(Block block); }
TransactionsPool { public void addBlock(Block block) { Util.check(block != null, "block != null"); if (BlockUtil.isEmptyBlock(block)) { return; } Object dummyObject = new Object(); synchronized (locker) { Collection<String> hashes = BlockUtil.getTransactionsHashesAsString(block); for (String hash : hashes) { lastTransactions.put(hash, dummyObject); } transactions.removeAll(hashes); } }  List<String> getTransactions(); boolean addTransaction(String transactionHash); boolean checkExists(String transactionHash); void addBlock(Block block);  }