good morning!!!!

Skip to content
Snippets Groups Projects
main.go 3.21 KiB
Newer Older
  • Learn to ignore specific revisions
  • Felix Lange's avatar
    Felix Lange committed
    // Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
    //
    // This library is free software; you can redistribute it and/or
    // modify it under the terms of the GNU General Public
    // License as published by the Free Software Foundation; either
    // version 2.1 of the License, or (at your option) any later version.
    //
    // This library is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    // General Public License for more details.
    //
    // You should have received a copy of the GNU General Public License
    // along with this library; if not, write to the Free Software
    // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    // MA 02110-1301  USA
    
    
    package main
    
    import (
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    	"fmt"
    	"os"
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    	"runtime"
    
    
    	"github.com/ethereum/go-ethereum/ethchain"
    	"github.com/ethereum/go-ethereum/ethlog"
    	"github.com/ethereum/go-ethereum/ethutil"
    
    Viktor Trón's avatar
    Viktor Trón committed
    	"github.com/ethereum/go-ethereum/utils"
    
    Viktor Trón's avatar
    Viktor Trón committed
    const (
    	ClientIdentifier = "Ethereum(G)"
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    	Version          = "0.7.0"
    
    var logger = ethlog.NewLogger("CLI")
    
    func main() {
    	runtime.GOMAXPROCS(runtime.NumCPU())
    
    
    	utils.HandleInterrupt()
    
    
    	// precedence: code-internal flag default < config file < environment variables < command line
    	Init() // parsing command line
    
    
    	// If the difftool option is selected ignore all other log output
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    	if DiffTool || Dump {
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    	utils.InitConfig(VmType, ConfigFile, Datadir, "ETH")
    
    	ethutil.Config.Diff = DiffTool
    
    	ethutil.Config.DiffType = DiffType
    
    
    	utils.InitDataDir(Datadir)
    
    	utils.InitLogging(Datadir, LogFile, LogLevel, DebugFile)
    
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    	err := utils.DBSanityCheck(db)
    	if err != nil {
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    		os.Exit(1)
    	}
    
    
    	keyManager := utils.NewKeyManager(KeyStore, Datadir, db)
    
    
    	// create, import, export keys
    
    	utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
    
    
    Viktor Trón's avatar
    Viktor Trón committed
    	clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier)
    
    	ethereum := utils.NewEthereum(db, clientIdentity, keyManager, UseUPnP, OutboundPort, MaxPeer)
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    	if Dump {
    		var block *ethchain.Block
    
    		if len(DumpHash) == 0 && DumpNumber == -1 {
    
    			block = ethereum.ChainManager().CurrentBlock
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    		} else if len(DumpHash) > 0 {
    
    			block = ethereum.ChainManager().GetBlock(ethutil.Hex2Bytes(DumpHash))
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    		} else {
    
    			block = ethereum.ChainManager().GetBlockByNumber(uint64(DumpNumber))
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    		}
    
    		if block == nil {
    			fmt.Fprintln(os.Stderr, "block not found")
    
    			// We want to output valid JSON
    			fmt.Println("{}")
    
    			os.Exit(1)
    		}
    
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    		fmt.Printf("RLP: %x\nstate: %x\nhash: %x\n", ethutil.Rlp(block), block.GetRoot(), block.Hash())
    
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    		// Leave the Println. This needs clean output for piping
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    		fmt.Printf("%s\n", block.State().Dump())
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    
    		os.Exit(0)
    	}
    
    
    Viktor Trón's avatar
    Viktor Trón committed
    	if ShowGenesis {
    		utils.ShowGenesis(ethereum)
    	}
    
    
    	if StartMining {
    		utils.StartMining(ethereum)
    	}
    
    	// better reworked as cases
    	if StartJsConsole {
    		InitJsConsole(ethereum)
    	} else if len(InputFile) > 0 {
    		ExecJsFile(ethereum, InputFile)
    	}
    
    	if StartRpc {
    		utils.StartRpc(ethereum, RpcPort)
    	}
    
    
    Jeffrey Wilcke's avatar
    Jeffrey Wilcke committed
    	if StartWebSockets {
    		utils.StartWebSockets(ethereum)
    	}
    
    
    	utils.StartEthereum(ethereum, UseSeed)
    
    Viktor Trón's avatar
    Viktor Trón committed
    
    	// this blocks the thread
    
    Viktor Trón's avatar
    Viktor Trón committed
    	ethereum.WaitForShutdown()
    	ethlog.Flush()