aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils/flags.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-29 00:01:40 +0800
committerobscuren <geffobscura@gmail.com>2015-05-29 00:01:40 +0800
commitf082c1b8959c1c729a4b62d6ff101d7569e8ba0f (patch)
treed19fdc2e8982a64d93612677dc2722dd41c8dbd3 /cmd/utils/flags.go
parent70867904a0255bd044851585a9ad2dc34391ced2 (diff)
parentd51d74eb55535db7670ad336d186ea64c6a2ff81 (diff)
downloaddexon-f082c1b8959c1c729a4b62d6ff101d7569e8ba0f.tar
dexon-f082c1b8959c1c729a4b62d6ff101d7569e8ba0f.tar.gz
dexon-f082c1b8959c1c729a4b62d6ff101d7569e8ba0f.tar.bz2
dexon-f082c1b8959c1c729a4b62d6ff101d7569e8ba0f.tar.lz
dexon-f082c1b8959c1c729a4b62d6ff101d7569e8ba0f.tar.xz
dexon-f082c1b8959c1c729a4b62d6ff101d7569e8ba0f.tar.zst
dexon-f082c1b8959c1c729a4b62d6ff101d7569e8ba0f.zip
Merge branch 'release/0.9.26'
Diffstat (limited to 'cmd/utils/flags.go')
-rw-r--r--cmd/utils/flags.go61
1 files changed, 29 insertions, 32 deletions
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 155110ddc..d319055b1 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -256,7 +256,8 @@ var (
}
)
-func GetNAT(ctx *cli.Context) nat.Interface {
+// MakeNAT creates a port mapper from set command line flags.
+func MakeNAT(ctx *cli.Context) nat.Interface {
natif, err := nat.Parse(ctx.GlobalString(NATFlag.Name))
if err != nil {
Fatalf("Option %s: %v", NATFlag.Name, err)
@@ -264,7 +265,8 @@ func GetNAT(ctx *cli.Context) nat.Interface {
return natif
}
-func GetNodeKey(ctx *cli.Context) (key *ecdsa.PrivateKey) {
+// MakeNodeKey creates a node key from set command line flags.
+func MakeNodeKey(ctx *cli.Context) (key *ecdsa.PrivateKey) {
hex, file := ctx.GlobalString(NodeKeyHexFlag.Name), ctx.GlobalString(NodeKeyFileFlag.Name)
var err error
switch {
@@ -282,21 +284,12 @@ func GetNodeKey(ctx *cli.Context) (key *ecdsa.PrivateKey) {
return key
}
+// MakeEthConfig creates ethereum options from set command line flags.
func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
- // Set verbosity on glog
- glog.SetV(ctx.GlobalInt(VerbosityFlag.Name))
- glog.CopyStandardLogTo("INFO")
- // Set the log type
- //glog.SetToStderr(ctx.GlobalBool(LogToStdErrFlag.Name))
- glog.SetToStderr(true)
- // Set the log dir
- glog.SetLogDir(ctx.GlobalString(LogFileFlag.Name))
-
customName := ctx.GlobalString(IdentityFlag.Name)
if len(customName) > 0 {
clientID += "/" + customName
}
-
return &eth.Config{
Name: common.MakeName(clientID, version),
DataDir: ctx.GlobalString(DataDirFlag.Name),
@@ -309,15 +302,15 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
LogJSON: ctx.GlobalString(LogJSONFlag.Name),
Etherbase: ctx.GlobalString(EtherbaseFlag.Name),
MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name),
- AccountManager: GetAccountManager(ctx),
+ AccountManager: MakeAccountManager(ctx),
VmDebug: ctx.GlobalBool(VMDebugFlag.Name),
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name),
Port: ctx.GlobalString(ListenPortFlag.Name),
- NAT: GetNAT(ctx),
+ NAT: MakeNAT(ctx),
NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name),
Discovery: !ctx.GlobalBool(NoDiscoverFlag.Name),
- NodeKey: GetNodeKey(ctx),
+ NodeKey: MakeNodeKey(ctx),
Shh: ctx.GlobalBool(WhisperEnabledFlag.Name),
Dial: true,
BootNodes: ctx.GlobalString(BootnodesFlag.Name),
@@ -327,35 +320,39 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
}
}
-func GetChain(ctx *cli.Context) (*core.ChainManager, common.Database, common.Database) {
- dataDir := ctx.GlobalString(DataDirFlag.Name)
+// SetupLogger configures glog from the logging-related command line flags.
+func SetupLogger(ctx *cli.Context) {
+ glog.SetV(ctx.GlobalInt(VerbosityFlag.Name))
+ glog.CopyStandardLogTo("INFO")
+ glog.SetToStderr(true)
+ glog.SetLogDir(ctx.GlobalString(LogFileFlag.Name))
+}
- blockDb, err := ethdb.NewLDBDatabase(filepath.Join(dataDir, "blockchain"))
- if err != nil {
+// MakeChain creates a chain manager from set command line flags.
+func MakeChain(ctx *cli.Context) (chain *core.ChainManager, blockDB, stateDB, extraDB common.Database) {
+ dd := ctx.GlobalString(DataDirFlag.Name)
+ var err error
+ if blockDB, err = ethdb.NewLDBDatabase(filepath.Join(dd, "blockchain")); err != nil {
Fatalf("Could not open database: %v", err)
}
-
- stateDb, err := ethdb.NewLDBDatabase(filepath.Join(dataDir, "state"))
- if err != nil {
+ if stateDB, err = ethdb.NewLDBDatabase(filepath.Join(dd, "state")); err != nil {
Fatalf("Could not open database: %v", err)
}
-
- extraDb, err := ethdb.NewLDBDatabase(filepath.Join(dataDir, "extra"))
- if err != nil {
+ if extraDB, err = ethdb.NewLDBDatabase(filepath.Join(dd, "extra")); err != nil {
Fatalf("Could not open database: %v", err)
}
eventMux := new(event.TypeMux)
pow := ethash.New()
- chainManager := core.NewChainManager(blockDb, stateDb, pow, eventMux)
- txPool := core.NewTxPool(eventMux, chainManager.State, chainManager.GasLimit)
- blockProcessor := core.NewBlockProcessor(stateDb, extraDb, pow, txPool, chainManager, eventMux)
- chainManager.SetProcessor(blockProcessor)
-
- return chainManager, blockDb, stateDb
+ chain = core.NewChainManager(blockDB, stateDB, pow, eventMux)
+ txpool := core.NewTxPool(eventMux, chain.State, chain.GasLimit)
+ proc := core.NewBlockProcessor(stateDB, extraDB, pow, txpool, chain, eventMux)
+ chain.SetProcessor(proc)
+ return chain, blockDB, stateDB, extraDB
}
-func GetAccountManager(ctx *cli.Context) *accounts.Manager {
+// MakeChain creates an account manager from set command line flags.
+func MakeAccountManager(ctx *cli.Context) *accounts.Manager {
dataDir := ctx.GlobalString(DataDirFlag.Name)
ks := crypto.NewKeyStorePassphrase(filepath.Join(dataDir, "keystore"))
return accounts.NewManager(ks)