diff --git a/cmd/lbcctl/config.go b/cmd/lbcctl/config.go index ef961df9..e31ecef6 100644 --- a/cmd/lbcctl/config.go +++ b/cmd/lbcctl/config.go @@ -16,6 +16,7 @@ import ( flags "github.com/jessevdk/go-flags" "github.com/lbryio/lbcd/btcjson" "github.com/lbryio/lbcd/chaincfg" + "github.com/lbryio/lbcd/version" btcutil "github.com/lbryio/lbcutil" ) @@ -214,7 +215,7 @@ func loadConfig() (*config, []string, error) { appName = strings.TrimSuffix(appName, filepath.Ext(appName)) usageMessage := fmt.Sprintf("Use %s -h to show options", appName) if preCfg.ShowVersion { - fmt.Println(appName, "version", version()) + fmt.Println(appName, "version", version.Full()) os.Exit(0) } diff --git a/cmd/lbcctl/version.go b/cmd/lbcctl/version.go deleted file mode 100644 index fcd70ce4..00000000 --- a/cmd/lbcctl/version.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2013 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -package main - -import ( - "bytes" - "fmt" - "strings" -) - -// semanticAlphabet -const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-" - -// These constants define the application version and follow the semantic -// versioning 2.0.0 spec (http://semver.org/). -const ( - appMajor uint = 0 - appMinor uint = 22 - appPatch uint = 100 - - // appPreRelease MUST only contain characters from semanticAlphabet - // per the semantic versioning spec. - appPreRelease = "beta" -) - -// appBuild is defined as a variable so it can be overridden during the build -// process with '-ldflags "-X main.appBuild foo' if needed. It MUST only -// contain characters from semanticAlphabet per the semantic versioning spec. -var appBuild string - -// version returns the application version as a properly formed string per the -// semantic versioning 2.0.0 spec (http://semver.org/). -func version() string { - // Start with the major, minor, and patch versions. - version := fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch) - - // Append pre-release version if there is one. The hyphen called for - // by the semantic versioning spec is automatically appended and should - // not be contained in the pre-release string. The pre-release version - // is not appended if it contains invalid characters. - preRelease := normalizeVerString(appPreRelease) - if preRelease != "" { - version = fmt.Sprintf("%s-%s", version, preRelease) - } - - // Append build metadata if there is any. The plus called for - // by the semantic versioning spec is automatically appended and should - // not be contained in the build metadata string. The build metadata - // string is not appended if it contains invalid characters. - build := normalizeVerString(appBuild) - if build != "" { - version = fmt.Sprintf("%s+%s", version, build) - } - - return version -} - -// normalizeVerString returns the passed string stripped of all characters which -// are not valid according to the semantic versioning guidelines for pre-release -// version and build metadata strings. In particular they MUST only contain -// characters in semanticAlphabet. -func normalizeVerString(str string) string { - var result bytes.Buffer - for _, r := range str { - if strings.ContainsRune(semanticAlphabet, r) { - // Ignoring the error here since it can only fail if - // the the system is out of memory and there are much - // bigger issues at that point. - _, _ = result.WriteRune(r) - } - } - return result.String() -} diff --git a/config.go b/config.go index 93e83e9b..fe77a818 100644 --- a/config.go +++ b/config.go @@ -32,6 +32,7 @@ import ( _ "github.com/lbryio/lbcd/database/ffldb" "github.com/lbryio/lbcd/mempool" "github.com/lbryio/lbcd/peer" + "github.com/lbryio/lbcd/version" "github.com/lbryio/lbcd/wire" btcutil "github.com/lbryio/lbcutil" ) @@ -469,7 +470,7 @@ func loadConfig() (*config, []string, error) { appName = strings.TrimSuffix(appName, filepath.Ext(appName)) usageMessage := fmt.Sprintf("Use %s -h to show usage", appName) if preCfg.ShowVersion { - fmt.Println(appName, "version", version()) + fmt.Println(appName, "version", version.Full()) os.Exit(0) } diff --git a/lbcd.go b/lbcd.go index e47efdb8..1110eeab 100644 --- a/lbcd.go +++ b/lbcd.go @@ -19,6 +19,7 @@ import ( "github.com/lbryio/lbcd/claimtrie/param" "github.com/lbryio/lbcd/database" "github.com/lbryio/lbcd/limits" + "github.com/lbryio/lbcd/version" "github.com/felixge/fgprof" ) @@ -64,7 +65,7 @@ func btcdMain(serverChan chan<- *server) error { defer btcdLog.Info("Shutdown complete") // Show version at startup. - btcdLog.Infof("Version %s", version()) + btcdLog.Infof("Version %s", version.Full()) // Enable http profiling server if requested. if cfg.Profile != "" { diff --git a/rpcserver.go b/rpcserver.go index 0724a757..fddfaaa3 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -42,6 +42,7 @@ import ( "github.com/lbryio/lbcd/mining/cpuminer" "github.com/lbryio/lbcd/peer" "github.com/lbryio/lbcd/txscript" + "github.com/lbryio/lbcd/version" "github.com/lbryio/lbcd/wire" btcutil "github.com/lbryio/lbcutil" ) @@ -2451,7 +2452,7 @@ func handleGetHeaders(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) func handleGetInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { best := s.cfg.Chain.BestSnapshot() ret := &btcjson.InfoChainResult{ - Version: int32(1000000*appMajor + 10000*appMinor + 100*appPatch), + Version: version.Numeric(), ProtocolVersion: int32(maxProtocolVersion), Blocks: best.Height, TimeOffset: int64(s.cfg.TimeSource.Offset().Seconds()), @@ -2750,7 +2751,7 @@ func handleGetNetworkInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct reply := &btcjson.GetNetworkInfoResult{ ProtocolVersion: int32(wire.ProtocolVersion), - Version: versionNumeric(), + Version: version.Numeric(), Connections: s.cfg.ConnMgr.ConnectedCount(), IncrementalFee: cfg.MinRelayTxFee, LocalAddresses: localAddrs, diff --git a/server.go b/server.go index 305b7852..82da9ee1 100644 --- a/server.go +++ b/server.go @@ -39,6 +39,7 @@ import ( "github.com/lbryio/lbcd/netsync" "github.com/lbryio/lbcd/peer" "github.com/lbryio/lbcd/txscript" + "github.com/lbryio/lbcd/version" "github.com/lbryio/lbcd/wire" "github.com/lbryio/lbcutil" btcutil "github.com/lbryio/lbcutil" @@ -71,7 +72,7 @@ var ( // userAgentVersion is the user agent version and is used to help // identify ourselves to other bitcoin peers. - userAgentVersion = fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch) + userAgentVersion = version.Full() ) // zeroHash is the zero value hash (all zeros). It is defined as a convenience. diff --git a/service_windows.go b/service_windows.go index 378c9204..448720b7 100644 --- a/service_windows.go +++ b/service_windows.go @@ -10,6 +10,8 @@ import ( "path/filepath" "time" + "github.com/lbryio/lbcd/version" + "github.com/btcsuite/winsvc/eventlog" "github.com/btcsuite/winsvc/mgr" "github.com/btcsuite/winsvc/svc" @@ -36,7 +38,7 @@ var elog *eventlog.Log // been started to the Windows event log. func logServiceStartOfDay(srvr *server) { var message string - message += fmt.Sprintf("Version %s\n", version()) + message += fmt.Sprintf("Version %s\n", version.Full()) message += fmt.Sprintf("Configuration directory: %s\n", defaultHomeDir) message += fmt.Sprintf("Configuration file: %s\n", cfg.ConfigFile) message += fmt.Sprintf("Data directory: %s\n", cfg.DataDir) diff --git a/version.go b/version.go deleted file mode 100644 index 23f1f3de..00000000 --- a/version.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2013-2014 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -package main - -import ( - "bytes" - "fmt" - "strings" -) - -// semanticAlphabet -const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-" - -// These constants define the application version and follow the semantic -// versioning 2.0.0 spec (http://semver.org/). -const ( - appMajor uint = 0 - appMinor uint = 22 - appPatch uint = 0 - - // appPreRelease MUST only contain characters from semanticAlphabet - // per the semantic versioning spec. - appPreRelease = "beta" -) - -// appBuild is defined as a variable so it can be overridden during the build -// process with '-ldflags "-X main.appBuild foo' if needed. It MUST only -// contain characters from semanticAlphabet per the semantic versioning spec. -var appBuild string - -// version returns the application version as a properly formed string per the -// semantic versioning 2.0.0 spec (http://semver.org/). -func version() string { - // Start with the major, minor, and patch versions. - version := fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch) - - // Append pre-release version if there is one. The hyphen called for - // by the semantic versioning spec is automatically appended and should - // not be contained in the pre-release string. The pre-release version - // is not appended if it contains invalid characters. - preRelease := normalizeVerString(appPreRelease) - if preRelease != "" { - version = fmt.Sprintf("%s-%s", version, preRelease) - } - - // Append build metadata if there is any. The plus called for - // by the semantic versioning spec is automatically appended and should - // not be contained in the build metadata string. The build metadata - // string is not appended if it contains invalid characters. - build := normalizeVerString(appBuild) - if build != "" { - version = fmt.Sprintf("%s+%s", version, build) - } - - return version -} - -// Numeric returns the application version as an integer. -func versionNumeric() int32 { - return int32(2 ^ appMajor*3 ^ appMinor*5 ^ appPatch) -} - -// normalizeVerString returns the passed string stripped of all characters which -// are not valid according to the semantic versioning guidelines for pre-release -// version and build metadata strings. In particular they MUST only contain -// characters in semanticAlphabet. -func normalizeVerString(str string) string { - var result bytes.Buffer - for _, r := range str { - if strings.ContainsRune(semanticAlphabet, r) { - result.WriteRune(r) - } - } - return result.String() -}