class BlockchainServiceImpl implements BlockchainService {

    @Override
    public synchronized <H extends Object, B extends Serializable> B get(H hash, Blockchain blockchain, BlockchainUnitType type) throws IOException, ClassNotFoundException {
        logger.traceEntry("params: {} {} {}", hash, blockchain, type);

        Util.check(hash != null, "hash!=null");
        Util.check(blockchain != null, "blockchain!=null");

        BlockchainPersistenceUnit<H, B> unit = blockchain.getUnit(type);
        P2PConnection connection = blockchain.getConnection();

        Map<H, B> cache = unit.getCache();

        boolean exists = cache.get(hash) != null;
        if (!exists) {
            B object = getDataFromDatabase(hash, unit);
            if (object == null) {
                object = requestData(hash, type, connection);
            }

            return object;
        }

        B result = cache.get(hash);
        return logger.traceExit(result);

    }

}