aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-08-18 02:59:59 +0800
committerGitHub <noreply@github.com>2016-08-18 02:59:59 +0800
commit475521dd747070372f84c2b0ac202e14216dc0e0 (patch)
treee97fb7892b21c503a7661578df0ff5a1f6d8e29c /cmd/geth
parent3369783e0a3e0c06388cf59fddfd799811381a2b (diff)
parent3c09c5f12d21258865677cf565bb9d53a8098d3a (diff)
downloadgo-tangerine-475521dd747070372f84c2b0ac202e14216dc0e0.tar
go-tangerine-475521dd747070372f84c2b0ac202e14216dc0e0.tar.gz
go-tangerine-475521dd747070372f84c2b0ac202e14216dc0e0.tar.bz2
go-tangerine-475521dd747070372f84c2b0ac202e14216dc0e0.tar.lz
go-tangerine-475521dd747070372f84c2b0ac202e14216dc0e0.tar.xz
go-tangerine-475521dd747070372f84c2b0ac202e14216dc0e0.tar.zst
go-tangerine-475521dd747070372f84c2b0ac202e14216dc0e0.zip
Merge pull request #2909 from fjl/account-manager-cleanup
all: clean up tech debt left behind by the API split
Diffstat (limited to 'cmd/geth')
-rw-r--r--cmd/geth/accountcmd.go24
-rw-r--r--cmd/geth/consolecmd.go4
-rw-r--r--cmd/geth/main.go62
3 files changed, 47 insertions, 43 deletions
diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go
index 7fea16a25..2069df6cd 100644
--- a/cmd/geth/accountcmd.go
+++ b/cmd/geth/accountcmd.go
@@ -168,8 +168,8 @@ nodes.
)
func accountList(ctx *cli.Context) error {
- accman := utils.MakeAccountManager(ctx)
- for i, acct := range accman.Accounts() {
+ stack := utils.MakeNode(ctx, clientIdentifier, verString)
+ for i, acct := range stack.AccountManager().Accounts() {
fmt.Printf("Account #%d: {%x} %s\n", i, acct.Address, acct.File)
}
return nil
@@ -261,10 +261,10 @@ func ambiguousAddrRecovery(am *accounts.Manager, err *accounts.AmbiguousAddrErro
// accountCreate creates a new account into the keystore defined by the CLI flags.
func accountCreate(ctx *cli.Context) error {
- accman := utils.MakeAccountManager(ctx)
+ stack := utils.MakeNode(ctx, clientIdentifier, verString)
password := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx))
- account, err := accman.NewAccount(password)
+ account, err := stack.AccountManager().NewAccount(password)
if err != nil {
utils.Fatalf("Failed to create account: %v", err)
}
@@ -278,11 +278,10 @@ func accountUpdate(ctx *cli.Context) error {
if len(ctx.Args()) == 0 {
utils.Fatalf("No accounts specified to update")
}
- accman := utils.MakeAccountManager(ctx)
-
- account, oldPassword := unlockAccount(ctx, accman, ctx.Args().First(), 0, nil)
+ stack := utils.MakeNode(ctx, clientIdentifier, verString)
+ account, oldPassword := unlockAccount(ctx, stack.AccountManager(), ctx.Args().First(), 0, nil)
newPassword := getPassPhrase("Please give a new password. Do not forget this password.", true, 0, nil)
- if err := accman.Update(account, oldPassword, newPassword); err != nil {
+ if err := stack.AccountManager().Update(account, oldPassword, newPassword); err != nil {
utils.Fatalf("Could not update the account: %v", err)
}
return nil
@@ -298,10 +297,9 @@ func importWallet(ctx *cli.Context) error {
utils.Fatalf("Could not read wallet file: %v", err)
}
- accman := utils.MakeAccountManager(ctx)
+ stack := utils.MakeNode(ctx, clientIdentifier, verString)
passphrase := getPassPhrase("", false, 0, utils.MakePasswordList(ctx))
-
- acct, err := accman.ImportPreSaleKey(keyJson, passphrase)
+ acct, err := stack.AccountManager().ImportPreSaleKey(keyJson, passphrase)
if err != nil {
utils.Fatalf("%v", err)
}
@@ -318,9 +316,9 @@ func accountImport(ctx *cli.Context) error {
if err != nil {
utils.Fatalf("Failed to load the private key: %v", err)
}
- accman := utils.MakeAccountManager(ctx)
+ stack := utils.MakeNode(ctx, clientIdentifier, verString)
passphrase := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx))
- acct, err := accman.ImportECDSA(key, passphrase)
+ acct, err := stack.AccountManager().ImportECDSA(key, passphrase)
if err != nil {
utils.Fatalf("Could not create the account: %v", err)
}
diff --git a/cmd/geth/consolecmd.go b/cmd/geth/consolecmd.go
index 8d53809ce..92d6f7f86 100644
--- a/cmd/geth/consolecmd.go
+++ b/cmd/geth/consolecmd.go
@@ -65,7 +65,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
// same time.
func localConsole(ctx *cli.Context) error {
// Create and start the node based on the CLI flags
- node := utils.MakeSystemNode(clientIdentifier, verString, relConfig, makeDefaultExtra(), ctx)
+ node := makeFullNode(ctx)
startNode(ctx, node)
defer node.Stop()
@@ -149,7 +149,7 @@ func dialRPC(endpoint string) (*rpc.Client, error) {
// everything down.
func ephemeralConsole(ctx *cli.Context) error {
// Create and start the node based on the CLI flags
- node := utils.MakeSystemNode(clientIdentifier, verString, relConfig, makeDefaultExtra(), ctx)
+ node := makeFullNode(ctx)
startNode(ctx, node)
defer node.Stop()
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 5f1157b90..de679ccca 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -29,7 +29,6 @@ import (
"time"
"github.com/ethereum/ethash"
- "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/console"
@@ -244,34 +243,13 @@ func main() {
}
}
-func makeDefaultExtra() []byte {
- var clientInfo = struct {
- Version uint
- Name string
- GoVersion string
- Os string
- }{uint(versionMajor<<16 | versionMinor<<8 | versionPatch), clientIdentifier, runtime.Version(), runtime.GOOS}
- extra, err := rlp.EncodeToBytes(clientInfo)
- if err != nil {
- glog.V(logger.Warn).Infoln("error setting canonical miner information:", err)
- }
-
- if uint64(len(extra)) > params.MaximumExtraDataSize.Uint64() {
- glog.V(logger.Warn).Infoln("error setting canonical miner information: extra exceeds", params.MaximumExtraDataSize)
- glog.V(logger.Debug).Infof("extra: %x\n", extra)
- return nil
- }
- return extra
-}
-
// geth is the main entry point into the system if no special subcommand is ran.
// It creates a default node based on the command line arguments and runs it in
// blocking mode, waiting for it to be shut down.
func geth(ctx *cli.Context) error {
- node := utils.MakeSystemNode(clientIdentifier, verString, relConfig, makeDefaultExtra(), ctx)
+ node := makeFullNode(ctx)
startNode(ctx, node)
node.Wait()
-
return nil
}
@@ -301,6 +279,38 @@ func initGenesis(ctx *cli.Context) error {
return nil
}
+func makeFullNode(ctx *cli.Context) *node.Node {
+ node := utils.MakeNode(ctx, clientIdentifier, verString)
+ utils.RegisterEthService(ctx, node, relConfig, makeDefaultExtra())
+ // Whisper must be explicitly enabled, but is auto-enabled in --dev mode.
+ shhEnabled := ctx.GlobalBool(utils.WhisperEnabledFlag.Name)
+ shhAutoEnabled := !ctx.GlobalIsSet(utils.WhisperEnabledFlag.Name) && ctx.GlobalIsSet(utils.DevModeFlag.Name)
+ if shhEnabled || shhAutoEnabled {
+ utils.RegisterShhService(node)
+ }
+ return node
+}
+
+func makeDefaultExtra() []byte {
+ var clientInfo = struct {
+ Version uint
+ Name string
+ GoVersion string
+ Os string
+ }{uint(versionMajor<<16 | versionMinor<<8 | versionPatch), clientIdentifier, runtime.Version(), runtime.GOOS}
+ extra, err := rlp.EncodeToBytes(clientInfo)
+ if err != nil {
+ glog.V(logger.Warn).Infoln("error setting canonical miner information:", err)
+ }
+
+ if uint64(len(extra)) > params.MaximumExtraDataSize.Uint64() {
+ glog.V(logger.Warn).Infoln("error setting canonical miner information: extra exceeds", params.MaximumExtraDataSize)
+ glog.V(logger.Debug).Infof("extra: %x\n", extra)
+ return nil
+ }
+ return extra
+}
+
// startNode boots up the system node and all registered protocols, after which
// it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
// miner.
@@ -311,12 +321,8 @@ func startNode(ctx *cli.Context, stack *node.Node) {
utils.StartNode(stack)
// Unlock any account specifically requested
- var accman *accounts.Manager
- if err := stack.Service(&accman); err != nil {
- utils.Fatalf("ethereum service not running: %v", err)
- }
+ accman := stack.AccountManager()
passwords := utils.MakePasswordList(ctx)
-
accounts := strings.Split(ctx.GlobalString(utils.UnlockedAccountFlag.Name), ",")
for i, account := range accounts {
if trimmed := strings.TrimSpace(account); trimmed != "" {