1818package main
1919
2020import (
21+ "encoding/hex"
2122 "fmt"
2223 "io/ioutil"
2324 "os"
@@ -41,31 +42,48 @@ import (
4142 "github.com/ethereum/go-ethereum/metrics"
4243 "github.com/ethereum/go-ethereum/node"
4344 "github.com/ethereum/go-ethereum/params"
45+ "github.com/ethereum/go-ethereum/release"
4446 "github.com/ethereum/go-ethereum/rlp"
4547)
4648
4749const (
48- ClientIdentifier = "Geth"
49- Version = "1.5.0-unstable"
50- VersionMajor = 1
51- VersionMinor = 5
52- VersionPatch = 0
50+ clientIdentifier = "Geth" // Client identifier to advertise over the network
51+ versionMajor = 1 // Major version component of the current release
52+ versionMinor = 5 // Minor version component of the current release
53+ versionPatch = 0 // Patch version component of the current release
54+ versionMeta = "unstable" // Version metadata to append to the version string
55+
56+ versionOracle = "0x48a117313039b73ab02fb9f73e04a66defe123ec" // Ethereum address of the Geth release oracle
5357)
5458
5559var (
56- gitCommit string // set via linker flagg
57- nodeNameVersion string
58- app * cli.App
60+ gitCommit string // Git SHA1 commit hash of the release (set via linker flags)
61+ verString string // Combined textual representation of all the version components
62+ relConfig release.Config // Structured version information and release oracle config
63+ app * cli.App
5964)
6065
6166func init () {
62- if gitCommit == "" {
63- nodeNameVersion = Version
64- } else {
65- nodeNameVersion = Version + "-" + gitCommit [:8 ]
67+ // Construct the textual version string from the individual components
68+ verString = fmt .Sprintf ("%d.%d.%d" , versionMajor , versionMinor , versionPatch )
69+ if versionMeta != "" {
70+ verString += "-" + versionMeta
71+ }
72+ if gitCommit != "" {
73+ verString += "-" + gitCommit [:8 ]
6674 }
75+ // Construct the version release oracle configuration
76+ relConfig .Oracle = common .HexToAddress (versionOracle )
6777
68- app = utils .NewApp (Version , "the go-ethereum command line interface" )
78+ relConfig .Major = uint32 (versionMajor )
79+ relConfig .Minor = uint32 (versionMinor )
80+ relConfig .Patch = uint32 (versionPatch )
81+
82+ commit , _ := hex .DecodeString (gitCommit )
83+ copy (relConfig .Commit [:], commit )
84+
85+ // Initialize the CLI app and start Geth
86+ app = utils .NewApp (verString , "the go-ethereum command line interface" )
6987 app .Action = geth
7088 app .HideVersion = true // we have a command to print the version
7189 app .Commands = []cli.Command {
@@ -257,7 +275,7 @@ func makeDefaultExtra() []byte {
257275 Name string
258276 GoVersion string
259277 Os string
260- }{uint (VersionMajor << 16 | VersionMinor << 8 | VersionPatch ), ClientIdentifier , runtime .Version (), runtime .GOOS }
278+ }{uint (versionMajor << 16 | versionMinor << 8 | versionPatch ), clientIdentifier , runtime .Version (), runtime .GOOS }
261279 extra , err := rlp .EncodeToBytes (clientInfo )
262280 if err != nil {
263281 glog .V (logger .Warn ).Infoln ("error setting canonical miner information:" , err )
@@ -275,7 +293,7 @@ func makeDefaultExtra() []byte {
275293// It creates a default node based on the command line arguments and runs it in
276294// blocking mode, waiting for it to be shut down.
277295func geth (ctx * cli.Context ) {
278- node := utils .MakeSystemNode (ClientIdentifier , nodeNameVersion , makeDefaultExtra (), ctx )
296+ node := utils .MakeSystemNode (clientIdentifier , verString , relConfig , makeDefaultExtra (), ctx )
279297 startNode (ctx , node )
280298 node .Wait ()
281299}
@@ -339,7 +357,7 @@ func initGenesis(ctx *cli.Context) {
339357// same time.
340358func console (ctx * cli.Context ) {
341359 // Create and start the node based on the CLI flags
342- node := utils .MakeSystemNode (ClientIdentifier , nodeNameVersion , makeDefaultExtra (), ctx )
360+ node := utils .MakeSystemNode (clientIdentifier , verString , relConfig , makeDefaultExtra (), ctx )
343361 startNode (ctx , node )
344362
345363 // Attach to the newly started node, and either execute script or become interactive
@@ -372,7 +390,7 @@ func console(ctx *cli.Context) {
372390// of the JavaScript files specified as command arguments.
373391func execScripts (ctx * cli.Context ) {
374392 // Create and start the node based on the CLI flags
375- node := utils .MakeSystemNode (ClientIdentifier , nodeNameVersion , makeDefaultExtra (), ctx )
393+ node := utils .MakeSystemNode (clientIdentifier , verString , relConfig , makeDefaultExtra (), ctx )
376394 startNode (ctx , node )
377395 defer node .Stop ()
378396
@@ -488,11 +506,8 @@ func gpubench(ctx *cli.Context) {
488506}
489507
490508func version (c * cli.Context ) {
491- fmt .Println (ClientIdentifier )
492- fmt .Println ("Version:" , Version )
493- if gitCommit != "" {
494- fmt .Println ("Git Commit:" , gitCommit )
495- }
509+ fmt .Println (clientIdentifier )
510+ fmt .Println ("Version:" , version )
496511 fmt .Println ("Protocol Versions:" , eth .ProtocolVersions )
497512 fmt .Println ("Network Id:" , c .GlobalInt (utils .NetworkIdFlag .Name ))
498513 fmt .Println ("Go Version:" , runtime .Version ())
0 commit comments