lotus/cmd/lotus-storage-miner/init.go

64 lines
1.4 KiB
Go
Raw Normal View History

2019-07-19 09:24:11 +00:00
package main
import (
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
"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")
2019-07-23 21:50:52 +00:00
r, err := repo.NewFS(cctx.String(FlagStorageRepo))
2019-07-19 09:24:11 +00:00
if err != nil {
return err
}
2019-07-23 21:54:54 +00:00
ok, err := r.Exists()
if err != nil {
return err
}
if ok {
2019-07-23 21:50:52 +00:00
return xerrors.Errorf("repo at '%s' is already initialized", cctx.String(FlagStorageRepo))
2019-07-19 09:24:11 +00:00
}
log.Info("Trying to connect to full node RPC")
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")
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
}
// 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
},
}