diff options
author | Felix Lange <fjl@twurst.com> | 2016-09-05 19:08:41 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-09-05 19:24:11 +0800 |
commit | 6b727c0440f79d12ba38f6c21f50d33b84aeaa83 (patch) | |
tree | 35c813b93218b19847e6d9e7e588377daad2c9a7 /cmd/geth | |
parent | 2c6be49d200a3fff660ad78aada3305f8a3e3b9a (diff) | |
download | dexon-6b727c0440f79d12ba38f6c21f50d33b84aeaa83.tar dexon-6b727c0440f79d12ba38f6c21f50d33b84aeaa83.tar.gz dexon-6b727c0440f79d12ba38f6c21f50d33b84aeaa83.tar.bz2 dexon-6b727c0440f79d12ba38f6c21f50d33b84aeaa83.tar.lz dexon-6b727c0440f79d12ba38f6c21f50d33b84aeaa83.tar.xz dexon-6b727c0440f79d12ba38f6c21f50d33b84aeaa83.tar.zst dexon-6b727c0440f79d12ba38f6c21f50d33b84aeaa83.zip |
cmd/evm, cmd/geth, cmd/utils: move version handling to cmd/utils
Diffstat (limited to 'cmd/geth')
-rw-r--r-- | cmd/geth/accountcmd.go | 10 | ||||
-rw-r--r-- | cmd/geth/consolecmd_test.go | 5 | ||||
-rw-r--r-- | cmd/geth/main.go | 86 |
3 files changed, 39 insertions, 62 deletions
diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index 2069df6cd..2d70dcc2c 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -168,7 +168,7 @@ nodes. ) func accountList(ctx *cli.Context) error { - stack := utils.MakeNode(ctx, clientIdentifier, verString) + stack := utils.MakeNode(ctx, clientIdentifier, gitCommit) for i, acct := range stack.AccountManager().Accounts() { fmt.Printf("Account #%d: {%x} %s\n", i, acct.Address, acct.File) } @@ -261,7 +261,7 @@ 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 { - stack := utils.MakeNode(ctx, clientIdentifier, verString) + stack := utils.MakeNode(ctx, clientIdentifier, gitCommit) 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 := stack.AccountManager().NewAccount(password) @@ -278,7 +278,7 @@ func accountUpdate(ctx *cli.Context) error { if len(ctx.Args()) == 0 { utils.Fatalf("No accounts specified to update") } - stack := utils.MakeNode(ctx, clientIdentifier, verString) + stack := utils.MakeNode(ctx, clientIdentifier, gitCommit) 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 := stack.AccountManager().Update(account, oldPassword, newPassword); err != nil { @@ -297,7 +297,7 @@ func importWallet(ctx *cli.Context) error { utils.Fatalf("Could not read wallet file: %v", err) } - stack := utils.MakeNode(ctx, clientIdentifier, verString) + stack := utils.MakeNode(ctx, clientIdentifier, gitCommit) passphrase := getPassPhrase("", false, 0, utils.MakePasswordList(ctx)) acct, err := stack.AccountManager().ImportPreSaleKey(keyJson, passphrase) if err != nil { @@ -316,7 +316,7 @@ func accountImport(ctx *cli.Context) error { if err != nil { utils.Fatalf("Failed to load the private key: %v", err) } - stack := utils.MakeNode(ctx, clientIdentifier, verString) + stack := utils.MakeNode(ctx, clientIdentifier, gitCommit) 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 := stack.AccountManager().ImportECDSA(key, passphrase) if err != nil { diff --git a/cmd/geth/consolecmd_test.go b/cmd/geth/consolecmd_test.go index e0e549e12..3f09c0414 100644 --- a/cmd/geth/consolecmd_test.go +++ b/cmd/geth/consolecmd_test.go @@ -28,6 +28,7 @@ import ( "testing" "time" + "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/rpc" ) @@ -45,7 +46,7 @@ func TestConsoleWelcome(t *testing.T) { // Gather all the infos the welcome message needs to contain geth.setTemplateFunc("goos", func() string { return runtime.GOOS }) geth.setTemplateFunc("gover", runtime.Version) - geth.setTemplateFunc("gethver", func() string { return verString }) + geth.setTemplateFunc("gethver", func() string { return utils.Version }) geth.setTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) }) geth.setTemplateFunc("apis", func() []string { apis := append(strings.Split(rpc.DefaultIPCApis, ","), rpc.MetadataApi) @@ -131,7 +132,7 @@ func testAttachWelcome(t *testing.T, geth *testgeth, endpoint string) { // Gather all the infos the welcome message needs to contain attach.setTemplateFunc("goos", func() string { return runtime.GOOS }) attach.setTemplateFunc("gover", runtime.Version) - attach.setTemplateFunc("gethver", func() string { return verString }) + attach.setTemplateFunc("gethver", func() string { return utils.Version }) attach.setTemplateFunc("etherbase", func() string { return geth.Etherbase }) attach.setTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) }) attach.setTemplateFunc("ipc", func() bool { return strings.HasPrefix(endpoint, "ipc") }) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 82eae244d..b5e454d87 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -42,49 +42,24 @@ import ( "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/node" - "github.com/ethereum/go-ethereum/params" - "github.com/ethereum/go-ethereum/rlp" "gopkg.in/urfave/cli.v1" ) const ( - clientIdentifier = "Geth" // Client identifier to advertise over the network - versionMajor = 1 // Major version component of the current release - versionMinor = 5 // Minor version component of the current release - versionPatch = 0 // Patch version component of the current release - versionMeta = "unstable" // Version metadata to append to the version string - - versionOracle = "0xfa7b9770ca4cb04296cac84f37736d4041251cdf" // Ethereum address of the Geth release oracle + clientIdentifier = "Geth" // Client identifier to advertise over the network ) var ( - gitCommit string // Git SHA1 commit hash of the release (set via linker flags) - verString string // Combined textual representation of all the version components - relConfig release.Config // Structured version information and release oracle config - app *cli.App + // Git SHA1 commit hash of the release (set via linker flags) + gitCommit = "" + // Ethereum address of the Geth release oracle. + relOracle = common.HexToAddress("0xfa7b9770ca4cb04296cac84f37736d4041251cdf") + // The app that holds all commands and flags. + app = utils.NewApp(gitCommit, "the go-ethereum command line interface") ) func init() { - // Construct the textual version string from the individual components - verString = fmt.Sprintf("%d.%d.%d", versionMajor, versionMinor, versionPatch) - if versionMeta != "" { - verString += "-" + versionMeta - } - if gitCommit != "" { - verString += "-" + gitCommit[:8] - } - // Construct the version release oracle configuration - relConfig.Oracle = common.HexToAddress(versionOracle) - - relConfig.Major = uint32(versionMajor) - relConfig.Minor = uint32(versionMinor) - relConfig.Patch = uint32(versionPatch) - - commit, _ := hex.DecodeString(gitCommit) - copy(relConfig.Commit[:], commit) - // Initialize the CLI app and start Geth - app = utils.NewApp(verString, "the go-ethereum command line interface") app.Action = geth app.HideVersion = true // we have a command to print the version app.Commands = []cli.Command{ @@ -290,35 +265,32 @@ func initGenesis(ctx *cli.Context) error { } func makeFullNode(ctx *cli.Context) *node.Node { - node := utils.MakeNode(ctx, clientIdentifier, verString) - utils.RegisterEthService(ctx, node, relConfig, makeDefaultExtra()) + stack := utils.MakeNode(ctx, clientIdentifier, gitCommit) + utils.RegisterEthService(ctx, stack, utils.MakeDefaultExtraData(clientIdentifier)) + // 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) + utils.RegisterShhService(stack) } - 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) + // Add the release oracle service so it boots along with node. + if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { + config := release.Config{ + Oracle: relOracle, + Major: uint32(utils.VersionMajor), + Minor: uint32(utils.VersionMinor), + Patch: uint32(utils.VersionPatch), + } + commit, _ := hex.DecodeString(gitCommit) + copy(config.Commit[:], commit) + return release.NewReleaseService(ctx, config) + }); err != nil { + utils.Fatalf("Failed to register the Geth release oracle service: %v", 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 + return stack } // startNode boots up the system node and all registered protocols, after which @@ -326,7 +298,8 @@ func makeDefaultExtra() []byte { // miner. func startNode(ctx *cli.Context, stack *node.Node) { // Report geth version - glog.V(logger.Info).Infof("instance: Geth/%s/%s/%s\n", verString, runtime.Version(), runtime.GOOS) + glog.V(logger.Info).Infof("instance: Geth/%s/%s/%s\n", utils.Version, runtime.Version(), runtime.GOOS) + // Start up the node itself utils.StartNode(stack) @@ -408,7 +381,10 @@ func gpubench(ctx *cli.Context) error { func version(c *cli.Context) error { fmt.Println(clientIdentifier) - fmt.Println("Version:", verString) + fmt.Println("Version:", utils.Version) + if gitCommit != "" { + fmt.Println("Git Commit:", gitCommit) + } fmt.Println("Protocol Versions:", eth.ProtocolVersions) fmt.Println("Network Id:", c.GlobalInt(utils.NetworkIdFlag.Name)) fmt.Println("Go Version:", runtime.Version()) |