lotus/cmd/sptool/main.go
Andrew Jackson (Ajax) b95e95f4d6
feat: SPTool (#11788)
* sptool: Initial structure

* sptool: Port lotus-miner actor withdraw

* sptool: Make cli docsgen happy

* actors are done

* info

* proving

* sptool the rest

* fixed gitignore

* lints

* oops

* 2

* terminate

* fixes

* sptool: improve sectors list

---------

Co-authored-by: Łukasz Magiera <magik6k@gmail.com>
2024-04-01 10:30:35 -05:00

85 lines
1.7 KiB
Go

package main
import (
"context"
"fmt"
"os"
"os/signal"
logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/cli/spcli"
)
var log = logging.Logger("sptool")
func main() {
local := []*cli.Command{
actorCmd,
spcli.InfoCmd(SPTActorGetter),
sectorsCmd,
provingCmd,
//multiSigCmd,
}
app := &cli.App{
Name: "sptool",
Usage: "Manage Filecoin Miner Actor",
Version: build.UserVersion(),
Commands: local,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "repo",
EnvVars: []string{"LOTUS_PATH"},
Hidden: true,
Value: "~/.lotus", // TODO: Consider XDG_DATA_HOME
},
&cli.StringFlag{
Name: "log-level",
Value: "info",
},
&cli.StringFlag{
Name: "actor",
Required: os.Getenv("LOTUS_DOCS_GENERATION") != "1",
Usage: "miner actor to manage",
EnvVars: []string{"SP_ADDRESS"},
},
},
Before: func(cctx *cli.Context) error {
return logging.SetLogLevel("sptool", cctx.String("sptool"))
},
}
// terminate early on ctrl+c
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
ctx, cancel := context.WithCancel(context.Background())
go func() {
<-c
cancel()
fmt.Println("Received interrupt, shutting down... Press CTRL+C again to force shutdown")
<-c
fmt.Println("Forcing stop")
os.Exit(1)
}()
if err := app.RunContext(ctx, os.Args); err != nil {
log.Errorf("%+v", err)
os.Exit(1)
return
}
}
func SPTActorGetter(cctx *cli.Context) (address.Address, error) {
addr, err := address.NewFromString(cctx.String("actor"))
if err != nil {
return address.Undef, fmt.Errorf("parsing address: %w", err)
}
return addr, nil
}