2021-03-05 21:01:20 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-06-15 10:06:22 +00:00
|
|
|
"golang.org/x/xerrors"
|
2021-03-05 21:01:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Version uint32
|
|
|
|
|
|
|
|
func newVer(major, minor, patch uint8) Version {
|
|
|
|
return Version(uint32(major)<<16 | uint32(minor)<<8 | uint32(patch))
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ve Version) EqMajorMinor(v2 Version) bool {
|
|
|
|
return ve&minorMask == v2&minorMask
|
|
|
|
}
|
|
|
|
|
|
|
|
type NodeType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
NodeUnknown NodeType = iota
|
|
|
|
|
|
|
|
NodeFull
|
|
|
|
NodeMiner
|
|
|
|
NodeWorker
|
|
|
|
)
|
|
|
|
|
|
|
|
var RunningNodeType NodeType
|
|
|
|
|
|
|
|
func VersionForType(nodeType NodeType) (Version, error) {
|
|
|
|
switch nodeType {
|
|
|
|
case NodeFull:
|
2021-04-15 22:19:26 +00:00
|
|
|
return FullAPIVersion1, nil
|
2021-03-05 21:01:20 +00:00
|
|
|
case NodeMiner:
|
2021-04-15 22:19:26 +00:00
|
|
|
return MinerAPIVersion0, nil
|
2021-03-05 21:01:20 +00:00
|
|
|
case NodeWorker:
|
2021-04-15 22:19:26 +00:00
|
|
|
return WorkerAPIVersion0, nil
|
2021-03-05 21:01:20 +00:00
|
|
|
default:
|
|
|
|
return Version(0), xerrors.Errorf("unknown node type %d", nodeType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// semver versions of the rpc api exposed
|
|
|
|
var (
|
2022-01-11 16:31:27 +00:00
|
|
|
FullAPIVersion0 = newVer(1, 5, 0)
|
2022-06-16 12:19:53 +00:00
|
|
|
FullAPIVersion1 = newVer(2, 3, 0)
|
2021-04-15 22:19:26 +00:00
|
|
|
|
2022-03-16 09:35:26 +00:00
|
|
|
MinerAPIVersion0 = newVer(1, 5, 0)
|
2022-11-16 16:07:42 +00:00
|
|
|
WorkerAPIVersion0 = newVer(1, 7, 0)
|
2021-03-05 21:01:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
//nolint:varcheck,deadcode
|
|
|
|
const (
|
|
|
|
majorMask = 0xff0000
|
|
|
|
minorMask = 0xffff00
|
|
|
|
patchMask = 0xffffff
|
|
|
|
|
|
|
|
majorOnlyMask = 0xff0000
|
|
|
|
minorOnlyMask = 0x00ff00
|
|
|
|
patchOnlyMask = 0x0000ff
|
|
|
|
)
|