diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 971457aba..c56d31888 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -55,8 +55,8 @@ func InitLDBDatabase(ip string, port string, freshDB bool, isBeacon bool) (*ethd return ethdb.NewLDBDatabase(dbFileName, 0, 0) } -func printVersion(me string) { - fmt.Fprintf(os.Stderr, "Harmony (C) 2018. %v, version %v-%v (%v %v)\n", path.Base(me), version, commit, builtBy, builtAt) +func printVersion() { + fmt.Fprintln(os.Stderr, nodeconfig.GetVersion()) os.Exit(0) } @@ -432,8 +432,9 @@ func main() { flag.Var(&utils.BootNodes, "bootnodes", "a list of bootnode multiaddress (delimited by ,)") flag.Parse() + nodeconfig.SetVersion(fmt.Sprintf("Harmony (C) 2018. %v, version %v-%v (%v %v)", path.Base(os.Args[0]), version, commit, builtBy, builtAt)) if *versionFlag { - printVersion(os.Args[0]) + printVersion() } // If FN node running, they should either specify blsPrivateKey or the file with passphrase diff --git a/internal/configs/node/config.go b/internal/configs/node/config.go index 7ad2b340b..5425c2a76 100644 --- a/internal/configs/node/config.go +++ b/internal/configs/node/config.go @@ -74,6 +74,8 @@ const ( MaxShards = 32 // maximum number of shards. It is also the maxium number of configs. ) +var version string + // ConfigType is the structure of all node related configuration variables type ConfigType struct { // The three groupID design, please refer to https://github.com/harmony-one/harmony/blob/master/node/node.md#libp2p-integration @@ -230,3 +232,13 @@ func (conf *ConfigType) SetNetworkType(networkType NetworkType) { func (conf *ConfigType) GetNetworkType() NetworkType { return conf.networkType } + +// SetVersion set the version of the node binary +func SetVersion(ver string) { + version = ver +} + +// GetVersion return the version of the node binary +func GetVersion() string { + return version +}