-
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.
adding an GetEnabledSubsystems API to storage miner
- Loading branch information
Showing
6 changed files
with
101 additions
and
2,302 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package api | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
) | ||
|
||
type MinerSubsystem int | ||
|
||
const ( | ||
MarketsSubsystem MinerSubsystem = 1 << iota | ||
MiningSubsystem | ||
SealingSubsystem | ||
SectorStorageSubsystem | ||
|
||
MinerSubsystems = iota | ||
) | ||
|
||
func (ms MinerSubsystem) Add(single MinerSubsystem) MinerSubsystem { | ||
return ms | single | ||
} | ||
|
||
func (ms MinerSubsystem) Has(single MinerSubsystem) bool { | ||
return ms&single == single | ||
} | ||
|
||
func (ms MinerSubsystem) String() string { | ||
return MinerSubsystemToString[ms] | ||
} | ||
|
||
var MinerSubsystemToString = map[MinerSubsystem]string{ | ||
MarketsSubsystem: "Markets", | ||
MiningSubsystem: "Mining", | ||
SealingSubsystem: "Sealing", | ||
SectorStorageSubsystem: "SectorStorage", | ||
} | ||
|
||
var MinerSubsystemToID = map[string]MinerSubsystem{ | ||
"Markets": MarketsSubsystem, | ||
"Mining": MiningSubsystem, | ||
"Sealing": SealingSubsystem, | ||
"SectorStorage": SectorStorageSubsystem, | ||
} | ||
|
||
func (ms MinerSubsystem) MarshalJSON() ([]byte, error) { | ||
buffer := bytes.NewBufferString(`"`) | ||
buffer.WriteString(MinerSubsystemToString[ms]) | ||
buffer.WriteString(`"`) | ||
return buffer.Bytes(), nil | ||
} | ||
|
||
func (ms *MinerSubsystem) UnmarshalJSON(b []byte) error { | ||
var j string | ||
err := json.Unmarshal(b, &j) | ||
if err != nil { | ||
return err | ||
} | ||
// TODO: handle zero value | ||
*ms = MinerSubsystemToID[j] | ||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.