-
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.
- Loading branch information
Showing
10 changed files
with
113 additions
and
80 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 was deleted.
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,79 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
// MinerSubsystem represents a miner subsystem. Int and string values are not | ||
// guaranteed to be stable over time is not | ||
// guaranteed to be stable over time. | ||
type MinerSubsystem int | ||
|
||
const ( | ||
// SubsystemUnknown is a placeholder for the zero value. It should never | ||
// be used. | ||
SubsystemUnknown MinerSubsystem = iota | ||
// SubsystemMarkets signifies the storage and retrieval | ||
// deal-making subsystem. | ||
SubsystemMarkets | ||
// SubsystemMining signifies the mining subsystem. | ||
SubsystemMining | ||
// SubsystemSealing signifies the sealing subsystem. | ||
SubsystemSealing | ||
// SubsystemSectorStorage signifies the sector storage subsystem. | ||
SubsystemSectorStorage | ||
) | ||
|
||
var MinerSubsystemToString = map[MinerSubsystem]string{ | ||
SubsystemUnknown: "Unknown", | ||
SubsystemMarkets: "Markets", | ||
SubsystemMining: "Mining", | ||
SubsystemSealing: "Sealing", | ||
SubsystemSectorStorage: "SectorStorage", | ||
} | ||
|
||
var MinerSubsystemToID = map[string]MinerSubsystem{ | ||
"Unknown": SubsystemUnknown, | ||
"Markets": SubsystemMarkets, | ||
"Mining": SubsystemMining, | ||
"Sealing": SubsystemSealing, | ||
"SectorStorage": SubsystemSectorStorage, | ||
} | ||
|
||
func (ms MinerSubsystem) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(MinerSubsystemToString[ms]) | ||
} | ||
|
||
func (ms *MinerSubsystem) UnmarshalJSON(b []byte) error { | ||
var j string | ||
err := json.Unmarshal(b, &j) | ||
if err != nil { | ||
return err | ||
} | ||
s, ok := MinerSubsystemToID[j] | ||
if !ok { | ||
*ms = SubsystemUnknown | ||
} else { | ||
*ms = s | ||
} | ||
return nil | ||
} | ||
|
||
type MinerSubsystems []MinerSubsystem | ||
|
||
func (ms MinerSubsystems) Has(entry MinerSubsystem) bool { | ||
for _, v := range ms { | ||
if v == entry { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func (ms MinerSubsystem) String() string { | ||
s, ok := MinerSubsystemToString[ms] | ||
if !ok { | ||
return MinerSubsystemToString[SubsystemUnknown] | ||
} | ||
return s | ||
} |
Binary file not shown.
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