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/main.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 ethereal/main.go (limited to 'ethereal/main.go') 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) +} -- 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/main.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'ethereal/main.go') 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) } -- 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/main.go') 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 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 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'ethereal/main.go') 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() } -- 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/main.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'ethereal/main.go') 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() } -- cgit v1.2.3