mirror of https://github.com/status-im/op-geth.git
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:
parent
c47866d251
commit
bdba044a80
|
@ -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
|
||||
|
|
|
@ -132,13 +132,15 @@ type Ethereum struct {
|
|||
|
||||
logger logger.LogSystem
|
||||
|
||||
Mining bool
|
||||
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,30 +20,27 @@ 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) {
|
||||
fmt.Printf("config file '%s' doesn't exist, creating it\n", ConfigFile)
|
||||
os.Create(ConfigFile)
|
||||
}
|
||||
g, err := globalconf.NewWithOptions(&globalconf.Options{
|
||||
Filename: ConfigFile,
|
||||
EnvPrefix: EnvPrefix,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
g.ParseAll()
|
||||
}
|
||||
Config = &ConfigManager{ExecPath: Datadir, Debug: true, conf: g, Paranoia: true}
|
||||
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)
|
||||
}
|
||||
return Config
|
||||
g, err := globalconf.NewWithOptions(&globalconf.Options{
|
||||
Filename: ConfigFile,
|
||||
EnvPrefix: EnvPrefix,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
g.ParseAll()
|
||||
}
|
||||
cfg := &ConfigManager{ExecPath: Datadir, Debug: true, conf: g, Paranoia: true}
|
||||
return cfg
|
||||
}
|
||||
|
||||
// provides persistence for flags
|
||||
|
|
Loading…
Reference in New Issue