StorageMiner init code
This commit is contained in:
parent
fe147ce90d
commit
0e570c0b19
43
cmd/lotus-storage-miner/init.go
Normal file
43
cmd/lotus-storage-miner/init.go
Normal file
@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"golang.org/x/xerrors"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
|
||||
lcli "github.com/filecoin-project/go-lotus/cli"
|
||||
"github.com/filecoin-project/go-lotus/node/repo"
|
||||
)
|
||||
|
||||
var initCmd = &cli.Command{
|
||||
Name: "init",
|
||||
Usage: "Initialize a lotus storage miner repo",
|
||||
Action: func(cctx *cli.Context) error {
|
||||
log.Info("Initializing lotus storage miner")
|
||||
log.Info("Checking if repo exists")
|
||||
|
||||
r, err := repo.NewFS(cctx.String("storagerepo"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if r.Exists() {
|
||||
return xerrors.Errorf("repo at '%s' is already initialized", cctx.String("storagerepo"))
|
||||
}
|
||||
|
||||
log.Info("Trying to connect to full node RPC")
|
||||
|
||||
api, err := lcli.GetAPI(cctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx := lcli.ReqContext(cctx)
|
||||
|
||||
log.Info("Checking full node version")
|
||||
|
||||
if err := r.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
@ -1,9 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/multiformats/go-multiaddr"
|
||||
"golang.org/x/xerrors"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
|
||||
lcli "github.com/filecoin-project/go-lotus/cli"
|
||||
"github.com/filecoin-project/go-lotus/lib/jsonrpc"
|
||||
"github.com/filecoin-project/go-lotus/node"
|
||||
"github.com/filecoin-project/go-lotus/node/repo"
|
||||
)
|
||||
|
||||
var RunCmd = &cli.Command{
|
||||
@ -15,6 +22,10 @@ var RunCmd = &cli.Command{
|
||||
EnvVars: []string{"LOTUS_STORAGE_PATH"},
|
||||
Value: "~/.lotusstorage", // TODO: Consider XDG_DATA_HOME
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "api",
|
||||
Value: "2345",
|
||||
},
|
||||
},
|
||||
Action: func(cctx *cli.Context) error {
|
||||
api, err := lcli.GetAPI(cctx)
|
||||
@ -25,9 +36,40 @@ var RunCmd = &cli.Command{
|
||||
|
||||
v, err := api.Version(ctx)
|
||||
|
||||
r, err := repo.NewFS(cctx.String("storagerepo"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !r.Exists() {
|
||||
return xerrors.Errorf("repo at '%s' is not initialized, run 'lotus-storage-miner init' to set it up", cctx.String("storagerepo"))
|
||||
}
|
||||
|
||||
minerapi, err := node.New(ctx,
|
||||
node.StorageMiner(),
|
||||
node.Online(),
|
||||
node.Repo(r),
|
||||
|
||||
node.Override(node.SetApiEndpointKey, func(lr repo.LockedRepo) error {
|
||||
apima, err := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/" + cctx.String("api"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return lr.SetAPIEndpoint(apima)
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: libp2p node
|
||||
|
||||
log.Infof("Remote version %s", v)
|
||||
return nil
|
||||
|
||||
|
||||
rpcServer := jsonrpc.NewServer()
|
||||
rpcServer.Register("Filecoin", minerapi)
|
||||
http.Handle("/rpc/v0", rpcServer)
|
||||
return http.ListenAndServe("127.0.0.1:"+cctx.String("api"), http.DefaultServeMux)
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user