2019-07-19 09:24:11 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
"gopkg.in/urfave/cli.v2"
|
|
|
|
|
2019-07-19 10:15:22 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/build"
|
2019-07-19 09:24:11 +00:00
|
|
|
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")
|
|
|
|
|
2019-07-19 10:15:22 +00:00
|
|
|
api, err := lcli.GetAPI(cctx) // TODO: consider storing full node address in config
|
2019-07-19 09:24:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
|
|
|
log.Info("Checking full node version")
|
|
|
|
|
2019-07-19 10:15:22 +00:00
|
|
|
v, err := api.Version(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.APIVersion & build.MinorMask != build.APIVersion & build.MinorMask {
|
|
|
|
return xerrors.Errorf("Remote API version didn't match (local %x, remote %x)", build.APIVersion, v.APIVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("Initializing repo")
|
|
|
|
|
2019-07-19 09:24:11 +00:00
|
|
|
if err := r.Init(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-07-19 10:15:22 +00:00
|
|
|
// create actors and stuff
|
|
|
|
|
|
|
|
log.Info("Storage miner successfully created, you can now start it with 'lotus-storage-miner run'")
|
|
|
|
|
2019-07-19 09:24:11 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|