lotus/cmd/lotus-storage-miner/init.go
Łukasz Magiera 8d529d1ae7 gofmt
2019-07-24 01:47:36 +02:00

64 lines
1.4 KiB
Go

package main
import (
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-lotus/build"
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(FlagStorageRepo))
if err != nil {
return err
}
ok, err := r.Exists()
if err != nil {
return err
}
if ok {
return xerrors.Errorf("repo at '%s' is already initialized", cctx.String(FlagStorageRepo))
}
log.Info("Trying to connect to full node RPC")
api, err := lcli.GetAPI(cctx) // TODO: consider storing full node address in config
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")
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'")
return nil
},
}