ethutil: remove Config variable
Various functions throughout the codebase used it to grab settings. This has to stop because I want to use them without reading the config file. These functions can now be used without reading the config first: * ethdb.NewLDBDatabase * ethrepl.NewJSRepl * vm.New
This commit is contained in:
		@@ -54,7 +54,7 @@ type JSRepl struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewJSRepl(ethereum *eth.Ethereum) *JSRepl {
 | 
			
		||||
	hist, err := os.OpenFile(path.Join(ethutil.Config.ExecPath, "history"), os.O_RDWR|os.O_CREATE, os.ModePerm)
 | 
			
		||||
	hist, err := os.OpenFile(path.Join(ethereum.DataDir, "history"), os.O_RDWR|os.O_CREATE, os.ModePerm)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -79,14 +79,14 @@ func (self *Gui) AddPlugin(pluginPath string) {
 | 
			
		||||
	self.plugins[pluginPath] = plugin{Name: pluginPath, Path: pluginPath}
 | 
			
		||||
 | 
			
		||||
	json, _ := json.MarshalIndent(self.plugins, "", "    ")
 | 
			
		||||
	ethutil.WriteFile(ethutil.Config.ExecPath+"/plugins.json", json)
 | 
			
		||||
	ethutil.WriteFile(self.eth.DataDir+"/plugins.json", json)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (self *Gui) RemovePlugin(pluginPath string) {
 | 
			
		||||
	delete(self.plugins, pluginPath)
 | 
			
		||||
 | 
			
		||||
	json, _ := json.MarshalIndent(self.plugins, "", "    ")
 | 
			
		||||
	ethutil.WriteFile(ethutil.Config.ExecPath+"/plugins.json", json)
 | 
			
		||||
	ethutil.WriteFile(self.eth.DataDir+"/plugins.json", json)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// this extra function needed to give int typecast value to gui widget
 | 
			
		||||
 
 | 
			
		||||
@@ -100,7 +100,7 @@ func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, session st
 | 
			
		||||
		plugins:       make(map[string]plugin),
 | 
			
		||||
		serviceEvents: make(chan ServEv, 1),
 | 
			
		||||
	}
 | 
			
		||||
	data, _ := ethutil.ReadAllFile(path.Join(ethutil.Config.ExecPath, "plugins.json"))
 | 
			
		||||
	data, _ := ethutil.ReadAllFile(path.Join(ethereum.DataDir, "plugins.json"))
 | 
			
		||||
	json.Unmarshal([]byte(data), &gui.plugins)
 | 
			
		||||
 | 
			
		||||
	return gui
 | 
			
		||||
 
 | 
			
		||||
@@ -133,12 +133,14 @@ type Ethereum struct {
 | 
			
		||||
	logger logger.LogSystem
 | 
			
		||||
 | 
			
		||||
	Mining  bool
 | 
			
		||||
	DataDir string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func New(config *Config) (*Ethereum, error) {
 | 
			
		||||
	// Boostrap database
 | 
			
		||||
	ethlogger := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat)
 | 
			
		||||
	db, err := ethdb.NewLDBDatabase("blockchain")
 | 
			
		||||
 | 
			
		||||
	db, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "blockchain"))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
@@ -175,6 +177,7 @@ func New(config *Config) (*Ethereum, error) {
 | 
			
		||||
		blacklist:    p2p.NewBlacklist(),
 | 
			
		||||
		eventMux:     &event.TypeMux{},
 | 
			
		||||
		logger:       ethlogger,
 | 
			
		||||
		DataDir:      config.DataDir,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	eth.chainManager = core.NewChainManager(db, eth.EventMux())
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,10 @@
 | 
			
		||||
package ethdb
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"path"
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"github.com/ethereum/go-ethereum/ethutil"
 | 
			
		||||
	"github.com/ethereum/go-ethereum/compression/rle"
 | 
			
		||||
	"github.com/ethereum/go-ethereum/ethutil"
 | 
			
		||||
	"github.com/syndtr/goleveldb/leveldb"
 | 
			
		||||
	"github.com/syndtr/goleveldb/leveldb/iterator"
 | 
			
		||||
)
 | 
			
		||||
@@ -15,17 +14,13 @@ type LDBDatabase struct {
 | 
			
		||||
	comp bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewLDBDatabase(name string) (*LDBDatabase, error) {
 | 
			
		||||
	dbPath := path.Join(ethutil.Config.ExecPath, name)
 | 
			
		||||
 | 
			
		||||
func NewLDBDatabase(file string) (*LDBDatabase, error) {
 | 
			
		||||
	// Open the db
 | 
			
		||||
	db, err := leveldb.OpenFile(dbPath, nil)
 | 
			
		||||
	db, err := leveldb.OpenFile(file, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	database := &LDBDatabase{db: db, comp: true}
 | 
			
		||||
 | 
			
		||||
	return database, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -20,15 +20,13 @@ type ConfigManager struct {
 | 
			
		||||
	conf *globalconf.GlobalConf
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var Config *ConfigManager
 | 
			
		||||
 | 
			
		||||
// Read config
 | 
			
		||||
//
 | 
			
		||||
// Initialize Config from Config File
 | 
			
		||||
func ReadConfig(ConfigFile string, Datadir string, EnvPrefix string) *ConfigManager {
 | 
			
		||||
	if Config == nil {
 | 
			
		||||
		// create ConfigFile if does not exist, otherwise globalconf panic when trying to persist flags
 | 
			
		||||
	if !FileExist(ConfigFile) {
 | 
			
		||||
		// create ConfigFile if it does not exist, otherwise
 | 
			
		||||
		// globalconf will panic when trying to persist flags.
 | 
			
		||||
		fmt.Printf("config file '%s' doesn't exist, creating it\n", ConfigFile)
 | 
			
		||||
		os.Create(ConfigFile)
 | 
			
		||||
	}
 | 
			
		||||
@@ -41,9 +39,8 @@ func ReadConfig(ConfigFile string, Datadir string, EnvPrefix string) *ConfigMana
 | 
			
		||||
	} else {
 | 
			
		||||
		g.ParseAll()
 | 
			
		||||
	}
 | 
			
		||||
		Config = &ConfigManager{ExecPath: Datadir, Debug: true, conf: g, Paranoia: true}
 | 
			
		||||
	}
 | 
			
		||||
	return Config
 | 
			
		||||
	cfg := &ConfigManager{ExecPath: Datadir, Debug: true, conf: g, Paranoia: true}
 | 
			
		||||
	return cfg
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// provides persistence for flags
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user