60 lines
1.4 KiB
Go
60 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("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) // 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
|
|
},
|
|
}
|