diff --git a/api/struct.go b/api/struct.go index 8f24bc272..f6394f678 100644 --- a/api/struct.go +++ b/api/struct.go @@ -68,7 +68,7 @@ type StorageMinerStruct struct { CommonStruct Internal struct { - StoreGarbageData func(context.Context) (uint64, error) + StoreGarbageData func(context.Context) (uint64, error) `perm:"write"` } } diff --git a/cli/cmd.go b/cli/cmd.go index 62775e635..9d444f533 100644 --- a/cli/cmd.go +++ b/cli/cmd.go @@ -27,19 +27,19 @@ const ( // ApiConnector returns API instance type ApiConnector func() api.FullNode -func GetAPI(ctx *cli.Context) (api.FullNode, error) { - r, err := repo.NewFS(ctx.String("repo")) +func getAPI(ctx *cli.Context, repoFlag string) (string, http.Header, error) { + r, err := repo.NewFS(ctx.String(repoFlag)) if err != nil { - return nil, err + return "", nil, err } ma, err := r.APIEndpoint() if err != nil { - return nil, xerrors.Errorf("failed to get api endpoint: %w", err) + return "", nil, xerrors.Errorf("failed to get api endpoint: %w", err) } _, addr, err := manet.DialArgs(ma) if err != nil { - return nil, err + return "", nil, err } var headers http.Header token, err := r.APIToken() @@ -50,7 +50,25 @@ func GetAPI(ctx *cli.Context) (api.FullNode, error) { headers.Add("Authorization", "Bearer "+string(token)) } - return client.NewFullNodeRPC("ws://"+addr+"/rpc/v0", headers) + return "ws://" + addr + "/rpc/v0", headers, nil +} + +func GetAPI(ctx *cli.Context) (api.FullNode, error) { + addr, headers, err := getAPI(ctx, "repo") + if err != nil { + return nil, err + } + + return client.NewFullNodeRPC(addr, headers) +} + +func GetStorageMinerAPI(ctx *cli.Context) (api.StorageMiner, error) { + addr, headers, err := getAPI(ctx, "storagerepo") + if err != nil { + return nil, err + } + + return client.NewStorageMinerRPC(addr, headers) } // ReqContext returns context for cli execution. Calling it for the first time diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index c625f4620..0b15bb611 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -154,7 +154,7 @@ var initCmd = &cli.Command{ return err } - log.Infof("Waiting for confirmation") + log.Infof("Waiting for confirmation (TODO: actually wait)") mw, err := api.ChainWaitMsg(ctx, signed.Cid()) if err != nil { diff --git a/cmd/lotus-storage-miner/run.go b/cmd/lotus-storage-miner/run.go index 6919d44b2..752d48d9a 100644 --- a/cmd/lotus-storage-miner/run.go +++ b/cmd/lotus-storage-miner/run.go @@ -1,7 +1,9 @@ package main import ( + "fmt" "net/http" + "os" "github.com/multiformats/go-multiaddr" "golang.org/x/xerrors" @@ -33,6 +35,13 @@ var runCmd = &cli.Command{ } ctx := lcli.ReqContext(cctx) + go func() { + // a hack for now to handle sigint + + <-ctx.Done() + os.Exit(0) + }() + v, err := nodeApi.Version(ctx) if err != nil { return err @@ -92,16 +101,18 @@ var storeGarbageCmd = &cli.Command{ Name: "store-garbage", Usage: "store random data in a sector", Action: func(cctx *cli.Context) error { - nodeApi, err := lcli.GetAPI(cctx) + nodeApi, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } ctx := lcli.ReqContext(cctx) - _ = ctx - _ = nodeApi - // ??? - // wait a second, i need the api handler for the storage miner... + sectorId, err := nodeApi.StoreGarbageData(ctx) + if err != nil { + return err + } + + fmt.Println(sectorId) return nil }, }