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:
Felix Lange 2015-03-06 02:46:56 +01:00
parent c47866d251
commit bdba044a80
7 changed files with 29 additions and 37 deletions

View File

@ -54,7 +54,7 @@ type JSRepl struct {
} }
func NewJSRepl(ethereum *eth.Ethereum) *JSRepl { 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 { if err != nil {
panic(err) panic(err)
} }

View File

@ -79,14 +79,14 @@ func (self *Gui) AddPlugin(pluginPath string) {
self.plugins[pluginPath] = plugin{Name: pluginPath, Path: pluginPath} self.plugins[pluginPath] = plugin{Name: pluginPath, Path: pluginPath}
json, _ := json.MarshalIndent(self.plugins, "", " ") 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) { func (self *Gui) RemovePlugin(pluginPath string) {
delete(self.plugins, pluginPath) delete(self.plugins, pluginPath)
json, _ := json.MarshalIndent(self.plugins, "", " ") 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 // this extra function needed to give int typecast value to gui widget

View File

@ -100,7 +100,7 @@ func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, session st
plugins: make(map[string]plugin), plugins: make(map[string]plugin),
serviceEvents: make(chan ServEv, 1), 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) json.Unmarshal([]byte(data), &gui.plugins)
return gui return gui

View File

@ -133,12 +133,14 @@ type Ethereum struct {
logger logger.LogSystem logger logger.LogSystem
Mining bool Mining bool
DataDir string
} }
func New(config *Config) (*Ethereum, error) { func New(config *Config) (*Ethereum, error) {
// Boostrap database // Boostrap database
ethlogger := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat) 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 { if err != nil {
return nil, err return nil, err
} }
@ -175,6 +177,7 @@ func New(config *Config) (*Ethereum, error) {
blacklist: p2p.NewBlacklist(), blacklist: p2p.NewBlacklist(),
eventMux: &event.TypeMux{}, eventMux: &event.TypeMux{},
logger: ethlogger, logger: ethlogger,
DataDir: config.DataDir,
} }
eth.chainManager = core.NewChainManager(db, eth.EventMux()) eth.chainManager = core.NewChainManager(db, eth.EventMux())

View File

@ -1,11 +1,10 @@
package ethdb package ethdb
import ( import (
"path"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/compression/rle" "github.com/ethereum/go-ethereum/compression/rle"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/iterator" "github.com/syndtr/goleveldb/leveldb/iterator"
) )
@ -15,17 +14,13 @@ type LDBDatabase struct {
comp bool comp bool
} }
func NewLDBDatabase(name string) (*LDBDatabase, error) { func NewLDBDatabase(file string) (*LDBDatabase, error) {
dbPath := path.Join(ethutil.Config.ExecPath, name)
// Open the db // Open the db
db, err := leveldb.OpenFile(dbPath, nil) db, err := leveldb.OpenFile(file, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
database := &LDBDatabase{db: db, comp: true} database := &LDBDatabase{db: db, comp: true}
return database, nil return database, nil
} }

View File

@ -20,15 +20,13 @@ type ConfigManager struct {
conf *globalconf.GlobalConf conf *globalconf.GlobalConf
} }
var Config *ConfigManager
// Read config // Read config
// //
// Initialize Config from Config File // Initialize Config from Config File
func ReadConfig(ConfigFile string, Datadir string, EnvPrefix string) *ConfigManager { 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) { 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) fmt.Printf("config file '%s' doesn't exist, creating it\n", ConfigFile)
os.Create(ConfigFile) os.Create(ConfigFile)
} }
@ -41,9 +39,8 @@ func ReadConfig(ConfigFile string, Datadir string, EnvPrefix string) *ConfigMana
} else { } else {
g.ParseAll() g.ParseAll()
} }
Config = &ConfigManager{ExecPath: Datadir, Debug: true, conf: g, Paranoia: true} cfg := &ConfigManager{ExecPath: Datadir, Debug: true, conf: g, Paranoia: true}
} return cfg
return Config
} }
// provides persistence for flags // provides persistence for flags

View File

@ -30,10 +30,7 @@ type Vm struct {
func New(env Environment) *Vm { func New(env Environment) *Vm {
lt := LogTyPretty lt := LogTyPretty
if ethutil.Config.Diff { // lt = LogTyDiff
lt = LogTyDiff
}
return &Vm{debug: true, env: env, logTy: lt, Recoverable: true} return &Vm{debug: true, env: env, logTy: lt, Recoverable: true}
} }