Skip to content

Commit

Permalink
adding an GetEnabledSubsystems API to storage miner
Browse files Browse the repository at this point in the history
  • Loading branch information
nonsense committed Jul 28, 2021
1 parent 11d3f19 commit a3895f7
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 2,302 deletions.
2 changes: 2 additions & 0 deletions api/api_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ type StorageMiner interface {
MarketPendingDeals(ctx context.Context) (PendingDealInfo, error) //perm:write
MarketPublishPendingDeals(ctx context.Context) error //perm:admin

GetEnabledSubsystems(ctx context.Context) ([]MinerSubsystem, error) //perm:read

DealsImportData(ctx context.Context, dealPropCid cid.Cid, file string) error //perm:admin
DealsList(ctx context.Context) ([]MarketDeal, error) //perm:admin
DealsConsiderOnlineStorageDeals(context.Context) (bool, error) //perm:admin
Expand Down
61 changes: 61 additions & 0 deletions api/api_subsystems.go
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
}
13 changes: 13 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a3895f7

Please sign in to comment.