2019-06-25 11:42:17 +00:00
|
|
|
package build
|
|
|
|
|
2020-09-08 18:54:37 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
)
|
2019-12-17 15:26:16 +00:00
|
|
|
|
2019-12-11 22:00:39 +00:00
|
|
|
var CurrentCommit string
|
2020-06-01 18:43:51 +00:00
|
|
|
var BuildType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
BuildDefault = 0
|
|
|
|
Build2k = 0x1
|
|
|
|
BuildDebug = 0x3
|
|
|
|
)
|
|
|
|
|
|
|
|
func buildType() string {
|
|
|
|
switch BuildType {
|
|
|
|
case BuildDefault:
|
2020-06-01 19:11:37 +00:00
|
|
|
return ""
|
2020-06-01 18:43:51 +00:00
|
|
|
case BuildDebug:
|
|
|
|
return "+debug"
|
|
|
|
case Build2k:
|
|
|
|
return "+2k"
|
|
|
|
default:
|
|
|
|
return "+huh?"
|
|
|
|
}
|
|
|
|
}
|
2019-12-11 22:00:39 +00:00
|
|
|
|
2019-12-17 15:26:16 +00:00
|
|
|
// BuildVersion is the local build version, set by build system
|
2020-09-09 19:54:21 +00:00
|
|
|
const BuildVersion = "0.6.2"
|
2019-07-19 10:15:22 +00:00
|
|
|
|
2020-06-01 18:43:51 +00:00
|
|
|
func UserVersion() string {
|
|
|
|
return BuildVersion + buildType() + CurrentCommit
|
|
|
|
}
|
2019-12-11 22:00:39 +00:00
|
|
|
|
2019-12-17 15:26:16 +00:00
|
|
|
type Version uint32
|
2019-07-19 10:15:22 +00:00
|
|
|
|
2019-12-17 15:26:16 +00:00
|
|
|
func newVer(major, minor, patch uint8) Version {
|
|
|
|
return Version(uint32(major)<<16 | uint32(minor)<<8 | uint32(patch))
|
|
|
|
}
|
2019-12-11 00:22:58 +00:00
|
|
|
|
2019-12-17 15:26:16 +00:00
|
|
|
// Ints returns (major, minor, patch) versions
|
|
|
|
func (ve Version) Ints() (uint32, uint32, uint32) {
|
|
|
|
v := uint32(ve)
|
|
|
|
return (v & majorOnlyMask) >> 16, (v & minorOnlyMask) >> 8, v & patchOnlyMask
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ve Version) String() string {
|
|
|
|
vmj, vmi, vp := ve.Ints()
|
|
|
|
return fmt.Sprintf("%d.%d.%d", vmj, vmi, vp)
|
|
|
|
}
|
2019-12-17 15:16:57 +00:00
|
|
|
|
2019-12-17 15:26:16 +00:00
|
|
|
func (ve Version) EqMajorMinor(v2 Version) bool {
|
|
|
|
return ve&minorMask == v2&minorMask
|
2019-12-17 15:16:57 +00:00
|
|
|
}
|
2019-12-17 15:26:16 +00:00
|
|
|
|
2020-09-08 18:54:37 +00:00
|
|
|
type NodeType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
NodeUnknown NodeType = iota
|
|
|
|
|
|
|
|
NodeFull
|
|
|
|
NodeMiner
|
|
|
|
NodeWorker
|
|
|
|
)
|
|
|
|
|
|
|
|
var RunningNodeType NodeType
|
|
|
|
|
|
|
|
func VersionForType(nodeType NodeType) (Version, error) {
|
|
|
|
switch nodeType {
|
|
|
|
case NodeFull:
|
|
|
|
return FullAPIVersion, nil
|
|
|
|
case NodeMiner:
|
|
|
|
return MinerAPIVersion, nil
|
|
|
|
case NodeWorker:
|
|
|
|
return WorkerAPIVersion, nil
|
|
|
|
default:
|
|
|
|
return Version(0), xerrors.Errorf("unknown node type %d", nodeType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// semver versions of the rpc api exposed
|
|
|
|
var (
|
|
|
|
FullAPIVersion = newVer(0, 14, 0)
|
|
|
|
MinerAPIVersion = newVer(0, 14, 0)
|
|
|
|
WorkerAPIVersion = newVer(0, 14, 0)
|
|
|
|
)
|
2019-12-17 15:26:16 +00:00
|
|
|
|
2020-06-02 14:29:39 +00:00
|
|
|
//nolint:varcheck,deadcode
|
2019-12-17 15:26:16 +00:00
|
|
|
const (
|
|
|
|
majorMask = 0xff0000
|
|
|
|
minorMask = 0xffff00
|
|
|
|
patchMask = 0xffffff
|
|
|
|
|
|
|
|
majorOnlyMask = 0xff0000
|
|
|
|
minorOnlyMask = 0x00ff00
|
|
|
|
patchOnlyMask = 0x0000ff
|
|
|
|
)
|