version.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2014 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. // Package utils contains internal helper functions for go-ethereum commands.
  17. package utils
  18. import (
  19. "fmt"
  20. "runtime"
  21. "github.com/ethereum/go-ethereum/logger"
  22. "github.com/ethereum/go-ethereum/logger/glog"
  23. "github.com/ethereum/go-ethereum/params"
  24. "github.com/ethereum/go-ethereum/rlp"
  25. )
  26. const (
  27. VersionMajor = 1 // Major version component of the current release
  28. VersionMinor = 5 // Minor version component of the current release
  29. VersionPatch = 0 // Patch version component of the current release
  30. VersionMeta = "unstable" // Version metadata to append to the version string
  31. )
  32. // Version holds the textual version string.
  33. var Version = func() string {
  34. v := fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionPatch)
  35. if VersionMeta != "" {
  36. v += "-" + VersionMeta
  37. }
  38. return v
  39. }()
  40. // MakeDefaultExtraData returns the default Ethereum block extra data blob.
  41. func MakeDefaultExtraData(clientIdentifier string) []byte {
  42. var clientInfo = struct {
  43. Version uint
  44. Name string
  45. GoVersion string
  46. Os string
  47. }{uint(VersionMajor<<16 | VersionMinor<<8 | VersionPatch), clientIdentifier, runtime.Version(), runtime.GOOS}
  48. extra, err := rlp.EncodeToBytes(clientInfo)
  49. if err != nil {
  50. glog.V(logger.Warn).Infoln("error setting canonical miner information:", err)
  51. }
  52. if uint64(len(extra)) > params.MaximumExtraDataSize.Uint64() {
  53. glog.V(logger.Warn).Infoln("error setting canonical miner information: extra exceeds", params.MaximumExtraDataSize)
  54. glog.V(logger.Debug).Infof("extra: %x\n", extra)
  55. return nil
  56. }
  57. return extra
  58. }