-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5729 from filecoin-project/feat/api-no-dep-build
Feat/api no dep build
- Loading branch information
Showing
21 changed files
with
116 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
|
||
xerrors "golang.org/x/xerrors" | ||
) | ||
|
||
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: | ||
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(1, 1, 0) | ||
MinerAPIVersion = newVer(1, 0, 1) | ||
WorkerAPIVersion = newVer(1, 0, 0) | ||
) | ||
|
||
//nolint:varcheck,deadcode | ||
const ( | ||
majorMask = 0xff0000 | ||
minorMask = 0xffff00 | ||
patchMask = 0xffffff | ||
|
||
majorOnlyMask = 0xff0000 | ||
minorOnlyMask = 0x00ff00 | ||
patchOnlyMask = 0x0000ff | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.