cmd/utils: GetEthereum -> MakeEthConfig

This allows changing the config before starting Ethereum
with it.
This commit is contained in:
Felix Lange 2015-03-13 18:30:45 +01:00
parent a80be98f31
commit 58d9d98daf
3 changed files with 16 additions and 12 deletions

View File

@ -156,24 +156,26 @@ func main() {
func run(ctx *cli.Context) { func run(ctx *cli.Context) {
fmt.Printf("Welcome to the FRONTIER\n") fmt.Printf("Welcome to the FRONTIER\n")
utils.HandleInterrupt() utils.HandleInterrupt()
eth, err := utils.GetEthereum(ClientIdentifier, Version, ctx) cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
ethereum, err := eth.New(cfg)
if err != nil { if err != nil {
utils.Fatalf("%v", err) utils.Fatalf("%v", err)
} }
startEth(ctx, eth) startEth(ctx, ethereum)
// this blocks the thread // this blocks the thread
eth.WaitForShutdown() ethereum.WaitForShutdown()
} }
func runjs(ctx *cli.Context) { func runjs(ctx *cli.Context) {
eth, err := utils.GetEthereum(ClientIdentifier, Version, ctx) cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
ethereum, err := eth.New(cfg)
if err != nil { if err != nil {
utils.Fatalf("%v", err) utils.Fatalf("%v", err)
} }
startEth(ctx, eth) startEth(ctx, ethereum)
repl := newJSRE(eth) repl := newJSRE(ethereum)
if len(ctx.Args()) == 0 { if len(ctx.Args()) == 0 {
repl.interactive() repl.interactive()
} else { } else {
@ -181,8 +183,8 @@ func runjs(ctx *cli.Context) {
repl.exec(file) repl.exec(file)
} }
} }
eth.Stop() ethereum.Stop()
eth.WaitForShutdown() ethereum.WaitForShutdown()
} }
func startEth(ctx *cli.Context, eth *eth.Ethereum) { func startEth(ctx *cli.Context, eth *eth.Ethereum) {

View File

@ -28,6 +28,7 @@ import (
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/ui/qt/webengine" "github.com/ethereum/go-ethereum/ui/qt/webengine"
@ -95,7 +96,8 @@ func run(ctx *cli.Context) {
tstart := time.Now() tstart := time.Now()
// TODO: show qml popup instead of exiting if initialization fails. // TODO: show qml popup instead of exiting if initialization fails.
ethereum, err := utils.GetEthereum(ClientIdentifier, Version, ctx) cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
ethereum, err := eth.New(cfg)
if err != nil { if err != nil {
utils.Fatalf("%v", err) utils.Fatalf("%v", err)
} }

View File

@ -192,8 +192,8 @@ func GetNodeKey(ctx *cli.Context) (key *ecdsa.PrivateKey) {
return key return key
} }
func GetEthereum(clientID, version string, ctx *cli.Context) (*eth.Ethereum, error) { func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
return eth.New(&eth.Config{ return &eth.Config{
Name: p2p.MakeName(clientID, version), Name: p2p.MakeName(clientID, version),
DataDir: ctx.GlobalString(DataDirFlag.Name), DataDir: ctx.GlobalString(DataDirFlag.Name),
LogFile: ctx.GlobalString(LogFileFlag.Name), LogFile: ctx.GlobalString(LogFileFlag.Name),
@ -209,7 +209,7 @@ func GetEthereum(clientID, version string, ctx *cli.Context) (*eth.Ethereum, err
Shh: true, Shh: true,
Dial: true, Dial: true,
BootNodes: ctx.GlobalString(BootnodesFlag.Name), BootNodes: ctx.GlobalString(BootnodesFlag.Name),
}) }
} }
func GetChain(ctx *cli.Context) (*core.ChainManager, ethutil.Database, ethutil.Database) { func GetChain(ctx *cli.Context) (*core.ChainManager, ethutil.Database, ethutil.Database) {