func createDBStore(config *config.BlockStoreConfig) (dbstore.DBStore, error) {
	switch config.PluginName {
	case PLUGIN_LEVELDB:
		log.Debug("Create file-based block store, with file path: %s ", config.DataPath)
		return leveldbstore.NewLevelDBStore(config.DataPath)
	case PLUGIN_MEMDB:
		log.Debug("Create memory-based block store")
		return memorystore.NewMemDBStore(), nil
	default:
		log.Error("Not support plugin.")
		return nil, fmt.Errorf("Not support plugin type %s", config.PluginName)
	}
}
init db store.
package blockstore
import (
	"bytes"
	"encoding/binary"
	"encoding/json"
	"fmt"
	"github.com/DSiSc/blockstore/common"
	"github.com/DSiSc/blockstore/config"
	"github.com/DSiSc/blockstore/dbstore"
	"github.com/DSiSc/blockstore/dbstore/leveldbstore"
	"github.com/DSiSc/blockstore/dbstore/memorystore"
	"github.com/DSiSc/blockstore/indexes"
	"github.com/DSiSc/craft/log"
	"github.com/DSiSc/craft/types"
	"sync"
	"sync/atomic"
)
const (
	PLUGIN_LEVELDB = "leveldb"
	PLUGIN_MEMDB = "memorydb"
	INIT_BLOCK_HEIGHT = 0
	latestBlockKey = "LatestBlock"
)
var (
	blockPrefix       = []byte("b")
	blockHeightPrefix = []byte("h")
	txPrefix          = []byte("t")
	receiptPrefix     = []byte("r")
)
type BlockStore struct {
	store        dbstore.DBStore  
	currentBlock atomic.Value     
	lock         sync.RWMutex
}
func NewBlockStore(config *config.BlockStoreConfig) (*BlockStore, error) {
	log.Info("Start creating block store, with config: %v ", config)
	store, err := createDBStore(config)
	if err != nil {
		return nil, err
	}
	blockStore := &BlockStore{
		store: store,
	}
	blockStore.loadLatestBlock()
	return blockStore, nil
}