github.com/jonasnick/go-ethereum@v0.7.12-0.20150216215225-22176f05d387/cmd/mist/main.go (about)

     1  /*
     2  	This file is part of go-ethereum
     3  
     4  	go-ethereum is free software: you can redistribute it and/or modify
     5  	it under the terms of the GNU General Public License as published by
     6  	the Free Software Foundation, either version 3 of the License, or
     7  	(at your option) any later version.
     8  
     9  	go-ethereum is distributed in the hope that it will be useful,
    10  	but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  	GNU General Public License for more details.
    13  
    14  	You should have received a copy of the GNU General Public License
    15  	along with go-ethereum.  If not, see <http://www.gnu.org/licenses/>.
    16  */
    17  /**
    18   * @authors
    19   * 	Jeffrey Wilcke <i@jev.io>
    20   */
    21  package main
    22  
    23  import (
    24  	"fmt"
    25  	"os"
    26  	"runtime"
    27  	"time"
    28  
    29  	"github.com/jonasnick/go-ethereum/cmd/utils"
    30  	"github.com/jonasnick/go-ethereum/eth"
    31  	"github.com/jonasnick/go-ethereum/logger"
    32  	"github.com/jonasnick/go-ethereum/p2p"
    33  	"github.com/jonasnick/go-ethereum/ui/qt/webengine"
    34  	"github.com/obscuren/qml"
    35  )
    36  
    37  const (
    38  	ClientIdentifier = "Mist"
    39  	Version          = "0.8.3"
    40  )
    41  
    42  var ethereum *eth.Ethereum
    43  var mainlogger = logger.NewLogger("MAIN")
    44  
    45  func run() error {
    46  	webengine.Initialize()
    47  
    48  	// precedence: code-internal flag default < config file < environment variables < command line
    49  	Init() // parsing command line
    50  
    51  	tstart := time.Now()
    52  	config := utils.InitConfig(VmType, ConfigFile, Datadir, "ETH")
    53  
    54  	ethereum, err := eth.New(&eth.Config{
    55  		Name:      p2p.MakeName(ClientIdentifier, Version),
    56  		KeyStore:  KeyStore,
    57  		DataDir:   Datadir,
    58  		LogFile:   LogFile,
    59  		LogLevel:  LogLevel,
    60  		MaxPeers:  MaxPeer,
    61  		Port:      OutboundPort,
    62  		NAT:       NAT,
    63  		BootNodes: BootNodes,
    64  		NodeKey:   NodeKey,
    65  		KeyRing:   KeyRing,
    66  		Dial:      true,
    67  	})
    68  	if err != nil {
    69  		mainlogger.Fatalln(err)
    70  	}
    71  	utils.KeyTasks(ethereum.KeyManager(), KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
    72  
    73  	if StartRpc {
    74  		utils.StartRpc(ethereum, RpcPort)
    75  	}
    76  
    77  	if StartWebSockets {
    78  		utils.StartWebSockets(ethereum, WsPort)
    79  	}
    80  
    81  	gui := NewWindow(ethereum, config, KeyRing, LogLevel)
    82  
    83  	utils.RegisterInterrupt(func(os.Signal) {
    84  		gui.Stop()
    85  	})
    86  	go utils.StartEthereum(ethereum)
    87  
    88  	fmt.Println("ETH stack took", time.Since(tstart))
    89  
    90  	// gui blocks the main thread
    91  	gui.Start(AssetPath)
    92  
    93  	return nil
    94  }
    95  
    96  func main() {
    97  	runtime.GOMAXPROCS(runtime.NumCPU())
    98  
    99  	// This is a bit of a cheat, but ey!
   100  	os.Setenv("QTWEBKIT_INSPECTOR_SERVER", "127.0.0.1:99999")
   101  
   102  	qml.Run(run)
   103  
   104  	var interrupted = false
   105  	utils.RegisterInterrupt(func(os.Signal) {
   106  		interrupted = true
   107  	})
   108  
   109  	utils.HandleInterrupt()
   110  
   111  	// we need to run the interrupt callbacks in case gui is closed
   112  	// this skips if we got here by actual interrupt stopping the GUI
   113  	if !interrupted {
   114  		utils.RunInterruptCallbacks(os.Interrupt)
   115  	}
   116  	logger.Flush()
   117  }