package store import ( "github.com/tendermint/iavl" ) // Implements IterKVStore type IAVLStore struct { // } // XXX GUT THIS AND TURN IT INTO AN IAVLSTORE LOADER func loadState(dbName string, cacheSize int) (*sm.State, error) { // memory backed case, just for testing if dbName == "" { tree := iavl.NewVersionedTree(0, dbm.NewMemDB()) return sm.NewState(tree), nil } // Expand the path fully dbPath, err := filepath.Abs(dbName) if err != nil { return nil, errors.ErrInternal("Invalid Database Name") } // Some external calls accidently add a ".db", which is now removed dbPath = strings.TrimSuffix(dbPath, path.Ext(dbPath)) // Split the database name into it's components (dir, name) dir := path.Dir(dbPath) name := path.Base(dbPath) // Open database called "dir/name.db", if it doesn't exist it will be created db := dbm.NewDB(name, dbm.LevelDBBackendStr, dir) tree := iavl.NewVersionedTree(cacheSize, db) if err = tree.Load(); err != nil { return nil, errors.ErrInternal("Loading tree: " + err.Error()) } return sm.NewState(tree), nil }