eth: add hook for database creation

This commit is contained in:
Felix Lange 2015-03-13 18:32:26 +01:00
parent 58d9d98daf
commit 6f8a2d6b84
1 changed files with 10 additions and 2 deletions

View File

@ -61,6 +61,10 @@ type Config struct {
MinerThreads int
AccountManager *accounts.Manager
// NewDB is used to create databases.
// If nil, the default is to create leveldb databases on disk.
NewDB func(path string) (ethutil.Database, error)
}
func (cfg *Config) parseBootNodes() []*discover.Node {
@ -136,11 +140,15 @@ func New(config *Config) (*Ethereum, error) {
// Boostrap database
servlogger := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat)
blockDb, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "blockchain"))
newdb := config.NewDB
if newdb == nil {
newdb = func(path string) (ethutil.Database, error) { return ethdb.NewLDBDatabase(path) }
}
blockDb, err := newdb(path.Join(config.DataDir, "blockchain"))
if err != nil {
return nil, err
}
stateDb, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "state"))
stateDb, err := newdb(path.Join(config.DataDir, "state"))
if err != nil {
return nil, err
}