package org.ethereum.config;

import org.ethereum.datasource.HashMapDB;
import org.ethereum.datasource.KeyValueDataSource;
import org.ethereum.datasource.LevelDbDataSource;
import org.ethereum.db.BlockStore;
import org.ethereum.db.IndexedBlockStore;
import org.mapdb.DB;
import org.mapdb.DBMaker;
import org.mapdb.Serializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.ethereum.db.IndexedBlockStore.BLOCK_INFO_SERIALIZER;

/**
 *
 * @author Roman Mandeleil
 * Created on: 27/01/2015 01:05
 */
@Configuration
@Import(CommonConfig.class)
public class DefaultConfig {

    @Autowired
    CommonConfig commonConfig;

    @Autowired
    SystemProperties config;

    @Bean
    public BlockStore blockStore(){

        String database = config.databaseDir();

        String blocksIndexFile = database + "/blocks/index";
        File dbFile = new File(blocksIndexFile);
        if (!dbFile.getParentFile().exists()) dbFile.getParentFile().mkdirs();

        DB indexDB = DBMaker.fileDB(dbFile)
                .closeOnJvmShutdown()
                .make();

        Map<Long, List<IndexedBlockStore.BlockInfo>> indexMap = indexDB.hashMapCreate("index")
                .keySerializer(Serializer.LONG)
                .valueSerializer(BLOCK_INFO_SERIALIZER)
                .counterEnable()
                .makeOrGet();

        KeyValueDataSource blocksDB = levelDbDataSource("blocks");
        blocksDB.setName("blocks");
        blocksDB.init();


        IndexedBlockStore cache = new IndexedBlockStore();
        cache.init(new HashMap<Long, List<IndexedBlockStore.BlockInfo>>(), new HashMapDB(), null, null);

        IndexedBlockStore indexedBlockStore = new IndexedBlockStore();
        indexedBlockStore.init(indexMap, blocksDB, cache, indexDB);


        return indexedBlockStore;
    }

    @Bean
    LevelDbDataSource levelDbDataSource(String name) {
        LevelDbDataSource ret = new LevelDbDataSource(name);
        ret.setName(name);
        return ret;
    }
}

@@ -1678,44 +1678,8 @@
 %22);%0A
-        blocksDB.setName(%22blocks%22);%0A
     
@@ -2102,19 +2102,8 @@
 rce(
-String name
 ) %7B%0A
@@ -2106,24 +2106,35 @@
 ) %7B%0A        
+return new 
 LevelDbDataS
@@ -2142,70 +2142,82 @@
 urce
- ret = new LevelDbDataSource(name);%0A        ret.setName(
+();%0A    %7D%0A    @Bean%0A    LevelDbDataSource levelDbDataSource(String 
 name)
-;
+ %7B
 %0A   
@@ -2228,19 +2228,43 @@
  return 
-ret
+new LevelDbDataSource(name)
 ;%0A    %7D%0A

Fix levelDbDataSource bean