From d060ae6a368bb880132e548c58b33e2508adc125 Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 23 Jun 2014 11:41:11 +0100 Subject: changed logger API, functions that allow Gui to implement ethlog.LogSystem for gui logging --- ethereal/ui/gui.go | 57 +++++++++++++++++++++++++------------------ ethereal/ui/html_container.go | 4 +-- ethereal/ui/ui_lib.go | 6 ++--- 3 files changed, 38 insertions(+), 29 deletions(-) (limited to 'ethereal') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 01d963332..d3b298d90 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/eth-go/ethdb" "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" "math/big" @@ -15,6 +16,8 @@ import ( "time" ) +var logger = ethlog.NewLogger("GUI") + type Gui struct { // The main application window win *qml.Window @@ -33,10 +36,11 @@ type Gui struct { addr []byte pub *ethpub.PEthereum + logLevel ethlog.LogLevel } // Create GUI, but doesn't start it -func New(ethereum *eth.Ethereum) *Gui { +func New(ethereum *eth.Ethereum, logLevel ethlog.LogLevel) *Gui { lib := &EthLib{stateManager: ethereum.StateManager(), blockChain: ethereum.BlockChain(), txPool: ethereum.TxPool()} db, err := ethdb.NewLDBDatabase("tx_database") if err != nil { @@ -52,7 +56,7 @@ func New(ethereum *eth.Ethereum) *Gui { pub := ethpub.NewPEthereum(ethereum) - return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub} + return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub, logLevel: logLevel} } func (gui *Gui) Start(assetPath string) { @@ -90,16 +94,15 @@ func (gui *Gui) Start(assetPath string) { win, err = gui.showKeyImport(context) } else { win, err = gui.showWallet(context) - - ethutil.Config.Log.AddLogSystem(gui) + ethlog.AddLogSystem(gui) } if err != nil { - ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'", err) + logger.Errorln("asset not found: you can set an alternative asset path on the command line using option 'asset_path'", err) panic(err) } - ethutil.Config.Log.Infoln("[GUI] Starting GUI") + logger.Infoln("Starting GUI") win.Show() win.Wait() @@ -315,22 +318,6 @@ func (gui *Gui) setPeerInfo() { } } -// Logging functions that log directly to the GUI interface -func (gui *Gui) Println(v ...interface{}) { - str := strings.TrimRight(fmt.Sprintln(v...), "\n") - lines := strings.Split(str, "\n") - for _, line := range lines { - gui.win.Root().Call("addLog", line) - } -} - -func (gui *Gui) Printf(format string, v ...interface{}) { - str := strings.TrimRight(fmt.Sprintf(format, v...), "\n") - lines := strings.Split(str, "\n") - for _, line := range lines { - gui.win.Root().Call("addLog", line) - } -} func (gui *Gui) RegisterName(name string) { keyPair := ethutil.GetKeyRing().Get(0) name = fmt.Sprintf("\"%s\"\n1", name) @@ -357,6 +344,28 @@ func (gui *Gui) ClientId() string { return ethutil.Config.Identifier } -func (gui *Gui) SetLogLevel(level int) { - ethutil.Config.Log.SetLevel(level) +// functions that allow Gui to implement interface ethlog.LogSystem +func (gui *Gui) SetLogLevel(level ethlog.LogLevel) { + gui.logLevel = level +} + +func (gui *Gui) GetLogLevel() ethlog.LogLevel { + return gui.logLevel +} + +func (gui *Gui) Println(v ...interface{}) { + gui.printLog(fmt.Sprintln(v...)) +} + +func (gui *Gui) Printf(format string, v ...interface{}) { + gui.printLog(fmt.Sprintf(format, v...)) +} + +// Print function that logs directly to the GUI +func (gui *Gui) printLog(s string) { + str := strings.TrimRight(s, "\n") + lines := strings.Split(str, "\n") + for _, line := range lines { + gui.win.Root().Call("addLog", line) + } } diff --git a/ethereal/ui/html_container.go b/ethereal/ui/html_container.go index 3867c0353..d7dc80af7 100644 --- a/ethereal/ui/html_container.go +++ b/ethereal/ui/html_container.go @@ -96,11 +96,11 @@ func (app *HtmlApplication) NewWatcher(quitChan chan bool) { app.watcher.Close() break out case <-app.watcher.Event: - //ethutil.Config.Log.Debugln("Got event:", ev) + //logger.Debugln("Got event:", ev) app.webView.Call("reload") case err := <-app.watcher.Error: // TODO: Do something here - ethutil.Config.Log.Infoln("Watcher error:", err) + logger.Infoln("Watcher error:", err) } } }() diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 9f2cca1e0..eb607aac5 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -40,7 +40,7 @@ func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { func (ui *UiLib) Open(path string) { component, err := ui.engine.LoadFile(path[7:]) if err != nil { - ethutil.Config.Log.Debugln(err) + logger.Debugln(err) } win := component.CreateWindow(nil) @@ -60,7 +60,7 @@ func (ui *UiLib) OpenHtml(path string) { func (ui *UiLib) Muted(content string) { component, err := ui.engine.LoadFile(ui.AssetPath("qml/muted.qml")) if err != nil { - ethutil.Config.Log.Debugln(err) + logger.Debugln(err) return } @@ -144,7 +144,7 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) script, err := ethutil.Compile(data) if err != nil { - ethutil.Config.Log.Debugln(err) + logger.Debugln(err) return } -- cgit v1.2.3 From 1024766514eea7bb628ec6e5ed974e997b8faefc Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 23 Jun 2014 12:20:59 +0100 Subject: refactor cli and gui wrapper code. Details: - all cli functions shared between ethereum and ethereal abstracted to utils/ cmd.go (should be ethcommon or shared or sth) - simplify main() now readable stepwise - rename main wrapper files to main.go - rename commmand line args definition file from config.go to flags.go - rename Do -> Start to parallel option names - register interrupt for rpc server stop - fix interrupt stopping js repl and ethereum - register interrupt for mining stop - custom config file option from command line - debug option from command line - loglevel option from command line - changed ethutil.Config API - default datadir and default config file set together with other flag defaults in wrappers - default assetpath set together with other command line flags defaults in gui wrapper (not in ethutil.Config or ui/ui_lib) - options precedence: default < config file < environment variables < command line --- ethereal/config.go | 43 --------------- ethereal/ethereum.go | 142 -------------------------------------------------- ethereal/flags.go | 81 ++++++++++++++++++++++++++++ ethereal/main.go | 43 +++++++++++++++ ethereal/ui/ui_lib.go | 30 +---------- 5 files changed, 125 insertions(+), 214 deletions(-) delete mode 100644 ethereal/config.go delete mode 100644 ethereal/ethereum.go create mode 100644 ethereal/flags.go create mode 100644 ethereal/main.go (limited to 'ethereal') diff --git a/ethereal/config.go b/ethereal/config.go deleted file mode 100644 index 2315d1435..000000000 --- a/ethereal/config.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - "flag" -) - -var Identifier string - -//var StartMining bool -var StartRpc bool -var RpcPort int -var UseUPnP bool -var OutboundPort string -var ShowGenesis bool -var AddPeer string -var MaxPeer int -var GenAddr bool -var UseSeed bool -var ImportKey string -var ExportKey bool -var AssetPath string - -var Datadir string - -func Init() { - flag.StringVar(&Identifier, "id", "", "Custom client identifier") - flag.StringVar(&OutboundPort, "port", "30303", "listening port") - flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support") - flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers") - flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on") - flag.BoolVar(&StartRpc, "rpc", false, "start rpc server") - flag.StringVar(&AssetPath, "asset_path", "", "absolute path to GUI assets directory") - - flag.BoolVar(&ShowGenesis, "genesis", false, "prints genesis header and exits") - flag.BoolVar(&UseSeed, "seed", true, "seed peers") - flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key") - flag.BoolVar(&ExportKey, "export", false, "export private key") - flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)") - - flag.StringVar(&Datadir, "datadir", ".ethereal", "specifies the datadir to use. Takes precedence over config file.") - - flag.Parse() -} diff --git a/ethereal/ethereum.go b/ethereal/ethereum.go deleted file mode 100644 index 0db1fa4cd..000000000 --- a/ethereal/ethereum.go +++ /dev/null @@ -1,142 +0,0 @@ -package main - -import ( - "fmt" - "github.com/ethereum/eth-go" - "github.com/ethereum/eth-go/ethutil" - "github.com/ethereum/go-ethereum/ethereal/ui" - "github.com/ethereum/go-ethereum/utils" - "github.com/go-qml/qml" - "github.com/rakyll/globalconf" - "log" - "os" - "os/signal" - "path" - "runtime" -) - -const Debug = true - -// Register interrupt handlers so we can stop the ethereum -func RegisterInterupts(s *eth.Ethereum) { - // Buffered chan of one is enough - c := make(chan os.Signal, 1) - // Notify about interrupts for now - signal.Notify(c, os.Interrupt) - go func() { - for sig := range c { - fmt.Printf("Shutting down (%v) ... \n", sig) - - s.Stop() - } - }() -} - -func main() { - Init() - - qml.Init(nil) - - runtime.GOMAXPROCS(runtime.NumCPU()) - - g, err := globalconf.NewWithOptions(&globalconf.Options{ - Filename: path.Join(ethutil.ApplicationFolder(Datadir), "conf.ini"), - }) - if err != nil { - fmt.Println(err) - } else { - g.ParseAll() - } - ethutil.ReadConfig(Datadir, ethutil.LogFile|ethutil.LogStd, g, Identifier) - - // Instantiated a eth stack - ethereum, err := eth.New(eth.CapDefault, UseUPnP) - if err != nil { - log.Println("eth start err:", err) - return - } - ethereum.Port = OutboundPort - - if GenAddr { - fmt.Println("This action overwrites your old private key. Are you sure? (y/n)") - - var r string - fmt.Scanln(&r) - for ; ; fmt.Scanln(&r) { - if r == "n" || r == "y" { - break - } else { - fmt.Printf("Yes or no?", r) - } - } - - if r == "y" { - utils.CreateKeyPair(true) - } - os.Exit(0) - } else { - if len(ImportKey) > 0 { - fmt.Println("This action overwrites your old private key. Are you sure? (y/n)") - var r string - fmt.Scanln(&r) - for ; ; fmt.Scanln(&r) { - if r == "n" || r == "y" { - break - } else { - fmt.Printf("Yes or no?", r) - } - } - - if r == "y" { - utils.ImportPrivateKey(ImportKey) - os.Exit(0) - } - } - } - - if ExportKey { - keyPair := ethutil.GetKeyRing().Get(0) - fmt.Printf(` -Generating new address and keypair. -Please keep your keys somewhere save. - -++++++++++++++++ KeyRing +++++++++++++++++++ -addr: %x -prvk: %x -pubk: %x -++++++++++++++++++++++++++++++++++++++++++++ -save these words so you can restore your account later: %s -`, keyPair.Address(), keyPair.PrivateKey, keyPair.PublicKey) - - os.Exit(0) - } - - if ShowGenesis { - fmt.Println(ethereum.BlockChain().Genesis()) - os.Exit(0) - } - - /* - if StartMining { - utils.DoMining(ethereum) - } - */ - - if StartRpc { - utils.DoRpc(ethereum, RpcPort) - } - - log.Printf("Starting Ethereum GUI v%s\n", ethutil.Config.Ver) - - // Set the max peers - ethereum.MaxPeers = MaxPeer - - gui := ethui.New(ethereum) - - ethereum.Start(UseSeed) - - gui.Start(AssetPath) - - // Wait for shutdown - ethereum.WaitForShutdown() -} diff --git a/ethereal/flags.go b/ethereal/flags.go new file mode 100644 index 000000000..18f55071a --- /dev/null +++ b/ethereal/flags.go @@ -0,0 +1,81 @@ +package main + +import ( + "flag" +) + +var Identifier string +var StartRpc bool +var RpcPort int +var UseUPnP bool +var OutboundPort string +var ShowGenesis bool +var AddPeer string +var MaxPeer int +var GenAddr bool +var UseSeed bool +var ImportKey string +var ExportKey bool +var NonInteractive bool +var Datadir string +var LogFile string +var ConfigFile string +var DebugFile string +var LogLevel int + +// flags specific to gui client +var AssetPath string + +func defaultAssetPath() string { + var assetPath string + // If the current working directory is the go-ethereum dir + // assume a debug build and use the source directory as + // asset directory. + pwd, _ := os.Getwd() + if pwd == path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "ethereal") { + assetPath = path.Join(pwd, "assets") + } else { + switch runtime.GOOS { + case "darwin": + // Get Binary Directory + exedir, _ := osext.ExecutableFolder() + assetPath = filepath.Join(exedir, "../Resources") + case "linux": + assetPath = "/usr/share/ethereal" + case "window": + fallthrough + default: + assetPath = "." + } + } + return assetPath +} + +func defaultDataDir() string { + usr, _ := user.Current() + return path.Join(usr.HomeDir, ".ethereum") +} + +var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini") + +func Init() { + flag.StringVar(&Identifier, "id", "", "Custom client identifier") + flag.StringVar(&OutboundPort, "port", "30303", "listening port") + flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support") + flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers") + flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on") + flag.BoolVar(&StartRpc, "rpc", false, "start rpc server") + flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)") + flag.BoolVar(&UseSeed, "seed", true, "seed peers") + flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key") + flag.BoolVar(&ExportKey, "export", false, "export private key") + flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)") + flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)") + flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use") + flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file") + flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)") + flag.IntVar(&LogLevel, "loglevel", int(ethlog.InfoLevel), "loglevel: 0-4: silent,error,warn,info,debug)") + flag.StringVar(&AssetPath, "asset_path", defaultAssetPath, "absolute path to GUI assets directory") + + flag.Parse() +} diff --git a/ethereal/main.go b/ethereal/main.go new file mode 100644 index 000000000..4af068197 --- /dev/null +++ b/ethereal/main.go @@ -0,0 +1,43 @@ +package main + +import ( + "fmt" + "github.com/ethereum/go-ethereum/ethereal/ui" + "github.com/ethereum/go-ethereum/utils" + "github.com/go-qml/qml" + "runtime" +) + +const Debug = true + +func main() { + qml.Init(nil) + + runtime.GOMAXPROCS(runtime.NumCPU()) + + // precedence: code-internal flag default < config file < environment variables < command line + Init() // parsing command line + utils.InitConfig(ConfigFile, Datadir, Identifier, "ETH") + + utils.InitDataDir(Datadir) + + utils.InitLogging(Datadir, LogFile, LogLevel, DebugFile) + + ethereum := utils.NewEthereum(UseUPnP, OutboundPort, MaxPeer) + + // create, import, export keys + utils.KeyTasks(GenAddr, ImportKey, ExportKey, NonInteractive) + + if ShowGenesis { + utils.ShowGenesis(ethereum) + } + + if StartRpc { + utils.StartRpc(ethereum, RpcPort) + } + + utils.StartEthereum(ethereum, UseSeed) + + gui := ethui.New(ethereum, logLevel) + gui.Start(AssetPath) +} diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 2dd66f4fd..156d55157 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -29,9 +29,6 @@ type UiLib struct { } func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { - if assetPath == "" { - assetPath = DefaultAssetPath() - } return &UiLib{engine: engine, eth: eth, assetPath: assetPath} } @@ -88,6 +85,7 @@ func (ui *UiLib) ConnectToPeer(addr string) { func (ui *UiLib) AssetPath(p string) string { return path.Join(ui.assetPath, p) } + func (self *UiLib) StartDbWithContractAndData(contractHash, data string) { dbWindow := NewDebuggerWindow(self) object := self.eth.StateManager().CurrentState().GetStateObject(ethutil.FromHex(contractHash)) @@ -111,29 +109,3 @@ func (self *UiLib) StartDebugger() { dbWindow.Show() } - -func DefaultAssetPath() string { - var base string - // If the current working directory is the go-ethereum dir - // assume a debug build and use the source directory as - // asset directory. - pwd, _ := os.Getwd() - if pwd == path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "ethereal") { - base = path.Join(pwd, "assets") - } else { - switch runtime.GOOS { - case "darwin": - // Get Binary Directory - exedir, _ := osext.ExecutableFolder() - base = filepath.Join(exedir, "../Resources") - case "linux": - base = "/usr/share/ethereal" - case "window": - fallthrough - default: - base = "." - } - } - - return base -} -- cgit v1.2.3 From 6f09a3e8200ba2eeeeb296141d6644d04078a9c4 Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 23 Jun 2014 12:38:23 +0100 Subject: fix imports in ui_lib and flags cos of defaultAssetPath move; fix logLevel type for gui --- ethereal/flags.go | 15 ++++++++++++++- ethereal/main.go | 5 +---- ethereal/ui/gui.go | 4 ++-- ethereal/ui/ui_lib.go | 4 ---- 4 files changed, 17 insertions(+), 11 deletions(-) (limited to 'ethereal') diff --git a/ethereal/flags.go b/ethereal/flags.go index 18f55071a..5975439c9 100644 --- a/ethereal/flags.go +++ b/ethereal/flags.go @@ -1,7 +1,15 @@ package main import ( + "fmt" + "os" + "os/user" + "path" + "github.com/ethereum/eth-go/ethlog" "flag" + "bitbucket.org/kardianos/osext" + "path/filepath" + "runtime" ) var Identifier string @@ -59,6 +67,11 @@ func defaultDataDir() string { var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini") func Init() { + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line", os.Args[0]) + flag.PrintDefaults() + } + flag.StringVar(&Identifier, "id", "", "Custom client identifier") flag.StringVar(&OutboundPort, "port", "30303", "listening port") flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support") @@ -75,7 +88,7 @@ func Init() { flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file") flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)") flag.IntVar(&LogLevel, "loglevel", int(ethlog.InfoLevel), "loglevel: 0-4: silent,error,warn,info,debug)") - flag.StringVar(&AssetPath, "asset_path", defaultAssetPath, "absolute path to GUI assets directory") + flag.StringVar(&AssetPath, "asset_path", defaultAssetPath(), "absolute path to GUI assets directory") flag.Parse() } diff --git a/ethereal/main.go b/ethereal/main.go index 4af068197..10571be7b 100644 --- a/ethereal/main.go +++ b/ethereal/main.go @@ -1,15 +1,12 @@ package main import ( - "fmt" "github.com/ethereum/go-ethereum/ethereal/ui" "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" "runtime" ) -const Debug = true - func main() { qml.Init(nil) @@ -38,6 +35,6 @@ func main() { utils.StartEthereum(ethereum, UseSeed) - gui := ethui.New(ethereum, logLevel) + gui := ethui.New(ethereum, LogLevel) gui.Start(AssetPath) } diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index ed29e2485..f3a918ea0 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -40,7 +40,7 @@ type Gui struct { } // Create GUI, but doesn't start it -func New(ethereum *eth.Ethereum, logLevel ethlog.LogLevel) *Gui { +func New(ethereum *eth.Ethereum, logLevel int) *Gui { lib := &EthLib{stateManager: ethereum.StateManager(), blockChain: ethereum.BlockChain(), txPool: ethereum.TxPool()} db, err := ethdb.NewLDBDatabase("tx_database") if err != nil { @@ -56,7 +56,7 @@ func New(ethereum *eth.Ethereum, logLevel ethlog.LogLevel) *Gui { pub := ethpub.NewPEthereum(ethereum) - return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub, logLevel: logLevel} + return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub, logLevel: ethlog.LogLevel(logLevel)} } func (gui *Gui) Start(assetPath string) { diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 156d55157..5f6a9ef0b 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -1,14 +1,10 @@ package ethui import ( - "bitbucket.org/kardianos/osext" "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" - "os" "path" - "path/filepath" - "runtime" ) type memAddr struct { -- cgit v1.2.3 From 39c0f7f3865965ae64ea51aba4de5b7350539ea8 Mon Sep 17 00:00:00 2001 From: zelig Date: Wed, 25 Jun 2014 16:53:19 +0100 Subject: fix logSlider: now has 5 levels, initialized to gui.GetLogLevel which is set through command line flag (defaults to InfoLevel) --- ethereal/assets/qml/wallet.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ethereal') diff --git a/ethereal/assets/qml/wallet.qml b/ethereal/assets/qml/wallet.qml index 454d0f3f0..eb3aa6df5 100644 --- a/ethereal/assets/qml/wallet.qml +++ b/ethereal/assets/qml/wallet.qml @@ -319,7 +319,7 @@ ApplicationWindow { Slider { id: logLevelSlider - value: 1 + value: eth.getLogLevel() anchors { right: parent.right top: parent.top @@ -332,7 +332,7 @@ ApplicationWindow { } orientation: Qt.Vertical - maximumValue: 3 + maximumValue: 5 stepSize: 1 onValueChanged: { -- cgit v1.2.3 From 8ee1abecb971e39ad5e0ed5b199ff4bf553ca67a Mon Sep 17 00:00:00 2001 From: zelig Date: Wed, 25 Jun 2014 16:54:29 +0100 Subject: update log levels to include DebugDetail; correct default datadir for ethereal --- ethereal/flags.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'ethereal') diff --git a/ethereal/flags.go b/ethereal/flags.go index 5975439c9..5ab4c80e2 100644 --- a/ethereal/flags.go +++ b/ethereal/flags.go @@ -61,7 +61,7 @@ func defaultAssetPath() string { func defaultDataDir() string { usr, _ := user.Current() - return path.Join(usr.HomeDir, ".ethereum") + return path.Join(usr.HomeDir, ".ethereal") } var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini") @@ -87,7 +87,8 @@ func Init() { flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use") flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file") flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)") - flag.IntVar(&LogLevel, "loglevel", int(ethlog.InfoLevel), "loglevel: 0-4: silent,error,warn,info,debug)") + flag.IntVar(&LogLevel, "loglevel", int(ethlog.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)") + flag.StringVar(&AssetPath, "asset_path", defaultAssetPath(), "absolute path to GUI assets directory") flag.Parse() -- cgit v1.2.3 From bf57e9603b9ef2c96e8e6d7c3d22ea674392d56b Mon Sep 17 00:00:00 2001 From: zelig Date: Wed, 25 Jun 2014 18:09:42 +0100 Subject: add newline to help usage msg --- ethereal/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal') diff --git a/ethereal/flags.go b/ethereal/flags.go index 5ab4c80e2..7e83e355f 100644 --- a/ethereal/flags.go +++ b/ethereal/flags.go @@ -68,7 +68,7 @@ var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini") func Init() { flag.Usage = func() { - fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line", os.Args[0]) + fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line\n", os.Args[0]) flag.PrintDefaults() } -- cgit v1.2.3 From 9a06efd0809c370451c5e85ce4688104cd5df461 Mon Sep 17 00:00:00 2001 From: zelig Date: Wed, 25 Jun 2014 18:28:38 +0100 Subject: new logger API for upstream merge --- ethereal/ui/qml_app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal') diff --git a/ethereal/ui/qml_app.go b/ethereal/ui/qml_app.go index d47751616..39ab7f922 100644 --- a/ethereal/ui/qml_app.go +++ b/ethereal/ui/qml_app.go @@ -22,7 +22,7 @@ func NewQmlApplication(path string, lib *UiLib) *QmlApplication { func (app *QmlApplication) Create() error { component, err := app.engine.LoadFile(app.path) if err != nil { - ethutil.Config.Log.Debugln(err) + logger.Warnln(err) } app.win = component.CreateWindow(nil) -- cgit v1.2.3 From 2f96652bb408e65c205317403d749ba9a395c6bb Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 26 Jun 2014 10:47:45 +0100 Subject: interrupt handlers now ordered --- ethereal/main.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'ethereal') diff --git a/ethereal/main.go b/ethereal/main.go index 10571be7b..5dfab4c45 100644 --- a/ethereal/main.go +++ b/ethereal/main.go @@ -8,10 +8,12 @@ import ( ) func main() { - qml.Init(nil) - runtime.GOMAXPROCS(runtime.NumCPU()) + utils.HandleInterrupt() + + qml.Init(nil) + // precedence: code-internal flag default < config file < environment variables < command line Init() // parsing command line utils.InitConfig(ConfigFile, Datadir, Identifier, "ETH") @@ -33,8 +35,10 @@ func main() { utils.StartRpc(ethereum, RpcPort) } - utils.StartEthereum(ethereum, UseSeed) - gui := ethui.New(ethereum, LogLevel) gui.Start(AssetPath) + + utils.StartEthereum(ethereum, UseSeed) + + } -- cgit v1.2.3 From c0a05fcf8984f04f198c5c0f8be4f73090f99403 Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 26 Jun 2014 12:13:31 +0100 Subject: log slider - only add the gui logger after window is shown otherwise slider wont be shown - need to silence gui logger after window closed otherwise logsystem hangs - gui.GetLogLevelInt() extra function needed to give correcty int typecast value to gui widget that sets initial loglevel to default --- ethereal/assets/qml/wallet.qml | 2 +- ethereal/ui/gui.go | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'ethereal') diff --git a/ethereal/assets/qml/wallet.qml b/ethereal/assets/qml/wallet.qml index eb3aa6df5..84f8fd5cf 100644 --- a/ethereal/assets/qml/wallet.qml +++ b/ethereal/assets/qml/wallet.qml @@ -319,7 +319,7 @@ ApplicationWindow { Slider { id: logLevelSlider - value: eth.getLogLevel() + value: eth.getLogLevelInt() anchors { right: parent.right top: parent.top diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index f3a918ea0..8845f6af3 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -90,11 +90,12 @@ func (gui *Gui) Start(assetPath string) { var win *qml.Window var err error + var addlog = false if len(data) == 0 { win, err = gui.showKeyImport(context) } else { win, err = gui.showWallet(context) - ethlog.AddLogSystem(gui) + addlog = true } if err != nil { logger.Errorln("asset not found: you can set an alternative asset path on the command line using option 'asset_path'", err) @@ -105,8 +106,13 @@ func (gui *Gui) Start(assetPath string) { logger.Infoln("Starting GUI") win.Show() + // only add the gui logger after window is shown otherwise slider wont be shown + if addlog { + ethlog.AddLogSystem(gui) + } win.Wait() - + // need to silence gui logger after window closed otherwise logsystem hangs + gui.SetLogLevel(ethlog.Silence) gui.eth.Stop() } @@ -353,6 +359,12 @@ func (gui *Gui) GetLogLevel() ethlog.LogLevel { return gui.logLevel } +// this extra function needed to give int typecast value to gui widget +// that sets initial loglevel to default +func (gui *Gui) GetLogLevelInt() int { + return int(gui.logLevel) +} + func (gui *Gui) Println(v ...interface{}) { gui.printLog(fmt.Sprintln(v...)) } -- cgit v1.2.3 From 21d86ca486a88c936a1fe71f78d76c78df36a7eb Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 26 Jun 2014 16:26:14 +0100 Subject: gui stop - introduce gui.Stop() - remember state with open - stopping ethereum stack is not gui concern, moved to main - stopping mining, gui and ethereum handled via interrupt callbacks - ^C triggers exactly the same behaviour as quit via menu --- ethereal/main.go | 27 ++++++++++++++++++++++----- ethereal/ui/gui.go | 16 +++++++++++++--- 2 files changed, 35 insertions(+), 8 deletions(-) (limited to 'ethereal') diff --git a/ethereal/main.go b/ethereal/main.go index 5dfab4c45..cfd85afe7 100644 --- a/ethereal/main.go +++ b/ethereal/main.go @@ -3,17 +3,24 @@ package main import ( "github.com/ethereum/go-ethereum/ethereal/ui" "github.com/ethereum/go-ethereum/utils" + "github.com/ethereum/eth-go/ethlog" "github.com/go-qml/qml" "runtime" + "os" ) func main() { runtime.GOMAXPROCS(runtime.NumCPU()) - utils.HandleInterrupt() - qml.Init(nil) + var interrupted = false + utils.RegisterInterrupt(func(os.Signal) { + interrupted = true + }) + + utils.HandleInterrupt() + // precedence: code-internal flag default < config file < environment variables < command line Init() // parsing command line utils.InitConfig(ConfigFile, Datadir, Identifier, "ETH") @@ -36,9 +43,19 @@ func main() { } gui := ethui.New(ethereum, LogLevel) - gui.Start(AssetPath) + utils.RegisterInterrupt(func(os.Signal) { + gui.Stop() + }) utils.StartEthereum(ethereum, UseSeed) - - + // gui blocks the main thread + gui.Start(AssetPath) + // we need to run the interrupt callbacks in case gui is closed + // this skips if we got here by actual interrupt stopping the GUI + if !interrupted { + utils.RunInterruptCallbacks(os.Interrupt) + } + // this blocks the thread + ethereum.WaitForShutdown() + ethlog.Flush() } diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 8845f6af3..938037b90 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -37,6 +37,7 @@ type Gui struct { pub *ethpub.PEthereum logLevel ethlog.LogLevel + open bool } // Create GUI, but doesn't start it @@ -56,7 +57,7 @@ func New(ethereum *eth.Ethereum, logLevel int) *Gui { pub := ethpub.NewPEthereum(ethereum) - return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub, logLevel: ethlog.LogLevel(logLevel)} + return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub, logLevel: ethlog.LogLevel(logLevel), open: false} } func (gui *Gui) Start(assetPath string) { @@ -104,7 +105,7 @@ func (gui *Gui) Start(assetPath string) { } logger.Infoln("Starting GUI") - + gui.open = true win.Show() // only add the gui logger after window is shown otherwise slider wont be shown if addlog { @@ -113,7 +114,16 @@ func (gui *Gui) Start(assetPath string) { win.Wait() // need to silence gui logger after window closed otherwise logsystem hangs gui.SetLogLevel(ethlog.Silence) - gui.eth.Stop() + gui.open = false +} + +func (gui *Gui) Stop() { + if gui.open { + gui.SetLogLevel(ethlog.Silence) + gui.open = false + gui.win.Hide() + } + logger.Infoln("Stopped") } func (gui *Gui) ToggleMining() { -- cgit v1.2.3 From ae5ace16190d48bfe7a0364fdb0b51644518ec42 Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 26 Jun 2014 18:41:36 +0100 Subject: go fmt --- ethereal/flags.go | 14 +++++++------- ethereal/main.go | 32 ++++++++++++++++---------------- ethereal/ui/gui.go | 6 +++--- 3 files changed, 26 insertions(+), 26 deletions(-) (limited to 'ethereal') diff --git a/ethereal/flags.go b/ethereal/flags.go index 7e83e355f..9bed38d9f 100644 --- a/ethereal/flags.go +++ b/ethereal/flags.go @@ -1,13 +1,13 @@ package main import ( + "bitbucket.org/kardianos/osext" + "flag" "fmt" + "github.com/ethereum/eth-go/ethlog" "os" - "os/user" - "path" - "github.com/ethereum/eth-go/ethlog" - "flag" - "bitbucket.org/kardianos/osext" + "os/user" + "path" "path/filepath" "runtime" ) @@ -60,8 +60,8 @@ func defaultAssetPath() string { } func defaultDataDir() string { - usr, _ := user.Current() - return path.Join(usr.HomeDir, ".ethereal") + usr, _ := user.Current() + return path.Join(usr.HomeDir, ".ethereal") } var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini") diff --git a/ethereal/main.go b/ethereal/main.go index cfd85afe7..799b50e4b 100644 --- a/ethereal/main.go +++ b/ethereal/main.go @@ -1,12 +1,12 @@ package main import ( + "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/go-ethereum/ethereal/ui" "github.com/ethereum/go-ethereum/utils" - "github.com/ethereum/eth-go/ethlog" "github.com/go-qml/qml" - "runtime" "os" + "runtime" ) func main() { @@ -32,11 +32,11 @@ func main() { ethereum := utils.NewEthereum(UseUPnP, OutboundPort, MaxPeer) // create, import, export keys - utils.KeyTasks(GenAddr, ImportKey, ExportKey, NonInteractive) + utils.KeyTasks(GenAddr, ImportKey, ExportKey, NonInteractive) - if ShowGenesis { - utils.ShowGenesis(ethereum) - } + if ShowGenesis { + utils.ShowGenesis(ethereum) + } if StartRpc { utils.StartRpc(ethereum, RpcPort) @@ -45,17 +45,17 @@ func main() { gui := ethui.New(ethereum, LogLevel) utils.RegisterInterrupt(func(os.Signal) { - gui.Stop() - }) + gui.Stop() + }) utils.StartEthereum(ethereum, UseSeed) - // gui blocks the main thread - gui.Start(AssetPath) - // we need to run the interrupt callbacks in case gui is closed - // this skips if we got here by actual interrupt stopping the GUI + // gui blocks the main thread + gui.Start(AssetPath) + // we need to run the interrupt callbacks in case gui is closed + // this skips if we got here by actual interrupt stopping the GUI if !interrupted { utils.RunInterruptCallbacks(os.Interrupt) - } - // this blocks the thread - ethereum.WaitForShutdown() - ethlog.Flush() + } + // this blocks the thread + ethereum.WaitForShutdown() + ethlog.Flush() } diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 83b1508e9..be7b395d8 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -6,9 +6,9 @@ import ( "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethdb" + "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" - "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" "math/big" @@ -35,9 +35,9 @@ type Gui struct { addr []byte - pub *ethpub.PEthereum + pub *ethpub.PEthereum logLevel ethlog.LogLevel - open bool + open bool } // Create GUI, but doesn't start it -- cgit v1.2.3