InMemoryBlockStore implements BlockStore { public Block dbGetBlockByHash(byte[] hash) { Session s = sessionFactory.openSession(); List result = s.createQuery("from BlockVO where hash = :hash"). setParameter("hash", hash).list(); if (result.size() == 0) return null; BlockVO vo = (BlockVO) result.get(0); s.close(); return new Block(vo.rlp); } InMemoryBlockStore(); @Override byte[] getBlockHashByNumber(long blockNumber); @Override Block getBlockByNumber(long blockNumber); @Override Block getBlockByHash(byte[] hash); @Override List<byte[]> getListHashesEndWith(byte[] hash, long qty); @Override void saveBlock(Block block, List<TransactionReceipt> receipts); @Override BigInteger getTotalDifficulty(); @Override Block getBestBlock(); byte[] dbGetBlockHashByNumber(long blockNumber); Block dbGetBlockByNumber(long blockNumber); Block dbGetBlockByHash(byte[] hash); @Override void flush(); void load(); @Override void setSessionFactory(SessionFactory sessionFactory);  }
@Test public void testDbGetBlockByHash(){ BlockStore blockStore = new InMemoryBlockStore(); SessionFactory sessionFactory = sessionFactory(); blockStore.setSessionFactory(sessionFactory); for( Block block : blocks ){ blockStore.saveBlock(block, null); } byte[] hash7000 = Hex.decode("459a8f0ee5d4b0c9ea047797606c94f0c1158ed0f30120490b96f7df9893e1fa"); byte[] hash6000 = Hex.decode("7a577a6b0b7e72e51a646c4cec82cf684c977bca6307e2a49a4116af49316159"); byte[] hash5000 = Hex.decode("820aa786619e1a2ae139877ba342078c83e5bd65c559069336c13321441e03dc"); Long number = blockStore.getBlockByHash(hash7000).getNumber(); assertTrue(number == 7000); number = blockStore.getBlockByHash(hash6000).getNumber(); assertTrue(number == 6000); number = blockStore.getBlockByHash(hash5000).getNumber(); assertTrue(number == 5000); }